From 62d9eba5f7eb364d2284cc5132ac5e31756f43e6 Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Dec 02 2016 09:45:58 +0000 Subject: Issue 1620 - list subscribers on the Issue/PR pages --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 5c72474..c20ccba 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -3344,6 +3344,38 @@ def is_watching_obj(session, user, obj): return False +def get_watch_list(session, obj): + """ Return a list of all the users that are watching the "object" + """ + if obj.isa == "issue": + query = session.query( + model.IssueWatcher + ).filter( + model.IssueWatcher.issue_uid == obj.uid + ) + elif obj.isa == "pull-request": + query = session.query( + model.PullRequestWatcher + ).filter( + model.PullRequestWatcher.pull_request_uid == obj.uid + ) + else: + raise pagure.exceptions.InvalidObjectException( + 'Unsupported object found: "%s"' % obj + ) + + user_objs = query.all() + users = [] + if user_objs: + # We found watchers + for user in user_objs: + users.append(str(user.user.username)) + if str(obj.user.user) not in users: + # Add Issue/PR creator if not already in the list + users.append(str(obj.user.user)) + return users + + def save_report(session, repo, name, url, username): """ Save the report of issues based on the given URL of the project. """ diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index 4b25403..56efa0c 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -312,6 +312,19 @@ {% if authenticated %} + {% if subscribers %} +
+
+
+ +
+ {{ subscribers | join(', ') }} +
+
+
+
+ {% endif %} +
+ + {% if subscribers and authenticated %} +
+
+
+ +
+ {{ subscribers | join(', ') }} +
+
+
+
+ {% endif %} + {% endif %} {% if diff and pull_request%} diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index 99b4054..c1837b8 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -317,6 +317,7 @@ def request_pull(repo, requestid, username=None, namespace=None): diff_commits=diff_commits, diff=diff, mergeform=form, + subscribers=pagure.lib.get_watch_list(SESSION, request), ) diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index 8447598..416d04e 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -894,6 +894,7 @@ def view_issue(repo, issueid, username=None, namespace=None): form=form, knowns_keys=knowns_keys, subscribed=subscribed, + subscribers=pagure.lib.get_watch_list(SESSION, issue), )