Skip to content

Commit

Permalink
Remove get_related_feature_id logic and add a new endpoint to retri…
Browse files Browse the repository at this point in the history
…eve an environment feature version without the path args
  • Loading branch information
matthewelwell committed Jun 3, 2024
1 parent a8b883b commit eb8ccb5
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 249 deletions.
31 changes: 0 additions & 31 deletions api/audit/audit_helpers.py

This file was deleted.

6 changes: 0 additions & 6 deletions api/audit/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from drf_yasg.utils import swagger_serializer_method
from rest_framework import serializers

from audit.audit_helpers import get_related_feature_id
from audit.models import AuditLog
from environments.serializers import EnvironmentSerializerLight
from projects.serializers import ProjectListSerializer
Expand Down Expand Up @@ -43,7 +42,6 @@ class AuditLogRetrieveSerializer(serializers.ModelSerializer):
project = ProjectListSerializer()
change_details = serializers.SerializerMethodField()
change_type = serializers.SerializerMethodField()
related_feature_id = serializers.SerializerMethodField()

class Meta:
model = AuditLog
Expand All @@ -60,7 +58,6 @@ class Meta:
"is_system_event",
"change_details",
"change_type",
"related_feature_id",
)

@swagger_serializer_method(
Expand All @@ -86,9 +83,6 @@ def get_change_type(self, instance: AuditLog) -> str:
"~": "UPDATE",
}.get(history_record.history_type)

def get_related_feature_id(self, instance: AuditLog) -> int | None:
return get_related_feature_id(instance)


class AuditLogsQueryParamSerializer(serializers.Serializer):
project = serializers.IntegerField(required=False)
Expand Down
7 changes: 7 additions & 0 deletions api/features/versioning/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ def has_object_permission(
)


class EnvironmentFeatureVersionRetrievePermissions(BasePermission):
def has_object_permission(self, request, view, obj):
return request.user.has_environment_permission(
VIEW_ENVIRONMENT, obj.environment
)


class EnvironmentFeatureVersionFeatureStatePermissions(BasePermission):
def has_permission(self, request: Request, view: GenericViewSet) -> bool:
environment_pk = view.kwargs["environment_pk"]
Expand Down
6 changes: 6 additions & 0 deletions api/features/versioning/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from features.versioning.views import (
EnvironmentFeatureVersionFeatureStatesViewSet,
EnvironmentFeatureVersionRetrieveAPIView,
EnvironmentFeatureVersionViewSet,
)

Expand Down Expand Up @@ -34,4 +35,9 @@
"environments/<int:environment_pk>/features/<int:feature_pk>/",
include(ef_version_fs_router.urls),
),
path(
"environment-feature-versions/<str:pk>/",
EnvironmentFeatureVersionRetrieveAPIView.as_view(),
name="get-efv-by-uuid",
),
]
20 changes: 18 additions & 2 deletions api/features/versioning/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from django.utils.decorators import method_decorator
from drf_yasg.utils import swagger_auto_schema
from rest_framework.decorators import action
from rest_framework.generics import RetrieveAPIView
from rest_framework.mixins import (
CreateModelMixin,
DestroyModelMixin,
ListModelMixin,
RetrieveModelMixin,
UpdateModelMixin,
)
from rest_framework.permissions import IsAuthenticated
Expand All @@ -26,6 +26,7 @@
from features.versioning.permissions import (
EnvironmentFeatureVersionFeatureStatePermissions,
EnvironmentFeatureVersionPermissions,
EnvironmentFeatureVersionRetrievePermissions,
)
from features.versioning.serializers import (
EnvironmentFeatureVersionFeatureStateSerializer,
Expand All @@ -46,7 +47,6 @@
)
class EnvironmentFeatureVersionViewSet(
GenericViewSet,
RetrieveModelMixin,
ListModelMixin,
CreateModelMixin,
DestroyModelMixin,
Expand Down Expand Up @@ -135,6 +135,22 @@ def publish(self, request: Request, **kwargs) -> Response:
return Response(serializer.data)


class EnvironmentFeatureVersionRetrieveAPIView(RetrieveAPIView):
"""
This is an additional endpoint to retrieve a specific version without needing
to provide the environment or feature as part of the URL.
"""

permission_classes = [
IsAuthenticated,
EnvironmentFeatureVersionRetrievePermissions,
]
serializer_class = EnvironmentFeatureVersionRetrieveSerializer

def get_queryset(self):
return EnvironmentFeatureVersion.objects.all()


class EnvironmentFeatureVersionFeatureStatesViewSet(
GenericViewSet,
ListModelMixin,
Expand Down
103 changes: 0 additions & 103 deletions api/tests/unit/audit/test_unit_audit_helpers.py

This file was deleted.

1 change: 0 additions & 1 deletion api/tests/unit/audit/test_unit_audit_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def test_retrieve_environment_feature_version_published_audit_log_record_include
response_json = response.json()
assert response_json["related_object_uuid"] == str(new_version.uuid)
assert response_json["related_object_type"] == RelatedObjectType.EF_VERSION.name
assert response_json["related_feature_id"] == new_version.feature_id
assert (
response_json["log"]
== ENVIRONMENT_FEATURE_VERSION_PUBLISHED_MESSAGE % feature.name
Expand Down
Loading

0 comments on commit eb8ccb5

Please sign in to comment.