forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,003 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
""" | ||
Taxonomies API URLs. | ||
""" | ||
|
||
from django.urls import path, include | ||
|
||
from .v1 import urls as v1_urls | ||
|
||
urlpatterns = [path("v1/", include(v1_urls))] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
API Filters for content tagging org | ||
""" | ||
|
||
from rest_framework.filters import BaseFilterBackend | ||
|
||
from ...rules import is_taxonomy_admin | ||
|
||
|
||
class UserOrgFilterBackend(BaseFilterBackend): | ||
""" | ||
Taxonomy admin can see all taxonomies | ||
Everyone else can see only enabled taxonomies | ||
""" | ||
|
||
def filter_queryset(self, request, queryset, _): | ||
if is_taxonomy_admin(request.user): | ||
return queryset | ||
|
||
return queryset.filter(enabled=True) |
35 changes: 35 additions & 0 deletions
35
openedx/features/content_tagging/rest_api/v1/serializers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
API Serializers for content tagging org | ||
""" | ||
|
||
from rest_framework import serializers | ||
|
||
from openedx_tagging.core.tagging.rest_api.v1.serializers import ( | ||
TaxonomyListQueryParamsSerializer, | ||
) | ||
|
||
from organizations.models import Organization | ||
|
||
|
||
class OrganizationField(serializers.Field): | ||
""" | ||
Custom field for organization | ||
""" | ||
def to_representation(self, value): | ||
return value.short_name | ||
|
||
def to_internal_value(self, data): | ||
try: | ||
return Organization.objects.get(short_name=data) | ||
except Organization.DoesNotExist as exc: | ||
raise serializers.ValidationError( | ||
"Invalid organization short name" | ||
) from exc | ||
|
||
|
||
class TaxonomyOrgListQueryParamsSerializer(TaxonomyListQueryParamsSerializer): | ||
""" | ||
Serializer for the query params for the GET view | ||
""" | ||
|
||
org = OrganizationField(required=False) |
Empty file.
Oops, something went wrong.