From 8a2d0bb6d1fe3166a54fa86294273493c977d2e2 Mon Sep 17 00:00:00 2001 From: borisLeBonPro Date: Mon, 2 Sep 2024 18:04:11 +0200 Subject: [PATCH] (PC-31604)[BO] fix: when user is already anonymized button to anonymize should not appear --- .../pcapi/routes/backoffice/accounts/blueprint.py | 8 +++++--- api/tests/routes/backoffice/accounts_test.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/api/src/pcapi/routes/backoffice/accounts/blueprint.py b/api/src/pcapi/routes/backoffice/accounts/blueprint.py index ecec40ae97a..3cbbb287313 100644 --- a/api/src/pcapi/routes/backoffice/accounts/blueprint.py +++ b/api/src/pcapi/routes/backoffice/accounts/blueprint.py @@ -406,9 +406,11 @@ def render_public_account_details( if not user.isEmailValidated: kwargs["resend_email_validation_form"] = empty_forms.EmptyForm() - if utils.has_current_user_permission( - perm_models.Permissions.ANONYMIZE_PUBLIC_ACCOUNT - ) and not _has_user_pending_anonymization(user_id): + if ( + utils.has_current_user_permission(perm_models.Permissions.ANONYMIZE_PUBLIC_ACCOUNT) + and not _has_user_pending_anonymization(user_id) + and users_models.UserRole.ANONYMIZED not in user.roles + ): kwargs["anonymize_form"] = empty_forms.EmptyForm() kwargs["anonymize_public_accounts_dst"] = url_for(".anonymize_public_account", user_id=user.id) diff --git a/api/tests/routes/backoffice/accounts_test.py b/api/tests/routes/backoffice/accounts_test.py index 49f8ca3464f..c5a019ac5e6 100644 --- a/api/tests/routes/backoffice/accounts_test.py +++ b/api/tests/routes/backoffice/accounts_test.py @@ -982,6 +982,21 @@ def test_get_public_account_history(self, legit_user, authenticated_client): assert history_rows[5]["Commentaire"].startswith("Fraude suspicion") assert history_rows[5]["Auteur"] == legit_user.full_name + def test_get_public_account_anonymized_user(self, authenticated_client): + user = users_factories.UserFactory(roles=[users_models.UserRole.ANONYMIZED]) + + user_id = user.id + # expected_num_queries depends on the number of feature flags checked (2 + user + FF) + with assert_num_queries(self.expected_num_queries): + response = authenticated_client.get(url_for(self.endpoint, user_id=user_id)) + assert response.status_code == 200 + + content = html_parser.content_as_text(response.data) + assert f"User ID : {user.id} " in content + + available_button = html_parser.extract(response.data, tag="button") + assert "Anonymiser" not in available_button + class UpdatePublicAccountTest(PostEndpointHelper): endpoint = "backoffice_web.public_accounts.update_public_account"