Commit bba03dc8febb8d44564339bc08fb71eb65349d8a

Authored by Victor Costa
1 parent 26ebfc45

Assign task to members with view_tasks permission

lib/proposals_discussion_plugin/proposal_task.rb
... ... @@ -42,7 +42,7 @@ class ProposalsDiscussionPlugin::ProposalTask < Task
42 42 before_create do |task|
43 43 if !task.target.nil?
44 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 46 task.responsible = responsible_candidates.sample
47 47 end
48 48 end
... ...
test/unit/proposal_task_test.rb
... ... @@ -2,10 +2,11 @@ require_relative '../test_helper'
2 2  
3 3 class ProposalTaskTest < ActiveSupport::TestCase
4 4  
5   - attr_reader :profile, :proposal, :person, :discussion
  5 + attr_reader :profile, :person, :discussion
6 6  
7 7 def setup
8 8 @person = fast_create(Person)
  9 + @profile = fast_create(Community)
9 10 @discussion = ProposalsDiscussionPlugin::Discussion.create!(:name => 'discussion', :profile => person, :allow_topics => false)
10 11 end
11 12  
... ... @@ -15,4 +16,17 @@ class ProposalTaskTest &lt; ActiveSupport::TestCase
15 16 assert_equal topic.name, task.proposal_source
16 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 32 end
... ...