Move the robot deletion code into a delete_instance method on the User object
This commit is contained in:
parent
158acd4f41
commit
72fedef097
2 changed files with 14 additions and 9 deletions
|
@ -287,15 +287,7 @@ def regenerate_robot_token(robot_shortname, parent):
|
|||
def delete_robot(robot_username):
|
||||
try:
|
||||
robot = User.get(username=robot_username, robot=True)
|
||||
|
||||
# For all the model dependencies, only delete those that allow robots.
|
||||
for query, fk in robot.dependencies(search_nullable=True):
|
||||
if isinstance(fk, QuayUserField) and fk.allows_robots:
|
||||
model = fk.model_class
|
||||
model.delete().where(query).execute()
|
||||
|
||||
# Delete the robot itself.
|
||||
robot.delete_instance(recursive=False)
|
||||
robot.delete_instance(recursive=True, delete_nullable=True)
|
||||
|
||||
except User.DoesNotExist:
|
||||
raise InvalidRobotException('Could not find robot with username: %s' %
|
||||
|
|
Reference in a new issue