From 2c802a2bdf3ad125a4051f9b04a96a9b51e0661b Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Mon, 28 Oct 2024 20:46:09 +0000 Subject: Merged r22913-r22917 from trunk to 5.1-stable (#40946). git-svn-id: https://svn.redmine.org/redmine/branches/5.1-stable@23167 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/plugins') diff --git a/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb b/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb index 1a5888464..139766b21 100644 --- a/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb +++ b/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb @@ -43,6 +43,24 @@ module Redmine users end + # array of watchers that the given user is allowed to see + def visible_watcher_users(user = User.current) + if user.allowed_to?(:"view_#{self.class.name.underscore}_watchers", project) + watcher_users + else + # without permission, the user can only see themselves (if they're a watcher) + watcher_users & [user] + end + end + + # true if user can be added as a watcher + def valid_watcher?(user) + return true unless respond_to?(:visible?) + return true unless user.is_a?(User) + + visible?(user) + end + # Adds user as a watcher def add_watcher(user) if persisted? -- cgit v1.2.3