From 8a2c88488aae17a5455d9270b20fff2378bf8dbc Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Fri, 18 Jul 2014 14:56:26 -0400 Subject: [PATCH] Filter tokens with an associated build trigger from the list API. Delete associated tokens when deleting a trigger. --- data/model/legacy.py | 16 +++++++++------- endpoints/api/trigger.py | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/data/model/legacy.py b/data/model/legacy.py index e59cae6b9..811979981 100644 --- a/data/model/legacy.py +++ b/data/model/legacy.py @@ -1402,12 +1402,14 @@ def create_delegate_token(namespace_name, repository_name, friendly_name, def get_repository_delegate_tokens(namespace_name, repository_name): - selected = AccessToken.select(AccessToken, Role) - with_repo = selected.join(Repository) - with_role = with_repo.switch(AccessToken).join(Role) - return with_role.where(Repository.name == repository_name, - Repository.namespace == namespace_name, - AccessToken.temporary == False) + return (AccessToken.select(AccessToken, Role) + .join(Repository) + .switch(AccessToken) + .join(Role) + .switch(AccessToken) + .join(RepositoryBuildTrigger, JOIN_LEFT_OUTER) + .where(Repository.name == repository_name, Repository.namespace == namespace_name, + AccessToken.temporary == False, RepositoryBuildTrigger.uuid >> None)) def get_repo_delegate_token(namespace_name, repository_name, code): @@ -1435,7 +1437,7 @@ def set_repo_delegate_token_role(namespace_name, repository_name, code, role): def delete_delegate_token(namespace_name, repository_name, code): token = get_repo_delegate_token(namespace_name, repository_name, code) - token.delete_instance() + token.delete_instance(recursive=True) return token diff --git a/endpoints/api/trigger.py b/endpoints/api/trigger.py index 20ab04330..47d36a547 100644 --- a/endpoints/api/trigger.py +++ b/endpoints/api/trigger.py @@ -81,6 +81,7 @@ class BuildTrigger(RepositoryParamResource): 'service': trigger.service.name, 'config': config_dict}, repo=model.get_repository(namespace, repository)) + trigger.write_token.delete_instance() trigger.delete_instance(recursive=True) return 'No Content', 204