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"] }