Merged r15586 (#23172).

git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@15743 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2016-08-20 11:45:49 +00:00
parent 7a450e1b84
commit e8afae7cbc
5 changed files with 36 additions and 13 deletions

View File

@@ -35,16 +35,8 @@ class ContextMenusController < ApplicationController
:add_watchers => User.current.allowed_to?(:add_issue_watchers, @projects), :add_watchers => User.current.allowed_to?(:add_issue_watchers, @projects),
:delete => @issues.all?(&:deletable?) :delete => @issues.all?(&:deletable?)
} }
if @project
if @issue @assignables = @issues.map(&:assignable_users).reduce(:&)
@assignables = @issue.assignable_users
else
@assignables = @project.assignable_users
end
else
#when multiple projects, we only keep the intersection of each set
@assignables = @projects.map(&:assignable_users).reduce(:&)
end
@trackers = @projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&) @trackers = @projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&)
@versions = @projects.map {|p| p.shared_versions.open}.reduce(:&) @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)

View File

@@ -854,7 +854,7 @@ class Issue < ActiveRecord::Base
# Users the issue can be assigned to # Users the issue can be assigned to
def assignable_users def assignable_users
users = project.assignable_users.to_a users = project.assignable_users(tracker).to_a
users << author if author && author.active? users << author if author && author.active?
users << assigned_to if assigned_to users << assigned_to if assigned_to
users.uniq.sort users.uniq.sort

View File

@@ -512,16 +512,27 @@ class Project < ActiveRecord::Base
end end
# Return a Principal scope of users/groups issues can be assigned to # Return a Principal scope of users/groups issues can be assigned to
def assignable_users def assignable_users(tracker=nil)
return @assignable_users[tracker] if @assignable_users && @assignable_users[tracker]
types = ['User'] types = ['User']
types << 'Group' if Setting.issue_group_assignment? types << 'Group' if Setting.issue_group_assignment?
@assignable_users ||= Principal. scope = Principal.
active. active.
joins(:members => :roles). joins(:members => :roles).
where(:type => types, :members => {:project_id => id}, :roles => {:assignable => true}). where(:type => types, :members => {:project_id => id}, :roles => {:assignable => true}).
uniq. uniq.
sorted sorted
if tracker
# Rejects users that cannot the view the tracker
roles = Role.where(:assignable => true).select {|role| role.permissions_tracker?(:view_issues, tracker)}
scope = scope.where(:roles => {:id => roles.map(&:id)})
end
@assignable_users ||= {}
@assignable_users[tracker] = scope
end end
# Returns the mail addresses of users that should be always notified on project events # Returns the mail addresses of users that should be always notified on project events

View File

@@ -222,6 +222,13 @@ class Role < ActiveRecord::Base
permissions_all_trackers[permission.to_s].to_s != '0' permissions_all_trackers[permission.to_s].to_s != '0'
end end
# Returns true if permission is given for the tracker
# (explicitly or for all trackers)
def permissions_tracker?(permission, tracker)
permissions_all_trackers?(permission) ||
permissions_tracker_ids?(permission, tracker.try(:id))
end
# Sets the trackers that are allowed for a permission. # Sets the trackers that are allowed for a permission.
# tracker_ids can be an array of tracker ids or :all for # tracker_ids can be an array of tracker ids or :all for
# no restrictions. # no restrictions.

View File

@@ -2292,6 +2292,19 @@ class IssueTest < ActiveSupport::TestCase
end end
end end
def test_assignable_users_should_not_include_users_that_cannot_view_the_tracker
user = User.find(3)
role = Role.find(2)
role.set_permission_trackers :view_issues, [1, 3]
role.save!
issue1 = Issue.new(:project_id => 1, :tracker_id => 1)
issue2 = Issue.new(:project_id => 1, :tracker_id => 2)
assert_include user, issue1.assignable_users
assert_not_include user, issue2.assignable_users
end
def test_create_should_send_email_notification def test_create_should_send_email_notification
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
issue = Issue.new(:project_id => 1, :tracker_id => 1, issue = Issue.new(:project_id => 1, :tracker_id => 1,