Skip to content

Commit

Permalink
require a verified email address for any account action (#15692)
Browse files Browse the repository at this point in the history
* require a verified email address for any account action

* Separate unverified views into a different route entirely

* Use mixin for both

* push this a bit more forward 🥚🐣

* Add emails to unverified template

* We don't need separate routes for reverification

* fix tests and translations

* Remove unavailable options

* Update language

* Update translations

* Revert template changes

* Testing

* Branch the redirect

* Update translations ya dummy

* Permit accounts without verified email to verify email

* Don't need startswith

* Fix typo

* Fix typo

* Remove unnecessary routes

* Revert "Remove unnecessary routes"

This reverts commit 0a4a0fc.

* Fix typogit diff!

---------

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
  • Loading branch information
ewdurbin and di committed Apr 1, 2024
1 parent 3f8c520 commit 3f9e0e2
Show file tree
Hide file tree
Showing 9 changed files with 854 additions and 156 deletions.
2 changes: 1 addition & 1 deletion tests/functional/manage/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_save_account(self, pyramid_services, user_service, db_request):
db_request.path = "/manage/accounts/"
db_request.POST = MultiDict({"name": "new name", "public_email": ""})

views.ManageAccountViews(db_request).save_account()
views.ManageVerifiedAccountViews(db_request).save_account()
user = user_service.get_user(user.id)

assert user.name == "new name"
Expand Down
160 changes: 102 additions & 58 deletions tests/unit/manage/test_views.py

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tests/unit/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ def add_policy(name, filename):
"/account/verify-project-role/",
domain=warehouse,
),
pretend.call(
"manage.unverified-account", "/manage/unverified-account/", domain=warehouse
),
pretend.call("manage.account", "/manage/account/", domain=warehouse),
pretend.call(
"manage.account.publishing", "/manage/account/publishing/", domain=warehouse
Expand Down
6 changes: 4 additions & 2 deletions warehouse/accounts/security_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def _permits_for_user_policy(acl, request, context, permission):
if (
isinstance(res, Allowed)
and not request.identity.has_primary_verified_email
and request.matched_route.name.startswith("manage")
and request.matched_route.name != "manage.account"
and request.matched_route.name
not in {"manage.unverified-account", "accounts.verify-email"}
):
return WarehouseDenied("unverified", reason="unverified_email")

Expand Down Expand Up @@ -214,6 +214,8 @@ def _check_for_mfa(request, context) -> WarehouseDenied | None:
"manage.account.totp-provision",
"manage.account.two-factor",
"manage.account.webauthn-provision",
"manage.unverified-account",
"accounts.verify-email",
]

if (
Expand Down

0 comments on commit 3f9e0e2

Please sign in to comment.