Skip to content

Commit

Permalink
feat: Update taxonomy view permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Mar 28, 2024
1 parent 1a3fbb6 commit cb628f7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
TaxonomyListQueryParamsSerializer,
TaxonomySerializer,
)
from openedx_tagging.core.tagging.rules import ObjectTagPermissionItem

from organizations.models import Organization

Expand All @@ -25,6 +26,9 @@ class TaxonomyOrgListQueryParamsSerializer(TaxonomyListQueryParamsSerializer):
required=False,
)
unassigned: fields.Field = serializers.BooleanField(required=False)
content_id: fields.Field = serializers.CharField(
required=False,
)

def validate(self, attrs: dict) -> dict:
"""
Expand Down Expand Up @@ -90,6 +94,18 @@ def get_all_orgs(self, obj) -> bool:
return True
return False

def get_can_tag_object(self, instance) -> bool | None:
"""
Returns True if the current request user may create object tags on this taxonomy and content.
"""
request = self.context.get('request')
# We no need to validate. The validation is done on the view.
content_id = request.query_params.get('content_id', None)

perm_name = 'oel_tagging.can_tag_object'
perm_object = ObjectTagPermissionItem(taxonomy=instance, object_id=content_id)
return self._can(perm_name, perm_object)

class Meta:
model = TaxonomySerializer.Meta.model
fields = TaxonomySerializer.Meta.fields + ["orgs", "all_orgs"]
Expand Down

0 comments on commit cb628f7

Please sign in to comment.