From 784502195d27b5018d0e22a4ca4d71e32a53ae6b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 15 2016 13:25:43 +0000 Subject: Adjust is_watching - Keep user be the user passed on to the method - Make sure the method never raises an exception, this method is called in every single endpoint of the repo controller making it painful if it return True/False and raises exception while at the same time not working if the user is logged out. --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 340fd3f..d72a3c8 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -2784,17 +2784,16 @@ def update_watch_status(session, project, user, watch): msg_success = 'You are no longer watching this repo.' return msg_success + def is_watching(session, user, project): ''' Check user watching the project. ''' if user is None: return False - user = user.username - user_obj = __get_user(session, user) + user_obj = search_user(session, username=user.username) if not user_obj: - raise pagure.exceptions.PagureException( - 'No user with username: %s' % user) + return False watcher = session.query( model.Watcher @@ -2809,12 +2808,12 @@ def is_watching(session, user, project): return watcher.watch watch=False - if user == project.user.user: + if user.username == project.user.username: return True for group in project.groups: for guser in group.users: - if user == guser.username: + if user.username == guser.username: watch=True break