Module: RailsWorkflow::Operations::Assignments
- Extended by:
- ActiveSupport::Concern
- Included in:
- RailsWorkflow::Operation
- Defined in:
- app/concerns/rails_workflow/operations/assignments.rb
Overview
User operation should be completed by some specific user. Operation template specifies user's that can assign that operation. By default you can use user role or user group to specify users that can pickup and complete operaitons but it can be customized.
Only user operaitons in WAITING status can be assigned to user.
Instance Method Summary (collapse)
-
- (Object) activate
Active operation is one that user is working on right now.
-
- (Object) assign(user)
Assigns operation to given user.
-
- (Object) assign_to(user)
Assigns operation to given user.
-
- (boolean) assigned?(user)
Checking if operation is assigned to given user.
-
- (boolean) can_be_assigned?(user)
Checking if user can be assigned to current operation.
-
- cancel_assignment(user)
Allows to cancel assignment operation from specific user.
Instance Method Details
- (Object) activate
Active operation is one that user is working on right now. This is operation that 'current_operation' helper returns. User may have only one active operation at the same time.
83 84 85 86 |
# File 'app/concerns/rails_workflow/operations/assignments.rb', line 83 def activate self.is_active = true save end |
- (Object) assign(user)
Assigns operation to given user. Checks if user can be assigned to given operation. It's safe to use that method for operations that is already assigned to user - this way operation will be set to active current user operation.
92 93 94 95 |
# File 'app/concerns/rails_workflow/operations/assignments.rb', line 92 def assign user ((assigned? user) && (activate)) || #if already assigned to user but unactive! (can_be_assigned?(user) && assign_to(user)) #user first time assigned to operation end |
- (Object) assign_to(user)
Assigns operation to given user.
71 72 73 74 75 76 77 78 79 |
# File 'app/concerns/rails_workflow/operations/assignments.rb', line 71 def assign_to user self.assignment = user self.is_active = true self.assigned_at = Time.zone.now self.class.assigned_to(user).update_all(is_active: false) save end |
- (boolean) assigned?(user)
Checking if operation is assigned to given user.
45 46 47 |
# File 'app/concerns/rails_workflow/operations/assignments.rb', line 45 def assigned? user assignment == user end |
- (boolean) can_be_assigned?(user)
Checking if user can be assigned to current operation.
65 66 67 |
# File 'app/concerns/rails_workflow/operations/assignments.rb', line 65 def can_be_assigned? user self.assignment.blank? end |
- cancel_assignment(user)
This method returns an undefined value.
Allows to cancel assignment operation from specific user. For example user has vacation and somebody else should complete operation. In this case operation is no longer assigned to given user and operation again assigned to role or group.
54 55 56 57 58 59 60 |
# File 'app/concerns/rails_workflow/operations/assignments.rb', line 54 def cancel_assignment user if assigned? user self.assignment = nil self.is_active = false save end end |