Skip to content

Commit

Permalink
fix: Prevent multiple permissions for single user in project
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnesbitt committed Oct 10, 2024
1 parent a843439 commit 16e6140
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions uvdat/core/rest/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ class ProjectPermissionsSerializer(serializers.Serializer):
collaborator_ids = serializers.ListField(child=serializers.IntegerField())
follower_ids = serializers.ListField(child=serializers.IntegerField())

def validate(self, attrs):
collaborators = set(attrs['collaborator_ids'])
followers = set(attrs['follower_ids'])
owner = attrs['owner_id']

if collaborators & followers or owner in (collaborators | followers):
raise serializers.ValidationError(
'A user cannot have multiple permissions on a single project'
)

return super().validate(attrs)


class ProjectSerializer(serializers.ModelSerializer):
default_map_center = serializers.SerializerMethodField('get_center')
Expand Down

0 comments on commit 16e6140

Please sign in to comment.