0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-24 18:07:17 +01:00
posthog/ee/api/organization_resource_access.py
Li Yi Yu c076b5eea3
fix: feature flag can edit (#13196)
* fix feature flag can edit details

* add simple test

* fix test

* adjust queries increase in tests

* remove available features check bc too many queries

* fix test

* filter with org too

* return true if feature is not available under org

* fix test
2022-12-12 10:48:19 -05:00

45 lines
1.6 KiB
Python

from rest_framework import mixins, serializers, viewsets
from rest_framework.permissions import IsAuthenticated
from ee.api.role import RolePermissions
from ee.models.organization_resource_access import OrganizationResourceAccess
from posthog.api.routing import StructuredViewSetMixin
from posthog.permissions import OrganizationMemberPermissions
class OrganizationResourceAccessSerializer(serializers.ModelSerializer):
class Meta:
model = OrganizationResourceAccess
fields = ["id", "resource", "access_level", "organization", "created_at", "updated_at", "created_by"]
read_only_fields = ["id", "created_at", "created_by", "organization"]
def validate_resource(self, resource):
if OrganizationResourceAccess.objects.filter(
organization=self.context["request"].user.organization,
resource=resource,
).exists():
raise serializers.ValidationError("This resource access already exists.", code="unique")
return resource
def create(self, validated_data):
validated_data["organization"] = self.context["request"].user.organization
return super().create(validated_data)
class OrganizationResourceAccessViewSet(
StructuredViewSetMixin,
mixins.ListModelMixin,
mixins.RetrieveModelMixin,
mixins.CreateModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
viewsets.GenericViewSet,
):
permission_classes = [
IsAuthenticated,
OrganizationMemberPermissions,
RolePermissions,
]
serializer_class = OrganizationResourceAccessSerializer
queryset = OrganizationResourceAccess.objects.all()