maxrossello / redmine_extended_watchers

Grant additional issue and project view permissions to watcher users
GNU General Public License v3.0
44 stars 20 forks source link

extended_watchers to group users (redmine 4.2.x) #30

Closed ebergu78 closed 2 years ago

ebergu78 commented 3 years ago

Hi!

Redmine 4.2.0 allows adding user groups as watchers for issues, but redmine_extended_watchers 4.2.0 (policy = Extended) doesn't extend the scope of issue visibility to group users.

ebergu78 commented 3 years ago

watcher group users cannot open the issue (Issues visibility = created by or assigned by the user) Error 403 Instead if I add the user as a watcher then the user can open the issue

maxrossello commented 3 years ago

ok, I suppose I need to add some unit test for the scenario. Thanks

maxrossello commented 3 years ago

Ok, I confirm that in extended mode, when adding a group of members as watchers, the group members do not gain visibility to the issue as it happens when added individually.

ebergu78 commented 3 years ago

It would be helpful if you could fix it soon. Thanks a lot

maxrossello commented 3 years ago

not so easy because act_as_watchable.watched_by? does not support group watching by itself

maxrossello commented 3 years ago

I am validating this patch

diff --git a/plugins/redmine_extended_watchers/lib/extended_watchers_issue_patch.rb b/plugins/redmin
e_extended_watchers/lib/extended_watchers_issue_patch.rb
index 2a982fff7..817390e5b 100644
--- a/plugins/redmine_extended_watchers/lib/extended_watchers_issue_patch.rb
+++ b/plugins/redmine_extended_watchers/lib/extended_watchers_issue_patch.rb
@@ -94,6 +94,15 @@ module ExtendedWatchersIssueClassPatch
       scope.to_a
     end
   end
+  
+  # Override the acts_as_watchable scope to report watchers through watchers groups
+  def watched_by(user)
+    if (user.is_a?(User))
+      joins(:watcher_users).where("#{Watcher.table_name}.user_id IN (?)", user.groups.ids << user.id)
+    else
+      super(user)
+    end
+  end

 end

@@ -136,6 +145,14 @@ module ExtendedWatchersIssueInstancePatch
     users
   end

+  def watched_by?(user)
+    if (user && user.is_a?(User))
+      !!(self.watcher_user_ids.detect {|uid| (user.groups.ids << user.id).include? uid })
+    else
+      super(user)
+    end
+  end
+
 end
maxrossello commented 2 years ago

Fix deployed in release 4.2.2 (branches: 4.2 and master). Thanks