Skip to content

Commit

Permalink
fix(versioning): ensure that audit log record is created when committ…
Browse files Browse the repository at this point in the history
…ing versions via CR (#4091)
  • Loading branch information
matthewelwell authored Jun 3, 2024
1 parent 60c0748 commit 8246dca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/features/workflows/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from environments.tasks import rebuild_environment_document
from features.models import FeatureState
from features.versioning.models import EnvironmentFeatureVersion
from features.versioning.signals import environment_feature_version_published
from features.versioning.tasks import trigger_update_version_webhooks
from features.workflows.core.exceptions import (
CannotApproveOwnChangeRequest,
Expand Down Expand Up @@ -169,6 +170,9 @@ def _publish_environment_feature_versions(
kwargs={"environment_id": self.environment_id},
delay_until=environment_feature_version.live_from,
)
environment_feature_version_published.send(
EnvironmentFeatureVersion, instance=environment_feature_version
)

def get_create_log_message(self, history_instance) -> typing.Optional[str]:
return CHANGE_REQUEST_CREATED_MESSAGE % self.title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
CHANGE_REQUEST_APPROVED_MESSAGE,
CHANGE_REQUEST_COMMITTED_MESSAGE,
CHANGE_REQUEST_CREATED_MESSAGE,
ENVIRONMENT_FEATURE_VERSION_PUBLISHED_MESSAGE,
FEATURE_STATE_UPDATED_BY_CHANGE_REQUEST_MESSAGE,
)
from audit.models import AuditLog
Expand Down Expand Up @@ -703,3 +704,30 @@ def test_can_delete_committed_change_request_scheduled_for_the_future_with_envir

# Then
assert not ChangeRequest.objects.filter(id=change_request.id).exists()


def test_committing_change_request_with_environment_feature_versions_creates_publish_audit_log(
feature: Feature, environment_v2_versioning: Environment, admin_user: FFAdminUser
) -> None:
# Given
change_request = ChangeRequest.objects.create(
title="Test CR",
environment=environment_v2_versioning,
user=admin_user,
)

environment_feature_version = EnvironmentFeatureVersion.objects.create(
environment=environment_v2_versioning,
feature=feature,
change_request=change_request,
)

# When
change_request.commit(admin_user)

# Then
assert AuditLog.objects.filter(
related_object_uuid=environment_feature_version.uuid,
related_object_type=RelatedObjectType.EF_VERSION.name,
log=ENVIRONMENT_FEATURE_VERSION_PUBLISHED_MESSAGE % feature.name,
).exists()

0 comments on commit 8246dca

Please sign in to comment.