diff --git a/terraso_backend/apps/graphql/schema/schema.graphql b/terraso_backend/apps/graphql/schema/schema.graphql index 4a58b787b..4516310d0 100644 --- a/terraso_backend/apps/graphql/schema/schema.graphql +++ b/terraso_backend/apps/graphql/schema/schema.graphql @@ -2109,6 +2109,7 @@ input ProjectAddMutationInput { description: String measurementUnits: MeasurementUnits! siteInstructions: String + createSoilSettings: Boolean clientMutationId: String } diff --git a/terraso_backend/apps/project_management/graphql/projects.py b/terraso_backend/apps/project_management/graphql/projects.py index 57f10db9c..fff7d667d 100644 --- a/terraso_backend/apps/project_management/graphql/projects.py +++ b/terraso_backend/apps/project_management/graphql/projects.py @@ -185,9 +185,10 @@ class Input: description = graphene.String() measurement_units = graphene.Field(MeasurementUnits, required=True) site_instructions = graphene.String() + create_soil_settings = graphene.Boolean() @classmethod - def mutate_and_get_payload(cls, root, info, **kwargs): + def mutate_and_get_payload(cls, root, info, create_soil_settings=True, **kwargs): logger = cls.get_logger() user = info.context.user with transaction.atomic(): @@ -195,6 +196,9 @@ def mutate_and_get_payload(cls, root, info, **kwargs): result = super().mutate_and_get_payload(root, info, **kwargs) result.project.add_manager(user) + if create_soil_settings: + ProjectSoilSettings.objects.create(project=result.project) + client_time = kwargs.get("client_time", None) result.project.mark_seen_by(user) if not client_time: diff --git a/terraso_backend/tests/graphql/mutations/test_projects.py b/terraso_backend/tests/graphql/mutations/test_projects.py index 3d5b88d8f..2cabf443b 100644 --- a/terraso_backend/tests/graphql/mutations/test_projects.py +++ b/terraso_backend/tests/graphql/mutations/test_projects.py @@ -62,6 +62,7 @@ def test_create_project(client, user): project = Project.objects.get(pk=id) assert list([mb.user for mb in project.manager_memberships.all()]) == [user] assert project.description == "A test project" + assert project.soil_settings is not None logs = Log.objects.all() assert len(logs) == 1