Skip to content

Commit

Permalink
publish the geoarea in the project
Browse files Browse the repository at this point in the history
  • Loading branch information
sudan45 committed Apr 8, 2024
1 parent e23f382 commit e4fc89e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
19 changes: 12 additions & 7 deletions apps/geo/mutations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import graphene

from geo.models import Region
from geo.schema import AdminLevelType, RegionType
from geo.serializers import RegionGqSerializer
from geo.schema import RegionType
from geo.serializers import PublishRegionGqSerializer, RegionGqSerializer

from deep.permissions import ProjectPermissions as PP
from utils.graphene.mutation import GrapheneMutation, generate_input_type_for_serializer
Expand All @@ -12,6 +12,11 @@
serializer_class=RegionGqSerializer,
)

RegionPublishInputType = generate_input_type_for_serializer(
'RegionPublishInputType',
serializer_class=PublishRegionGqSerializer,
)


class CreateRegion(GrapheneMutation):
class Arguments:
Expand All @@ -26,13 +31,13 @@ def check_permissions(cls, *args, **_):
return True


class UpdateRegion(GrapheneMutation):
class PublishRegion(GrapheneMutation):
class Arguments:
data = RegionInputType(required=True)
data = RegionPublishInputType(required=True)
id = graphene.ID(required=True)
model = Region
serializer_class = RegionGqSerializer
result = graphene.Field(AdminLevelType)
serializer_class = PublishRegionGqSerializer
result = graphene.Field(RegionType)

@classmethod
def check_permissions(cls, *args, **_):
Expand All @@ -42,4 +47,4 @@ def check_permissions(cls, *args, **_):

class Mutation():
create_region = CreateRegion.Field()
update_region = UpdateRegion.Field()
publish_region = PublishRegion.Field()
26 changes: 25 additions & 1 deletion apps/geo/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,29 @@ def create(self, validated_data):

return region

def update(self,validated_data,instance):
def update(self, validated_data, instance):
return True


class PublishRegionGqSerializer(ProjectPropertySerializerMixin, UserResourceSerializer):
project = serializers.IntegerField()

class Meta:
model = Region
fields = ['is_published', 'project']

def validate_project(self, project):
try:
project = Project.objects.get(id=project)
except Project.DoesNotExist:
raise serializers.ValidationError(
'Project matching query does not exist'
)

if not project.can_modify(self.context['request'].user):
raise serializers.ValidationError('Invalid project')
return project.id

def update(self, instance, validated_data):
data = super().update(instance, validated_data)
return data
12 changes: 12 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4280,6 +4280,7 @@ type MissingPredictionReviewType {

type Mutation {
createRegion(data: RegionInputType!): CreateRegion
publishRegion(data: RegionPublishInputType!, id: ID!): PublishRegion
createAssessmentRegSummaryIssue(data: AssessmentRegistrySummaryIssueCreateInputType!): AssessmentRegistryCreateIssue
fileUpload(data: FileUploadInputType!): UploadFile
genericExportCreate(data: GenericExportCreateInputType!): CreateUserGenericExport
Expand Down Expand Up @@ -5036,6 +5037,12 @@ type PublicProjectWithMembershipData {
isRejected: Boolean!
}

type PublishRegion {
errors: [GenericScalar!]
ok: Boolean
result: RegionType
}

type Query {
assessmentRegSummaryIssue(id: ID!): AssessmentRegistrySummaryIssueType
assessmentRegSummaryIssues(label: String, parent: ID, subPillar: AssessmentRegistrySummarySubPillarTypeEnum, subDimension: AssessmentRegistrySummarySubDimensionTypeEnum, search: String, isParent: Boolean, page: Int = 1, ordering: String, pageSize: Int): AssessmentRegistrySummaryIssueListType
Expand Down Expand Up @@ -5168,6 +5175,11 @@ input RegionProjectFilterData {
isTest: Boolean
}

input RegionPublishInputType {
isPublished: Boolean
project: Int!
}

type RegionType {
id: ID!
title: String!
Expand Down

0 comments on commit e4fc89e

Please sign in to comment.