Skip to content

Implement graphql mutation node for creating new organization #1444

@sudan45

Description

@sudan45

Problem Statement

Creating new organization features uses a Rest API.

Acceptance Criteria

Creating new organization works with a graphql mutation.

Additional Information

serializer

class OrganizationSerializer(
DynamicFieldsMixin, RemoveNullFieldsMixin, UserResourceSerializer,
):
organization_type_display = OrganizationTypeSerializer(
source='organization_type', read_only=True,
)
regions_display = SimpleRegionSerializer(
source='regions', read_only=True, many=True,
)
logo_url = URLCachedFileField(source='logo.file', allow_null=True, required=False)
merged_as = MergedAsOrganizationSerializer(source='parent', read_only=True)
client_id = None
class Meta:
model = Organization
exclude = ('parent',)
read_only_fields = ('verified', 'logo_url',)
def create(self, validated_data):
organization = super().create(validated_data)
organization.created_by = organization.modified_by = self.context['request'].user
return organization

views

class OrganizationViewSet(
mixins.CreateModelMixin,
mixins.RetrieveModelMixin,
mixins.ListModelMixin,
viewsets.GenericViewSet,
):
serializer_class = OrganizationSerializer
permission_classes = [permissions.IsAuthenticated]
pagination_class = AutocompleteSetPagination
authentication_classes = [CSRFExemptSessionAuthentication]
filter_backends = (django_filters.rest_framework.DjangoFilterBackend,
filters.SearchFilter, filters.OrderingFilter)
search_fields = ('title', 'short_name', 'long_name', 'url',)
filterset_fields = ('verified',)
ordering = ('title',)
def get_queryset(self):
if self.kwargs.get('pk'):
return Organization.objects.prefetch_related('parent')
return Organization.objects.filter(parent=None)

testcase

Not updated

Rest Framework URLs

method: POST
url: /api/v1/organizations
request payload: {
  "title": str
  "shortName":str,
  "url": str
  "organizationType": ID,
  "logo": ID
}
response: {
    "id":ID,
    "modifiedAt": datetime
    "modifiedBy": ID,
    "createdByName": str,
    "modifiedByName": str,
    "organizationTypeDisplay": Object / Organization type,
    "regionsDisplay": RegionList,
    "createdAt": datetime,
    "title": str,
    "shortName": str,
    "longName": str,
    "url": str,
    "verified": bool,
    "popularity": int,
    "createdBy": ID,
    "organizationType": ID,
    "regions": regionobject
}

Metadata

Metadata

Assignees

Labels

DEEP SupportDEEP's support and maintenance issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions