From 358bf3325deecd0f0457ac2f7af07c1149bf6dd4 Mon Sep 17 00:00:00 2001 From: Lars Holm Nielsen Date: Mon, 19 Feb 2024 22:21:31 +0100 Subject: [PATCH] requests: better error handling --- .../user_moderation/user_moderation.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/invenio_requests/customizations/user_moderation/user_moderation.py b/invenio_requests/customizations/user_moderation/user_moderation.py index 4d35c1a0..6d2556e9 100644 --- a/invenio_requests/customizations/user_moderation/user_moderation.py +++ b/invenio_requests/customizations/user_moderation/user_moderation.py @@ -8,6 +8,7 @@ from invenio_i18n import lazy_gettext as _ from invenio_users_resources.proxies import current_users_service +from marshmallow import ValidationError from invenio_requests.customizations import RequestType, actions @@ -18,7 +19,11 @@ class DeclineUserAction(actions.DeclineAction): def execute(self, identity, uow): """Executes block action.""" user = self.request.topic.resolve() - current_users_service.block(identity, user.id, uow=uow) + try: + current_users_service.block(identity, user.id, uow=uow) + except ValidationError: + # User already blocked so just ignore + pass super().execute(identity, uow) @@ -28,7 +33,11 @@ class AcceptUserAction(actions.AcceptAction): def execute(self, identity, uow): """Executes approve action.""" user = self.request.topic.resolve() - current_users_service.approve(identity, user.id, uow=uow) + try: + current_users_service.approve(identity, user.id, uow=uow) + except ValidationError: + # User already approved so just ignore + pass super().execute(identity, uow)