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

fix: Create project soil settings on project creation #1062

Merged
merged 1 commit into from
Dec 19, 2023
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
1 change: 1 addition & 0 deletions terraso_backend/apps/graphql/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,7 @@ input ProjectAddMutationInput {
description: String
measurementUnits: MeasurementUnits!
siteInstructions: String
createSoilSettings: Boolean
clientMutationId: String
}

Expand Down
6 changes: 5 additions & 1 deletion terraso_backend/apps/project_management/graphql/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,20 @@ 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():
kwargs["privacy"] = kwargs["privacy"].value
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:
Expand Down
1 change: 1 addition & 0 deletions terraso_backend/tests/graphql/mutations/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down