Commit 2664a61ab86b2dbfbee5ea87e1f11647c277c9ed
1 parent
22aa604c
Exists in
master
and in
7 other branches
Change responsible to a person with perform_task permission when flagged
Showing
2 changed files
with
56 additions
and
0 deletions
Show diff stats
lib/proposals_discussion_plugin/proposal_task.rb
| @@ -47,6 +47,14 @@ class ProposalsDiscussionPlugin::ProposalTask < Task | @@ -47,6 +47,14 @@ class ProposalsDiscussionPlugin::ProposalTask < Task | ||
| 47 | end | 47 | end |
| 48 | end | 48 | end |
| 49 | 49 | ||
| 50 | + before_update do |task| | ||
| 51 | + if task.target.present? && flagged? && task.changes[:status].present? | ||
| 52 | + organization = task.target | ||
| 53 | + responsible_candidates = organization.members.by_role(organization.roles.reject {|r| !r.has_permission?('perform_task')}) | ||
| 54 | + task.responsible = responsible_candidates.sample | ||
| 55 | + end | ||
| 56 | + end | ||
| 57 | + | ||
| 50 | def unflagged? | 58 | def unflagged? |
| 51 | ! flagged? | 59 | ! flagged? |
| 52 | end | 60 | end |
test/unit/proposal_task_test.rb
| @@ -29,4 +29,52 @@ class ProposalTaskTest < ActiveSupport::TestCase | @@ -29,4 +29,52 @@ class ProposalTaskTest < ActiveSupport::TestCase | ||
| 29 | assert_equal person2, task.responsible | 29 | assert_equal person2, task.responsible |
| 30 | end | 30 | end |
| 31 | 31 | ||
| 32 | + should 'assign proposal task to member with perform_task permission after flag as accepted' do | ||
| 33 | + role1 = Role.create!(:name => 'profile_role2', :permissions => ['perform_task'], :environment => Environment.default) | ||
| 34 | + role2 = Role.create!(:name => 'profile_role', :permissions => ['view_tasks'], :environment => Environment.default) | ||
| 35 | + | ||
| 36 | + person1 = fast_create(Person) | ||
| 37 | + person1.define_roles([role1], profile) | ||
| 38 | + person2 = fast_create(Person) | ||
| 39 | + person2.define_roles([role2], profile) | ||
| 40 | + | ||
| 41 | + task = ProposalsDiscussionPlugin::ProposalTask.create!(:requestor => person, :target => profile, :article => {:name => 'proposal 1', :abstract => 'proposal 1'}) | ||
| 42 | + task.categories = [fast_create(ProposalsDiscussionPlugin::TaskCategory)] | ||
| 43 | + task.flag_accept_proposal(person2) | ||
| 44 | + assert_equal person1, task.responsible | ||
| 45 | + end | ||
| 46 | + | ||
| 47 | + should 'assign proposal task to member with perform_task permission after flag as rejected' do | ||
| 48 | + role1 = Role.create!(:name => 'profile_role2', :permissions => ['perform_task'], :environment => Environment.default) | ||
| 49 | + role2 = Role.create!(:name => 'profile_role', :permissions => ['view_tasks'], :environment => Environment.default) | ||
| 50 | + | ||
| 51 | + person1 = fast_create(Person) | ||
| 52 | + person1.define_roles([role1], profile) | ||
| 53 | + person2 = fast_create(Person) | ||
| 54 | + person2.define_roles([role2], profile) | ||
| 55 | + | ||
| 56 | + task = ProposalsDiscussionPlugin::ProposalTask.create!(:requestor => person, :target => profile, :article => {:name => 'proposal 1', :abstract => 'proposal 1'}) | ||
| 57 | + task.categories = [fast_create(ProposalsDiscussionPlugin::TaskCategory)] | ||
| 58 | + task.flag_reject_proposal(person2) | ||
| 59 | + assert_equal person1, task.responsible | ||
| 60 | + end | ||
| 61 | + | ||
| 62 | + should 'not change assignment when update the task responsible' do | ||
| 63 | + role1 = Role.create!(:name => 'profile_role2', :permissions => ['perform_task'], :environment => Environment.default) | ||
| 64 | + role2 = Role.create!(:name => 'profile_role', :permissions => ['view_tasks'], :environment => Environment.default) | ||
| 65 | + | ||
| 66 | + person1 = fast_create(Person) | ||
| 67 | + person1.define_roles([role1], profile) | ||
| 68 | + person2 = fast_create(Person) | ||
| 69 | + person2.define_roles([role2], profile) | ||
| 70 | + | ||
| 71 | + task = ProposalsDiscussionPlugin::ProposalTask.create!(:requestor => person, :target => profile, :article => {:name => 'proposal 1', :abstract => 'proposal 1'}) | ||
| 72 | + task.categories = [fast_create(ProposalsDiscussionPlugin::TaskCategory)] | ||
| 73 | + task.flag_accept_proposal(person2) | ||
| 74 | + assert_equal person1, task.responsible | ||
| 75 | + task.responsible = person2 | ||
| 76 | + task.save! | ||
| 77 | + assert_equal person2, task.responsible | ||
| 78 | + end | ||
| 79 | + | ||
| 32 | end | 80 | end |