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(versioning): ensure that audit log record is created when committing versions via CR #4091

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
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
)
Comment on lines +173 to +175
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see from this review where environment_feature_version_published is actually coming from.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a signal defined here and consumed here.

I kind of hate using signals because it can be a bit hard to track the execution stack, but I seem to remember having no choice in this case.


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()