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

Add API endpoint for organization type #65

Merged
merged 4 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from core.email_utils import send_email, send_email_body

from core.models import CoreUser, CoreGroup, EmailTemplate, LogicModule, Organization, PERMISSIONS_ORG_ADMIN, \
TEMPLATE_RESET_PASSWORD, Consortium
TEMPLATE_RESET_PASSWORD, Consortium, OrganizationType


class LogicModuleSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -358,3 +358,11 @@ class ConsortiumSerializer(serializers.ModelSerializer):
class Meta:
model = Consortium
fields = '__all__'


class OrganizationTypeSerializer(serializers.ModelSerializer):
id = serializers.ReadOnlyField()

class Meta:
model = OrganizationType
fields = '__all__'
4 changes: 2 additions & 2 deletions core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from core.views.consortium import ConsortiumViewSet
from rest_framework import routers

from core.views.organization import OrganizationTypeViewSet
from core import views
from core.views.web import IndexView, oauth_complete

Expand All @@ -22,7 +22,7 @@
router.register(r'organization', views.OrganizationViewSet)
router.register(r'logicmodule', views.LogicModuleViewSet)
router.register(r'consortium', ConsortiumViewSet)

router.register(r'organization_type', OrganizationTypeViewSet)

urlpatterns = [
path('', IndexView.as_view(), name='index'),
Expand Down
48 changes: 43 additions & 5 deletions core/views/organization.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import logging

from django_filters.rest_framework import DjangoFilterBackend
from core.permissions import IsSuperUser
import django_filters
from rest_framework import viewsets
from rest_framework.response import Response
from rest_framework.decorators import action
from core.models import Organization
from core.serializers import OrganizationSerializer
from core.models import Organization, OrganizationType
from core.serializers import OrganizationSerializer, OrganizationTypeSerializer
from core.permissions import IsOrgMember
from django.views.decorators.csrf import csrf_exempt

from rest_framework.permissions import AllowAny

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -50,7 +51,8 @@ def list(self, request, *args, **kwargs):
serializer_class = OrganizationSerializer

@csrf_exempt
@action(detail=False, methods=['get'], name='Fetch Already existing Organization', url_path='fetch_orgs')
@action(detail=False, methods=['get'], permission_classes=[AllowAny],
name='Fetch Already existing Organization', url_path='fetch_orgs')
def fetch_existing_orgs(self, request, pk=None, *args, **kwargs):
"""
Fetch Already existing Organizations in Buildly Core,
Expand All @@ -63,3 +65,39 @@ def fetch_existing_orgs(self, request, pk=None, *args, **kwargs):
names.append(record.name)

return Response(names)


class OrganizationTypeViewSet(viewsets.ModelViewSet):
"""
Organization type is associated with an organization which defines type of organization.

title:
Organization Type

description:
An organization type are custodian and producer

They are associated with an organization.
Only admin has access to organization type.

retrieve:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace Consortium with Organization type

Return the Organization Type.

list:
Return a list of all the existing Organization Types.

create:
Create a new Organization Type instance.

update:
Update a Organization Type instance.

delete:
Delete a Organization Type instance.
"""

filter_fields = ('name',)
filter_backends = (DjangoFilterBackend,)
permission_classes = (IsSuperUser,)
queryset = OrganizationType.objects.all()
serializer_class = OrganizationTypeSerializer