diff --git a/invenio_accounts/datastore.py b/invenio_accounts/datastore.py index 95e0b6e1..387bcc1d 100644 --- a/invenio_accounts/datastore.py +++ b/invenio_accounts/datastore.py @@ -2,6 +2,7 @@ # # This file is part of Invenio. # Copyright (C) 2015-2024 CERN. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -33,6 +34,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() diff --git a/tests/test_sessions.py b/tests/test_sessions.py index cce4449a..bcbca251 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -2,6 +2,7 @@ # # This file is part of Invenio. # Copyright (C) 2015-2018 CERN. +# Copyright (C) 2022 KTH Royal Institute of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -288,3 +289,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( + "verified@test.org", + 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() + + # Ensure the user is no longer verified + assert user.verified_at is None