- Turn on foreign key constraint checking in the tests

- Change all ForeignKeyField's that refer to users to use our custom class, and mark those that allow robots
- Change robot delete to only execute the subset of queries necessary to actually delete robots
This commit is contained in:
Joseph Schorr 2014-11-07 12:05:21 -05:00
parent 8548538516
commit 158acd4f41
4 changed files with 104 additions and 24 deletions

View file

@ -14,7 +14,7 @@ from data.database import (User, Repository, Image, AccessToken, Role, Repositor
ExternalNotificationEvent, ExternalNotificationMethod,
RepositoryNotification, RepositoryAuthorizedEmail, TeamMemberInvite,
DerivedImageStorage, ImageStorageTransformation, random_string_generator,
db, BUILD_PHASE)
db, BUILD_PHASE, QuayUserField)
from peewee import JOIN_LEFT_OUTER, fn
from util.validation import (validate_username, validate_email, validate_password,
INVALID_PASSWORD_MESSAGE)
@ -287,7 +287,16 @@ def regenerate_robot_token(robot_shortname, parent):
def delete_robot(robot_username):
try:
robot = User.get(username=robot_username, robot=True)
robot.delete_instance(recursive=True, delete_nullable=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)
except User.DoesNotExist:
raise InvalidRobotException('Could not find robot with username: %s' %
robot_username)