-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional refactoring + fixing post merge
- Loading branch information
1 parent
ea39474
commit 6391840
Showing
5 changed files
with
62 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from rest_framework.exceptions import APIException | ||
|
||
|
||
class FeatureVersioningError(APIException): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,36 @@ | ||
from datetime import datetime | ||
|
||
from rest_framework.exceptions import ValidationError | ||
from rest_framework.serializers import ModelSerializer | ||
|
||
from features.serializers import CreateSegmentOverrideFeatureStateSerializer | ||
from features.versioning.models import EnvironmentFeatureVersion | ||
|
||
|
||
class EnvironmentFeatureVersionFeatureStateSerializer( | ||
CreateSegmentOverrideFeatureStateSerializer | ||
): | ||
class Meta(CreateSegmentOverrideFeatureStateSerializer.Meta): | ||
read_only_fields = ( | ||
CreateSegmentOverrideFeatureStateSerializer.Meta.read_only_fields | ||
+ ("feature",) | ||
) | ||
|
||
|
||
class EnvironmentFeatureVersionSerializer(ModelSerializer): | ||
class Meta: | ||
model = EnvironmentFeatureVersion | ||
fields = ("created_at", "updated_at", "published", "live_from", "sha") | ||
read_only_fields = ("published", "updated_at", "created_at", "sha") | ||
read_only_fields = ("updated_at", "created_at", "sha") | ||
|
||
def validate_published(self, published: bool) -> None: | ||
if instance := getattr(self, "instance", None): | ||
if instance.is_live and published is False: | ||
raise ValidationError("Cannot un-publish already live version") | ||
|
||
def validate_live_from(self, live_from: datetime) -> None: | ||
if instance := getattr(self, "instance", None): | ||
if instance.is_live and live_from != instance.live_from: | ||
raise ValidationError( | ||
"Cannot change 'live from' date of already live version." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters