diff --git a/apps/organization/mutation.py b/apps/organization/mutation.py new file mode 100644 index 0000000000..e263d0bb98 --- /dev/null +++ b/apps/organization/mutation.py @@ -0,0 +1,31 @@ +import graphene +from organization.schema import OrganizationType +from organization.serializers import OrganizationGqSerializer + +from utils.graphene.mutation import ( + generate_input_type_for_serializer, + GrapheneMutation +) + +from .models import Organization + +OrganizationInputType = generate_input_type_for_serializer( + 'OrganizationInputType', + serializer_class=OrganizationGqSerializer, +) + + +class OrganizationCreate(GrapheneMutation): + class Arguments: + data = OrganizationInputType(required=True) + model = Organization + result = graphene.Field(OrganizationType) + serializer_class = OrganizationGqSerializer + + @classmethod + def check_permissions(cls, info, **kwargs): + return True # global permission is always True + + +class Mutation(): + organization_create = OrganizationCreate.Field() diff --git a/apps/organization/serializers.py b/apps/organization/serializers.py index 82c8c4c114..3f4df84f6e 100644 --- a/apps/organization/serializers.py +++ b/apps/organization/serializers.py @@ -69,3 +69,9 @@ class Meta: model = Organization fields = ('key', 'title', 'long_name', 'short_name', 'logo', 'organization_type', 'merged_as') + + +class OrganizationGqSerializer(UserResourceSerializer): + class Meta: + model = Organization + fields = ('title', 'long_name', 'url', 'short_name', 'logo', 'organization_type') diff --git a/apps/organization/tests/test_mutations.py b/apps/organization/tests/test_mutations.py new file mode 100644 index 0000000000..ee5e74a951 --- /dev/null +++ b/apps/organization/tests/test_mutations.py @@ -0,0 +1,48 @@ +from user.factories import UserFactory +from utils.graphene.tests import GraphQLTestCase + + +class TestOrganizationMutation(GraphQLTestCase): + def test_orgainization_query(self): + self.organization_query = ''' + mutation MyMutation ($input : OrganizationInputType!) + { + organizationCreate(data: $input){ + errors + ok + result{ + id + longName + shortName + title + url + verified + } + } + } + ''' + + user = UserFactory.create() + minput = dict( + title="Test Organization", + shortName="Short Name", + longName="This is long name" + ) + + def _query_check(minput, **kwargs): + return self.query_check( + self.organization_query, + minput=minput, + **kwargs + ) + # without login + _query_check(minput, assert_for_error=True) + + # with login + + self.force_login(user) + + content = _query_check(minput) + self.assertEqual(content['data']['organizationCreate']['errors'], None) + self.assertEqual(content['data']['organizationCreate']['result']['title'], 'Test Organization') + self.assertEqual(content['data']['organizationCreate']['result']['verified'], False) diff --git a/deep/schema.py b/deep/schema.py index 83d266c630..dd3fcdb751 100644 --- a/deep/schema.py +++ b/deep/schema.py @@ -17,7 +17,7 @@ from analysis import public_schema as analysis_public_schema from user import mutation as user_mutation, schema as user_schema from user_group import mutation as user_group_mutation, schema as user_group_schema -from organization import schema as organization_schema +from organization import schema as organization_schema, mutation as organization_mutation from geo import schema as geo_schema from notification import schema as notification_schema, mutation as notification_mutation from assisted_tagging import schema as assisted_tagging_schema @@ -72,6 +72,7 @@ class Mutation( export_mutation.Mutation, gallery_mutation.Mutation, assessment_registry_mutation.Mutation, + organization_mutation.Mutation, # -- graphene.ObjectType ): diff --git a/schema.graphql b/schema.graphql index 8551b206b4..318c7fd9a3 100644 --- a/schema.graphql +++ b/schema.graphql @@ -4972,6 +4972,7 @@ type MissingPredictionReviewType { } type Mutation { + organizationCreate(data: OrganizationInputType!): OrganizationCreate createAssessmentRegSummaryIssue(data: AssessmentRegistrySummaryIssueCreateInputType!): AssessmentRegistryCreateIssue fileUpload(data: FileUploadInputType!): UploadFile genericExportCreate(data: GenericExportCreateInputType!): CreateUserGenericExport @@ -5048,6 +5049,21 @@ enum NotificationTypeEnum { ENTRY_REVIEW_COMMENT_MODIFY } +type OrganizationCreate { + errors: [GenericScalar!] + ok: Boolean + result: OrganizationType +} + +input OrganizationInputType { + title: String! + longName: String + url: String + shortName: String + logo: ID + organizationType: ID +} + type OrganizationListType { results: [OrganizationType!] totalCount: Int