Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update of organisations during flags and admin access #4344

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading