diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-07-08 12:56:27 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-07-08 12:56:27 +0000 |
commit | 66f6bf0e8df52e842d948362bda2ed14754860d6 (patch) | |
tree | b4b964f39b3fbb829a9815b518e4a36e4432bcbf /app/models | |
parent | 8e9ce2dbee0c073e4b7616aea90f0a6324158e47 (diff) | |
download | redmine-66f6bf0e8df52e842d948362bda2ed14754860d6.tar.gz redmine-66f6bf0e8df52e842d948362bda2ed14754860d6.zip |
Merged r16766 to r16768 (#26376).
git-svn-id: http://svn.redmine.org/redmine/branches/3.4-stable@16771 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/user.rb | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 308889fcf..62a0289f0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -603,36 +603,40 @@ class User < Principal # Includes the projects that the user is a member of and the projects # that grant custom permissions to the builtin groups. def project_ids_by_role - return @project_ids_by_role if @project_ids_by_role - - group_class = anonymous? ? GroupAnonymous : GroupNonMember - group_id = group_class.pluck(:id).first - - members = Member.joins(:project, :member_roles). - where("#{Project.table_name}.status <> 9"). - where("#{Member.table_name}.user_id = ? OR (#{Project.table_name}.is_public = ? AND #{Member.table_name}.user_id = ?)", self.id, true, group_id). - pluck(:user_id, :role_id, :project_id) - - hash = {} - members.each do |user_id, role_id, project_id| - # Ignore the roles of the builtin group if the user is a member of the project - next if user_id != id && project_ids.include?(project_id) - - hash[role_id] ||= [] - hash[role_id] << project_id - end - - result = Hash.new([]) - if hash.present? - roles = Role.where(:id => hash.keys).to_a - hash.each do |role_id, proj_ids| - role = roles.detect {|r| r.id == role_id} - if role - result[role] = proj_ids.uniq + # Clear project condition for when called from chained scopes + # eg. project.children.visible(user) + Project.unscoped do + return @project_ids_by_role if @project_ids_by_role + + group_class = anonymous? ? GroupAnonymous : GroupNonMember + group_id = group_class.pluck(:id).first + + members = Member.joins(:project, :member_roles). + where("#{Project.table_name}.status <> 9"). + where("#{Member.table_name}.user_id = ? OR (#{Project.table_name}.is_public = ? AND #{Member.table_name}.user_id = ?)", self.id, true, group_id). + pluck(:user_id, :role_id, :project_id) + + hash = {} + members.each do |user_id, role_id, project_id| + # Ignore the roles of the builtin group if the user is a member of the project + next if user_id != id && project_ids.include?(project_id) + + hash[role_id] ||= [] + hash[role_id] << project_id + end + + result = Hash.new([]) + if hash.present? + roles = Role.where(:id => hash.keys).to_a + hash.each do |role_id, proj_ids| + role = roles.detect {|r| r.id == role_id} + if role + result[role] = proj_ids.uniq + end end end + @project_ids_by_role = result end - @project_ids_by_role = result end # Returns the ids of visible projects |