summaryrefslogtreecommitdiffstats
path: root/app/models/member.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-12-13 12:39:22 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-12-13 12:39:22 +0000
commitf33231181f9591ee67577e229a8bf6de24516ba0 (patch)
tree57bbc4338b9cf35cecf323565fefbf549ecfd14f /app/models/member.rb
parentc31a6719735114c371e5da68eb3787b8713c5360 (diff)
downloadredmine-f33231181f9591ee67577e229a8bf6de24516ba0.tar.gz
redmine-f33231181f9591ee67577e229a8bf6de24516ba0.zip
Makes user unwatch what he can no longer view after its permissions have changed (#3589).
A rake task (redmine:watchers:prune) is also added to prune existing watchers. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3167 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/member.rb')
-rw-r--r--app/models/member.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/app/models/member.rb b/app/models/member.rb
index 6fffb2161..44a421745 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -24,6 +24,8 @@ class Member < ActiveRecord::Base
validates_presence_of :principal, :project
validates_uniqueness_of :user_id, :scope => :project_id
+
+ after_destroy :unwatch_from_permission_change
def name
self.user.name
@@ -39,7 +41,11 @@ class Member < ActiveRecord::Base
# Add new roles
new_role_ids.each {|id| member_roles << MemberRole.new(:role_id => id) }
# Remove roles (Rails' #role_ids= will not trigger MemberRole#on_destroy)
- member_roles.select {|mr| !ids.include?(mr.role_id)}.each(&:destroy)
+ member_roles_to_destroy = member_roles.select {|mr| !ids.include?(mr.role_id)}
+ if member_roles_to_destroy.any?
+ member_roles_to_destroy.each(&:destroy)
+ unwatch_from_permission_change
+ end
end
def <=>(member)
@@ -63,4 +69,13 @@ class Member < ActiveRecord::Base
def validate
errors.add_to_base "Role can't be blank" if member_roles.empty? && roles.empty?
end
+
+ private
+
+ # Unwatch things that the user is no longer allowed to view inside project
+ def unwatch_from_permission_change
+ if user
+ Watcher.prune(:user => user, :project => project)
+ end
+ end
end