Merge pull request #2998 from coreos-inc/joseph.schorr/QUAY-826/create-transaction

Make sure to add primary repo permissions under a transaction
This commit is contained in:
josephschorr 2018-02-06 15:32:42 -05:00 committed by GitHub
commit 2bdcd7f64f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,21 +38,23 @@ def create_repository(namespace, name, creating_user, visibility='private', repo
namespace_user = User.get(username=namespace) namespace_user = User.get(username=namespace)
yesterday = datetime.now() - timedelta(days=1) yesterday = datetime.now() - timedelta(days=1)
repo = Repository.create(name=name, visibility=Repository.visibility.get_id(visibility), with db_transaction():
namespace_user=namespace_user, repo = Repository.create(name=name, visibility=Repository.visibility.get_id(visibility),
kind=Repository.kind.get_id(repo_kind), namespace_user=namespace_user,
description=description) kind=Repository.kind.get_id(repo_kind),
description=description)
RepositoryActionCount.create(repository=repo, count=0, date=yesterday) RepositoryActionCount.create(repository=repo, count=0, date=yesterday)
RepositorySearchScore.create(repository=repo, score=0) RepositorySearchScore.create(repository=repo, score=0)
if creating_user and not creating_user.organization: # Note: We put the admin create permission under the transaction to ensure it is created.
admin = Role.get(name='admin') if creating_user and not creating_user.organization:
RepositoryPermission.create(user=creating_user, repository=repo, role=admin) admin = Role.get(name='admin')
RepositoryPermission.create(user=creating_user, repository=repo, role=admin)
if creating_user.username != namespace: # Apply default permissions (only occurs for repositories under organizations)
# Permission prototypes only work for orgs if creating_user and not creating_user.organization and creating_user.username != namespace:
permission.apply_default_permissions(repo, creating_user) permission.apply_default_permissions(repo, creating_user)
return repo return repo