diff --git a/data/model/legacy.py b/data/model/legacy.py index 16191b8a6..464131f55 100644 --- a/data/model/legacy.py +++ b/data/model/legacy.py @@ -642,6 +642,13 @@ def find_user_by_email(email): return None +def get_nonrobot_user(username): + try: + return User.get(User.username == username, User.organization == False, User.robot == False) + except User.DoesNotExist: + return None + + def get_user(username): try: return User.get(User.username == username, User.organization == False) diff --git a/endpoints/api/superuser.py b/endpoints/api/superuser.py index c1406dcb8..947b2a8db 100644 --- a/endpoints/api/superuser.py +++ b/endpoints/api/superuser.py @@ -238,8 +238,8 @@ class SuperUserSendRecoveryEmail(ApiResource): @nickname('sendInstallUserRecoveryEmail') def post(self, username): if SuperUserPermission().can(): - user = model.get_user(username) - if not user or user.organization or user.robot: + user = model.get_nonrobot_user(username) + if not user: abort(404) if superusers.is_superuser(username): @@ -288,8 +288,8 @@ class SuperUserManagement(ApiResource): def get(self, username): """ Returns information about the specified user. """ if SuperUserPermission().can(): - user = model.get_user(username) - if not user or user.organization or user.robot: + user = model.get_nonrobot_user(username) + if not user: abort(404) return user_view(user) @@ -302,8 +302,8 @@ class SuperUserManagement(ApiResource): def delete(self, username): """ Deletes the specified user. """ if SuperUserPermission().can(): - user = model.get_user(username) - if not user or user.organization or user.robot: + user = model.get_nonrobot_user(username) + if not user: abort(404) if superusers.is_superuser(username): @@ -321,8 +321,8 @@ class SuperUserManagement(ApiResource): def put(self, username): """ Updates information about the specified user. """ if SuperUserPermission().can(): - user = model.get_user(username) - if not user or user.organization or user.robot: + user = model.get_nonrobot_user(username) + if not user: abort(404) if superusers.is_superuser(username): diff --git a/endpoints/api/user.py b/endpoints/api/user.py index 2d17073aa..3e093888e 100644 --- a/endpoints/api/user.py +++ b/endpoints/api/user.py @@ -281,7 +281,7 @@ class User(ApiResource): user_data = request.get_json() invite_code = user_data.get('invite_code', '') - existing_user = model.get_user(user_data['username']) + existing_user = model.get_nonrobot_user(user_data['username']) if existing_user: raise request_error(message='The username already exists') @@ -821,8 +821,8 @@ class Users(ApiResource): @nickname('getUserInformation') def get(self, username): """ Get user information for the specified user. """ - user = model.get_user(username) - if user is None or user.organization or user.robot: + user = model.get_nonrobot_user(username) + if user is None: abort(404) return user_view(user) diff --git a/endpoints/notificationmethod.py b/endpoints/notificationmethod.py index 4d2d685f8..8626fd68f 100644 --- a/endpoints/notificationmethod.py +++ b/endpoints/notificationmethod.py @@ -71,7 +71,7 @@ class QuayNotificationMethod(NotificationMethod): target_info = config_data['target'] if target_info['kind'] == 'user': - target = model.get_user(target_info['name']) + target = model.get_nonrobot_user(target_info['name']) if not target: # Just to be safe. return (True, 'Unknown user %s' % target_info['name'], []) diff --git a/tools/sendconfirmemail.py b/tools/sendconfirmemail.py index 94345c573..2ec28132c 100644 --- a/tools/sendconfirmemail.py +++ b/tools/sendconfirmemail.py @@ -10,7 +10,7 @@ from flask import Flask, current_app from flask_mail import Mail def sendConfirmation(username): - user = model.get_user(username) + user = model.get_nonrobot_user(username) if not user: print 'No user found' return diff --git a/tools/sendresetemail.py b/tools/sendresetemail.py index e977c654e..0ead72283 100644 --- a/tools/sendresetemail.py +++ b/tools/sendresetemail.py @@ -10,7 +10,7 @@ from flask import Flask, current_app from flask_mail import Mail def sendReset(username): - user = model.get_user(username) + user = model.get_nonrobot_user(username) if not user: print 'No user found' return