]> source.dussan.org Git - redmine.git/commitdiff
Memorize project override roles.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 24 Jan 2015 08:54:04 +0000 (08:54 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 24 Jan 2015 08:54:04 +0000 (08:54 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13934 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb

index e0994b4ba86b95c2c5b4ac273b78911b8eeb555a..83c678bda854e1e934d7794178d5e4cc0d5f5571 100644 (file)
@@ -216,8 +216,11 @@ class Project < ActiveRecord::Base
   end
 
   def override_roles(role)
+    @override_members ||= member_principals.
+      where("#{Principal.table_name}.type IN (?)", ['GroupAnonymous', 'GroupNonMember']).to_a
+
     group_class = role.anonymous? ? GroupAnonymous : GroupNonMember
-    member = member_principals.where("#{Principal.table_name}.type = ?", group_class.name).first
+    member = @override_members.detect {|m| m.principal.is_a? group_class}
     member ? member.roles.to_a : [role]
   end