Skip to content

Commit

Permalink
Use transaction.atomic in context manager form
Browse files Browse the repository at this point in the history
Co-authored-by: Mike VanDenburgh <[email protected]>
  • Loading branch information
jjnesbitt and mvandenburgh committed Jan 2, 2025
1 parent a57538a commit 265f0f2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions dandiapi/api/services/permissions/dandiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ def add_dandiset_owner(dandiset: Dandiset, user: User):
assign_perm('owner', user, dandiset)


@transaction.atomic
def replace_dandiset_owners(dandiset: Dandiset, users: list[User]):
existing_owners = get_dandiset_owners(dandiset)
existing_owner_set = set(existing_owners)
new_owner_set = set(users)

# Delete all existing owners
DandisetUserObjectPermission.objects.filter(
content_object=dandiset.pk, permission__codename='owner'
).delete()
with transaction.atomic():
# Delete all existing owners
DandisetUserObjectPermission.objects.filter(
content_object=dandiset.pk, permission__codename='owner'
).delete()

# Set owners to new list
for user in users:
add_dandiset_owner(dandiset, user)
# Set owners to new list
for user in users:
add_dandiset_owner(dandiset, user)

# Return the owners added/removed so they can be emailed
removed_owners = existing_owner_set - new_owner_set
Expand Down

0 comments on commit 265f0f2

Please sign in to comment.