Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update taxonomy view permissions #649

Draft
wants to merge 1 commit into
base: chris/FAL-3624-import-export-courses
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py
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