Skip to content

Commit

Permalink
feat: add taxonomies for org api
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Aug 10, 2023
1 parent a11eba0 commit c81c7bd
Show file tree
Hide file tree
Showing 15 changed files with 1,003 additions and 77 deletions.
5 changes: 5 additions & 0 deletions cms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,8 @@
urlpatterns += [
path('api/contentstore/', include('cms.djangoapps.contentstore.rest_api.urls'))
]

# Content tagging
urlpatterns += [
path('api/content_tagging/', include(('openedx.features.content_tagging.urls'))),
]
5 changes: 5 additions & 0 deletions lms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,3 +1049,8 @@
urlpatterns += [
path('api/notifications/', include('openedx.core.djangoapps.notifications.urls')),
]

# Content tagging
urlpatterns += [
path('api/content_tagging/', include(('openedx.features.content_tagging.urls'))),
]
2 changes: 1 addition & 1 deletion openedx/features/content_tagging/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Meta:

@classmethod
def get_relationships(
cls, taxonomy: Taxonomy, rel_type: RelType, org_short_name: str = None
cls, taxonomy: Taxonomy, rel_type: RelType, org_short_name: Union[str, None] = None
) -> QuerySet:
"""
Returns the relationships of the given rel_type and taxonomy where:
Expand Down
Empty file.
9 changes: 9 additions & 0 deletions openedx/features/content_tagging/rest_api/urls.py
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.
21 changes: 21 additions & 0 deletions openedx/features/content_tagging/rest_api/v1/filters.py
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 openedx/features/content_tagging/rest_api/v1/serializers.py
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.
Loading

0 comments on commit c81c7bd

Please sign in to comment.