From 53887dd204805ba368613fcecbb796ee69f171a4 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 10 2017 09:21:15 +0000 Subject: Do not include watchers in the subscribers of an issue Fixes https://pagure.io/pagure/issue/2080 --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index ad7a606..bb35e11 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -3656,7 +3656,9 @@ def set_watch_obj(session, user, obj, watch_status): def get_watch_list(session, obj): """ Return a list of all the users that are watching the "object" """ + private = False if obj.isa == "issue": + private = obj.private obj_watchers_query = session.query( model.IssueWatcher ).filter( @@ -3700,21 +3702,23 @@ def get_watch_list(session, obj): for member in group.users: users.add(member.username) - # Add all the people watching the repo, remove those who opted-out - for watcher in project_watchers_query.all(): - if watcher.watch: - users.add(watcher.user.username) - else: - if watcher.user.username in users: - users.remove(watcher.user.username) + # If the issue isn't private: + if not private: + # Add all the people watching the repo, remove those who opted-out + for watcher in project_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) + # 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 diff --git a/tests/test_pagure_lib_watch_list.py b/tests/test_pagure_lib_watch_list.py index 40cebd4..70be7b8 100644 --- a/tests/test_pagure_lib_watch_list.py +++ b/tests/test_pagure_lib_watch_list.py @@ -457,6 +457,66 @@ class PagureLibGetWatchListtests(tests.Modeltests): set(['foo', 'bar', 'pingou']) ) + 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 """ + # Create a project ns/test3 + item = pagure.lib.model.Project( + user_id=1, # pingou + name='test3', + namespace='ns', + description='test project #1', + hook_token='aaabbbcccdd', + ) + item.close_status = ['Invalid', 'Insufficient data', 'Fixed'] + self.session.add(item) + self.session.commit() + + # Add a new user + item = pagure.lib.model.User( + user='bar', + fullname='bar foo', + password='foo', + default_email='bar@bar.com', + ) + self.session.add(item) + item = pagure.lib.model.UserEmail( + user_id=3, + email='bar@bar.com') + self.session.add(item) + + # Set the user `bar` to watch the project + project = pagure.lib.get_project( + self.session, 'test3', namespace='ns') + msg = pagure.lib.update_watch_status( + session=self.session, + project=project, + user='bar', + watch=True, + ) + self.session.commit() + self.assertEqual(msg, 'You are now watching this repo.') + + # Create the ticket + iss = pagure.lib.new_issue( + issue_id=4, + session=self.session, + repo=project, + title='test issue', + content='content test issue', + user='pingou', + private=True, + ticketfolder=None, + ) + self.session.commit() + self.assertEqual(iss.id, 4) + self.assertEqual(iss.title, 'test issue') + + self.assertEqual( + pagure.lib.get_watch_list(self.session, iss), + set(['pingou']) + ) + if __name__ == '__main__': unittest.main()