Sfoglia il codice sorgente

Fix letting site admin subscribe to private tickets

Add tests for site admin private issue subscriptions checking it while
at it.

Fixes: https://pagure.io/pagure/issue/3419
Merges: https://pagure.io/pagure/pull-request/3457

Signed-off-by: Karsten Hopp <karsten@redhat.com>
Karsten Hopp 5 anni fa
parent
commit
19b3268de1
2 ha cambiato i file con 21 aggiunte e 7 eliminazioni
  1. 7 7
      pagure/lib/__init__.py
  2. 14 0
      tests/test_pagure_lib_watch_list.py

+ 7 - 7
pagure/lib/__init__.py

@@ -4414,13 +4414,13 @@ def get_watch_list(session, obj):
                 if watcher.user.username in users:
                     users.remove(watcher.user.username)
 
-        # Add all the people watching this object, remove those who opted-out
-        for watcher in obj_watchers_query.all():
-            if watcher.watch:
-                users.add(watcher.user.username)
-            else:
-                if watcher.user.username in users:
-                    users.remove(watcher.user.username)
+    # Add all the people watching this object, remove those who opted-out
+    for watcher in obj_watchers_query.all():
+        if watcher.watch:
+            users.add(watcher.user.username)
+        else:
+            if watcher.user.username in users:
+                users.remove(watcher.user.username)
 
     return users
 

+ 14 - 0
tests/test_pagure_lib_watch_list.py

@@ -460,6 +460,7 @@ class PagureLibGetWatchListtests(tests.Modeltests):
             set(['foo', 'bar', 'pingou'])
         )
 
+    @mock.patch.dict('pagure.config.config', {'PAGURE_ADMIN_USERS': 'foo'})
     def test_get_watch_list_project_w_private_issue(self):
         """ Test get_watch_list when the project has one contributor watching
         the project and the issue is private """
@@ -520,6 +521,19 @@ class PagureLibGetWatchListtests(tests.Modeltests):
             pagure.lib.get_watch_list(self.session, iss),
             set(['pingou'])
         )
+        out = pagure.lib.set_watch_obj(self.session, 'foo', iss, True)
+        self.assertEqual(out, 'You are now watching this issue')
+        self.assertEqual(
+            pagure.lib.get_watch_list(self.session, iss),
+            set(['pingou','foo'])
+        )
+        out = pagure.lib.set_watch_obj(self.session, 'foo', iss, False)
+        self.assertEqual(
+            out, 'You are no longer watching this issue')
+        self.assertEqual(
+            pagure.lib.get_watch_list(self.session, iss),
+            set(['pingou'])
+        )
 
 
 if __name__ == '__main__':