Class: Wf::CaseCommand::AddWorkitemAssignment
- Inherits:
-
Object
- Object
- Wf::CaseCommand::AddWorkitemAssignment
- Includes:
- SimpleCommand
- Defined in:
- app/models/wf/case_command/add_workitem_assignment.rb
Instance Attribute Summary collapse
-
#party ⇒ Object
readonly
Returns the value of attribute party.
-
#permanent ⇒ Object
readonly
Returns the value of attribute permanent.
-
#workitem ⇒ Object
readonly
Returns the value of attribute workitem.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(workitem, party, permanent = true) ⇒ AddWorkitemAssignment
constructor
A new instance of AddWorkitemAssignment.
Constructor Details
#initialize(workitem, party, permanent = true) ⇒ AddWorkitemAssignment
Returns a new instance of AddWorkitemAssignment.
7 8 9 10 11 |
# File 'app/models/wf/case_command/add_workitem_assignment.rb', line 7 def initialize(workitem, party, permanent = true) @workitem = workitem @party = party @permanent = permanent end |
Instance Attribute Details
#party ⇒ Object (readonly)
Returns the value of attribute party.
6 7 8 |
# File 'app/models/wf/case_command/add_workitem_assignment.rb', line 6 def party @party end |
#permanent ⇒ Object (readonly)
Returns the value of attribute permanent.
6 7 8 |
# File 'app/models/wf/case_command/add_workitem_assignment.rb', line 6 def permanent @permanent end |
#workitem ⇒ Object (readonly)
Returns the value of attribute workitem.
6 7 8 |
# File 'app/models/wf/case_command/add_workitem_assignment.rb', line 6 def workitem @workitem end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/wf/case_command/add_workitem_assignment.rb', line 13 def call return if party.nil? Wf::ApplicationRecord.transaction do AddManualAssignment.call(workitem.case, workitem.transition, party) if permanent notified_users = workitem.parties.map do |p| p.partable.users.to_a end.flatten assign = workitem.workitem_assignments.where(party: party).first break if assign workitem.workitem_assignments.create!(party: party) new_users = party.partable.users.to_a to_notify = new_users - notified_users transition = workitem.transition to_notify.each do |user| # TODO: multiple instance + sub workflow if transition.multiple_instance? && !workitem.forked? next if workitem.children.where(holding_user: user).exists? child = workitem.children.create!( workflow_id: workitem.workflow_id, transition_id: workitem.transition_id, state: :enabled, trigger_time: workitem.trigger_time, forked: true, holding_user: user, case_id: workitem.case_id ) workitem.transition.notification_callback.constantize.new(child, user.id).perform_now else workitem.transition.notification_callback.constantize.new(workitem, user.id).perform_now end end end end |