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

(PC-31604)[BO] fix: when user is already anonymized button to anonymize should not appear #13933

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
8 changes: 5 additions & 3 deletions api/src/pcapi/routes/backoffice/accounts/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Comment on lines +409 to +413
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il manque un petit test :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A vrai dire, j'ai justement pensé qu'un test n'était pas nécéssaire pour ce cas spécifique étant donné les tests en backend mais très bien, je vais faire le test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ça me semble bien, je laisse Patrick approuver si ça lui convient

kwargs["anonymize_form"] = empty_forms.EmptyForm()
kwargs["anonymize_public_accounts_dst"] = url_for(".anonymize_public_account", user_id=user.id)

Expand Down
15 changes: 15 additions & 0 deletions api/tests/routes/backoffice/accounts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading