Commit bba03dc8febb8d44564339bc08fb71eb65349d8a
1 parent
26ebfc45
Exists in
master
and in
7 other branches
Assign task to members with view_tasks permission
Showing
2 changed files
with
16 additions
and
2 deletions
Show diff stats
lib/proposals_discussion_plugin/proposal_task.rb
| @@ -42,7 +42,7 @@ class ProposalsDiscussionPlugin::ProposalTask < Task | @@ -42,7 +42,7 @@ class ProposalsDiscussionPlugin::ProposalTask < Task | ||
| 42 | before_create do |task| | 42 | before_create do |task| |
| 43 | if !task.target.nil? | 43 | if !task.target.nil? |
| 44 | organization = task.target | 44 | organization = task.target |
| 45 | - responsible_candidates = organization.members.by_role(organization.roles.reject {|r| !r.has_permission?('perform_task')}) | 45 | + responsible_candidates = organization.members.by_role(organization.roles.reject {|r| !r.has_permission?('view_tasks')}) |
| 46 | task.responsible = responsible_candidates.sample | 46 | task.responsible = responsible_candidates.sample |
| 47 | end | 47 | end |
| 48 | end | 48 | end |
test/unit/proposal_task_test.rb
| @@ -2,10 +2,11 @@ require_relative '../test_helper' | @@ -2,10 +2,11 @@ require_relative '../test_helper' | ||
| 2 | 2 | ||
| 3 | class ProposalTaskTest < ActiveSupport::TestCase | 3 | class ProposalTaskTest < ActiveSupport::TestCase |
| 4 | 4 | ||
| 5 | - attr_reader :profile, :proposal, :person, :discussion | 5 | + attr_reader :profile, :person, :discussion |
| 6 | 6 | ||
| 7 | def setup | 7 | def setup |
| 8 | @person = fast_create(Person) | 8 | @person = fast_create(Person) |
| 9 | + @profile = fast_create(Community) | ||
| 9 | @discussion = ProposalsDiscussionPlugin::Discussion.create!(:name => 'discussion', :profile => person, :allow_topics => false) | 10 | @discussion = ProposalsDiscussionPlugin::Discussion.create!(:name => 'discussion', :profile => person, :allow_topics => false) |
| 10 | end | 11 | end |
| 11 | 12 | ||
| @@ -15,4 +16,17 @@ class ProposalTaskTest < ActiveSupport::TestCase | @@ -15,4 +16,17 @@ class ProposalTaskTest < ActiveSupport::TestCase | ||
| 15 | assert_equal topic.name, task.proposal_source | 16 | assert_equal topic.name, task.proposal_source |
| 16 | end | 17 | end |
| 17 | 18 | ||
| 19 | + should 'assign proposal task to member with view_task permission' do | ||
| 20 | + role1 = Role.create!(:name => 'profile_role2', :permissions => ['perform_task'], :environment => Environment.default) | ||
| 21 | + role2 = Role.create!(:name => 'profile_role', :permissions => ['view_tasks'], :environment => Environment.default) | ||
| 22 | + | ||
| 23 | + person1 = fast_create(Person) | ||
| 24 | + person1.define_roles([role1], profile) | ||
| 25 | + person2 = fast_create(Person) | ||
| 26 | + person2.define_roles([role2], profile) | ||
| 27 | + | ||
| 28 | + task = ProposalsDiscussionPlugin::ProposalTask.create!(:requestor => person, :target => profile, :article => {:name => 'proposal 1', :abstract => 'proposal 1'}) | ||
| 29 | + assert_equal person2, task.responsible | ||
| 30 | + end | ||
| 31 | + | ||
| 18 | end | 32 | end |