Skip to content

Commit

Permalink
fix: Update of organisations during flags and admin access (#4344)
Browse files Browse the repository at this point in the history
  • Loading branch information
zachaysan authored Jul 18, 2024
1 parent 61cfdbf commit 7a9edca
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions api/organisations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ def restrict_use_due_to_api_limit_grace_period_over() -> None:
)
)

update_organisations = []
api_limit_access_blocks = []
flagsmith_client = get_client("local", local_eval=True)

Expand All @@ -390,15 +389,13 @@ def restrict_use_due_to_api_limit_grace_period_over() -> None:
organisation.stop_serving_flags = stop_serving
organisation.block_access_to_admin = block_access

# Save models individually to allow lifecycle hooks to fire.
organisation.save()

api_limit_access_blocks.append(APILimitAccessBlock(organisation=organisation))
update_organisations.append(organisation)

APILimitAccessBlock.objects.bulk_create(api_limit_access_blocks)

Organisation.objects.bulk_update(
update_organisations, ["stop_serving_flags", "block_access_to_admin"]
)


def unrestrict_after_api_limit_grace_period_is_stale() -> None:
"""
Expand Down Expand Up @@ -432,7 +429,12 @@ def unrestrict_after_api_limit_grace_period_is_stale() -> None:
id__in=(organisation_ids - still_restricted_organisation_ids),
)

matching_organisations.update(stop_serving_flags=False, block_access_to_admin=False)
for organisation in matching_organisations:
organisation.stop_serving_flags = False
organisation.block_access_to_admin = False

# Save models individually to allow lifecycle hooks to fire.
organisation.save()

for organisation in matching_organisations:
organisation.api_limit_access_block.delete()
Expand Down

0 comments on commit 7a9edca

Please sign in to comment.