Filter tokens with an associated build trigger from the list API. Delete associated tokens when deleting a trigger.

This commit is contained in:
Jake Moshenko 2014-07-18 14:56:26 -04:00
parent 3d852aa9d3
commit 8a2c88488a
2 changed files with 10 additions and 7 deletions

View file

@ -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

View file

@ -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