From d373386692669a1eaa137d02ea9b3a348f16ebdf Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 11 2016 14:21:14 +0000 Subject: [PATCH 1/7] If a ticket is public notify the users watching the project --- diff --git a/pagure/lib/notify.py b/pagure/lib/notify.py index 0ca8443..885492d 100644 --- a/pagure/lib/notify.py +++ b/pagure/lib/notify.py @@ -122,6 +122,11 @@ def _get_emails_for_issue(issue): if issue.assignee and issue.assignee.default_email: emails.add(issue.assignee.default_email) + # Add the person watching this project, if the issue is public + if issue.isa == 'issue' and not issue.private: + for watcher in issue.project.watchers: + emails.add(watcher.user.default_email) + # Remove the person list in unwatch for unwatcher in issue.project.unwatchers: if unwatcher.user.default_email in emails: From c8160dd863526147ec2d88850674371a7eff4ef9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 11 2016 14:50:07 +0000 Subject: [PATCH 2/7] Make pagure.lib.is_watching accept directly a reponame and its username --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index a02e3a4..c4032ac 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -2822,7 +2822,7 @@ def update_watch_status(session, project, user, watch): return msg_success -def is_watching(session, user, project): +def is_watching(session, user, reponame, repouser=None): ''' Check user watching the project. ''' if user is None: @@ -2832,14 +2832,30 @@ def is_watching(session, user, project): if not user_obj: return False - watcher = session.query( + query = session.query( model.Watcher ).filter( - sqlalchemy.and_( - model.Watcher.project_id == project.id, - model.Watcher.user_id == user_obj.id, + model.Watcher.user_id == user_obj.id + ).filter( + model.Watcher.project_id == model.Project.id + ).filter( + model.Project.name == reponame + ) + + if repouser is not None: + query = query.filter( + model.User.user == repouser + ).filter( + model.User.id == model.Project.user_id + ).filter( + model.Project.parent_id != None ) - ).first() + else: + query = query.filter( + model.Project.parent_id == None + ) + + watcher = query.first() if watcher: return watcher.watch From f21cbaa768bd248203a954407301ccc5e461bacf Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 11 2016 14:50:29 +0000 Subject: [PATCH 3/7] Pass to all the templates the is_watching function --- diff --git a/pagure/__init__.py b/pagure/__init__.py index 8888a2e..fe2c2f1 100644 --- a/pagure/__init__.py +++ b/pagure/__init__.py @@ -348,11 +348,19 @@ def inject_variables(): if justlogedout: flask.session['_justloggedout'] = None + def is_watching(reponame, username=None): + watch = False + if authenticated(): + watch = pagure.lib.is_watching( + SESSION, flask.g.fas_user, reponame, repouser=username) + return watch + return dict( version=__version__, admin=user_admin, authenticated=authenticated(), forkbuttonform=forkbuttonform, + is_watching=is_watching, ) From b13b8b6e52faa701c171c54c1be0b12eb244ec28 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 11 2016 14:50:43 +0000 Subject: [PATCH 4/7] Make use of the is_watching function and adjust style The is_watching function allows to know if the current user is watching the specified repo or not. --- diff --git a/pagure/templates/repo_master.html b/pagure/templates/repo_master.html index dd58575..9fd4e5e 100644 --- a/pagure/templates/repo_master.html +++ b/pagure/templates/repo_master.html @@ -31,12 +31,20 @@ {% if authenticated %}
- - +