Skip to content

Commit

Permalink
fix(api): validate before creating projects based on current subscrip…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
tushar5526 committed Oct 22, 2023
1 parent 619c3f5 commit bbc4f86
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ def get_use_edge_identities(self, obj: Project) -> bool:
== ProjectIdentityMigrationStatus.MIGRATION_COMPLETED.value
)

def validate(self, data):
subscription_metadata = data[
"organisation"
].subscription.get_subscription_metadata()
total_projects = len(Project.objects.filter(organisation=data["organisation"]))
if subscription_metadata.projects <= total_projects:
raise serializers.ValidationError("Max projects reached for subscription")
return data


class ProjectRetrieveSerializer(ProjectListSerializer):
total_features = serializers.SerializerMethodField()
Expand Down

0 comments on commit bbc4f86

Please sign in to comment.