From e69883363db57db1cccf9578b028f46f2ca0a609 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Aug 30 2017 15:57:53 +0000 Subject: [PATCH 1/2] Don't expand groups in the watchers API. This should fix https://pagure.io/fedora-infrastructure/issue/6315 The rhbz sync script subscribes every user on the watchers list to every bugzilla mail, but as discussed in the ticket and on the devel list: this doesn't match the old behavior and is highly undesirable. --- diff --git a/pagure/api/project.py b/pagure/api/project.py index 1700a20..75b826c 100644 --- a/pagure/api/project.py +++ b/pagure/api/project.py @@ -113,21 +113,23 @@ def api_project_watchers(repo, username=None, namespace=None): implicit_watch_users = \ implicit_watch_users | set( [user.username for user in repo.access_users[access_type]]) - for access_type in repo.access_groups.keys(): - group_names = [group.group_name - for group in repo.access_groups[access_type]] - for group_name in group_names: - group = pagure.lib.search_groups(SESSION, group_name=group_name) - implicit_watch_users = \ - implicit_watch_users | set([ - user.username for user in group.users]) - watching_users_to_watch_level = {} for implicit_watch_user in implicit_watch_users: user_watch_level = pagure.lib.get_watch_level_on_repo( SESSION, implicit_watch_user, repo) watching_users_to_watch_level[implicit_watch_user] = user_watch_level + for access_type in repo.access_groups.keys(): + group_names = ['@' + group.group_name + for group in repo.access_groups[access_type]] + for group_name in group_names: + if not group_name in watching_users_to_watch_level: + watching_users_to_watch_level[group_name] = set() + # By the logic in pagure.lib.get_watch_level_on_repo, group members + # only by default watch issues. If they want to watch commits they + # have to explicitly subscribe. + watching_users_to_watch_level[group_name].add('issues') + # Get the explicit watch statuses for watcher in repo.watchers: if watcher.watch_issues or watcher.watch_commits: diff --git a/tests/test_pagure_flask_api_project.py b/tests/test_pagure_flask_api_project.py index 59766c7..12dd514 100644 --- a/tests/test_pagure_flask_api_project.py +++ b/tests/test_pagure_flask_api_project.py @@ -1593,7 +1593,7 @@ class PagureFlaskApiProjecttests(tests.Modeltests): expected_data = { "total_watchers": 2, "watchers": { - "foo": ["issues"], + "@some_group": ["issues"], "pingou": ["issues"] } } @@ -1609,8 +1609,9 @@ class PagureFlaskApiProjecttests(tests.Modeltests): output = self.app.get('/api/0/test/watchers') self.assertEqual(output.status_code, 200) expected_data = { - "total_watchers": 2, + "total_watchers": 3, "watchers": { + "@some_group": ["issues"], "foo": ["commits"], "pingou": ["issues"] } From 02a9cef86826efa3657df600440d2d19a4b32cfd Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Aug 30 2017 18:17:35 +0000 Subject: [PATCH 2/2] PEP8!!!!!! --- diff --git a/pagure/api/project.py b/pagure/api/project.py index 75b826c..17f0c7d 100644 --- a/pagure/api/project.py +++ b/pagure/api/project.py @@ -123,7 +123,7 @@ def api_project_watchers(repo, username=None, namespace=None): group_names = ['@' + group.group_name for group in repo.access_groups[access_type]] for group_name in group_names: - if not group_name in watching_users_to_watch_level: + if group_name not in watching_users_to_watch_level: watching_users_to_watch_level[group_name] = set() # By the logic in pagure.lib.get_watch_level_on_repo, group members # only by default watch issues. If they want to watch commits they