Skip to content

Commit

Permalink
datastore: Add unverify_user method
Browse files Browse the repository at this point in the history
* Provides a programmatic way to revert user verification.
* Avoids the need for direct database modifications.
* Enables correction of verification errors from admin panel.
* partially closes <inveniosoftware/invenio-administration#202>
  • Loading branch information
Samk13 committed May 2, 2024
1 parent 345abfc commit 6ffe216
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions invenio_accounts/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def verify_user(self, user):
user.confirmed_at = now
return True

def unverify_user(self, user):
"""Unverify a user."""
user.verified_at = None
return True

def block_user(self, user):
"""Verify a user."""
now = datetime.utcnow()
Expand Down
18 changes: 18 additions & 0 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,21 @@ def test_session_ip_no_country(app, users):
[session] = SessionActivity.query.all()
assert session.country is None
assert session.ip == "139.191.247.1"


def test_unverify_user(app):
"""Test unverifying a user."""
with app.app_context():
user = testutils.create_test_user(
"[email protected]",
verified_at=datetime.datetime.now(datetime.timezone.utc),
)

# Ensure the user starts off as verified
assert user.verified_at is not None

_datastore.unverify_user(user)
db.session.commit() # Assuming that commit is needed to persist changes to the database

# Ensure the user is no longer verified
assert user.verified_at is None

0 comments on commit 6ffe216

Please sign in to comment.