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: Allow updates with null privacy #963

Merged
merged 1 commit into from
Nov 9, 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
6 changes: 4 additions & 2 deletions terraso_backend/apps/project_management/graphql/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,15 @@ def mutate_and_get_payload(cls, root, info, **kwargs):
cls.remove_null_fields(kwargs, ["privacy", "measurement_units"])
if not user.has_perm(Project.get_perm("change"), project):
cls.not_allowed()
kwargs["privacy"] = kwargs["privacy"].value

metadata = {
"name": kwargs["name"],
"privacy": kwargs["privacy"],
"description": kwargs["description"] if "description" in kwargs else None,
}

if privacy := kwargs.get("privacy"):
metadata["privacy"] = privacy.value

logger.log(
user=user,
action=log_api.CHANGE,
Expand Down
24 changes: 19 additions & 5 deletions terraso_backend/tests/graphql/mutations/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,25 @@ def test_update_project_user_is_manager(project, client, project_manager):
assert content["data"]["updateProject"]["project"]["privacy"] == "PRIVATE"


def test_update_project_audit_log(project, client, project_manager):
@pytest.mark.parametrize(
"metadata",
[
{
"name": "test_name",
"privacy": "PRIVATE",
"description": "A test project",
},
{
"name": "test_name",
"description": "A test project",
},
],
)
def test_update_project_audit_log(metadata, project, client, project_manager):
input = {
"id": str(project.id),
"name": "test_name",
"privacy": "PRIVATE",
"description": "A test project",
}
input.update(metadata)
client.force_login(project_manager)

response = graphql_query(UPDATE_PROJECT_GRAPHQL, input_data=input, client=client)
Expand All @@ -204,7 +216,9 @@ def test_update_project_audit_log(project, client, project_manager):
assert log_result.event == CHANGE.value
assert log_result.user_human_readable == project_manager.full_name()
assert log_result.resource_object == project
expected_metadata = {"name": "test_name", "privacy": "private", "description": "A test project"}
expected_metadata = metadata
if "privacy" in expected_metadata:
expected_metadata["privacy"] = expected_metadata["privacy"].lower()
assert log_result.metadata == expected_metadata


Expand Down