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

Create graphql node for creating new organization #1445

Merged
merged 3 commits into from
May 15, 2024
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
31 changes: 31 additions & 0 deletions apps/organization/mutation.py
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 6 additions & 0 deletions apps/organization/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
48 changes: 48 additions & 0 deletions apps/organization/tests/test_mutations.py
Original file line number Diff line number Diff line change
@@ -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,
thenav56 marked this conversation as resolved.
Show resolved Hide resolved
**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')
thenav56 marked this conversation as resolved.
Show resolved Hide resolved
self.assertEqual(content['data']['organizationCreate']['result']['verified'], False)
3 changes: 2 additions & 1 deletion deep/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,6 +72,7 @@ class Mutation(
export_mutation.Mutation,
gallery_mutation.Mutation,
assessment_registry_mutation.Mutation,
organization_mutation.Mutation,
# --
graphene.ObjectType
):
Expand Down
16 changes: 16 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4972,6 +4972,7 @@ type MissingPredictionReviewType {
}

type Mutation {
organizationCreate(data: OrganizationInputType!): OrganizationCreate
createAssessmentRegSummaryIssue(data: AssessmentRegistrySummaryIssueCreateInputType!): AssessmentRegistryCreateIssue
fileUpload(data: FileUploadInputType!): UploadFile
genericExportCreate(data: GenericExportCreateInputType!): CreateUserGenericExport
Expand Down Expand Up @@ -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
Expand Down
Loading