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(organisation): allow Organisation delete when committed change request present #5101

Merged
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion api/features/workflows/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ def prevent_change_request_delete_if_committed(self) -> None:
# deleted but, since this can have unexpected effects on published
# feature states, we also want to prevent it at the ORM level.
if self.committed_at and not (
self.environment.deleted_at
(self.environment and self.environment.deleted_at)
or (self.project and self.project.deleted_at)
or (self.live_from and self.live_from > timezone.now())
):
raise ChangeRequestDeletionError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
ChangeRequestApproval,
ChangeRequestGroupAssignment,
)
from organisations.models import Organisation
from projects.models import Project
from segments.models import Condition, Segment, SegmentRule
from users.models import FFAdminUser
Expand Down Expand Up @@ -1003,3 +1004,22 @@ def test_url_via_project(project_change_request: ChangeRequest) -> None:
expected_url = get_current_site_url()
expected_url += f"/project/{project_id}/change-requests/{project_change_request.id}"
assert url == expected_url


def test_delete_organisation_with_committed_change_request(
organisation: Organisation,
feature: Feature,
change_request_no_required_approvals: ChangeRequest,
admin_user: FFAdminUser,
) -> None:
"""
Specific test to cover https://github.com/Flagsmith/flagsmith/issues/5097
"""
# Given
change_request_no_required_approvals.commit(admin_user)

# When
organisation.delete()

# Then
assert organisation.deleted_at is not None
Loading