diff --git a/invenio_app_rdm/communities_ui/views/ui.py b/invenio_app_rdm/communities_ui/views/ui.py index f795f8b33..08b5458c6 100644 --- a/invenio_app_rdm/communities_ui/views/ui.py +++ b/invenio_app_rdm/communities_ui/views/ui.py @@ -15,10 +15,18 @@ UICommunityJSONSerializer, ) from invenio_communities.errors import CommunityDeletedError +from invenio_communities.views.ui import ( + not_found_error, + record_permission_denied_error, + record_tombstone_error, +) from invenio_i18n import lazy_gettext as _ from invenio_pidstore.errors import PIDDeletedError, PIDDoesNotExistError from invenio_rdm_records.collections import search_app_context as c_search_app_context -from invenio_records_resources.services.errors import PermissionDeniedError +from invenio_records_resources.services.errors import ( + PermissionDeniedError, + RecordPermissionDeniedError, +) from ..searchapp import search_app_context from .communities import ( @@ -30,46 +38,6 @@ ) -# -# Error handlers -# -def not_found_error(error): - """Handler for 'Not Found' errors.""" - return render_template(current_app.config["THEME_404_TEMPLATE"]), 404 - - -def record_tombstone_error(error): - """Tombstone page.""" - # the RecordDeletedError will have the following properties, - # while the PIDDeletedError won't - record = getattr(error, "record", None) - if (record_ui := getattr(error, "result_item", None)) is not None: - if record is None: - record = record_ui._record - record_ui = UICommunityJSONSerializer().dump_obj(record_ui.to_dict()) - - # render a 404 page if the tombstone isn't visible - if not record.tombstone.is_visible: - return not_found_error(error) - - # we only render a tombstone page if there is a record with a visible tombstone - return ( - render_template( - "invenio_communities/tombstone.html", - record=record_ui, - ), - 410, - ) - - -def record_permission_denied_error(error): - """Handle permission denier error on record views.""" - if not current_user.is_authenticated: - # trigger the flask-login unauthorized handler - return current_app.login_manager.unauthorized() - return render_template(current_app.config["THEME_403_TEMPLATE"]), 403 - - def _show_browse_page(): """Whether the browse page should be visible in the menu.""" return ( @@ -118,6 +86,9 @@ def create_ui_blueprint(app): blueprint.register_error_handler( PermissionDeniedError, record_permission_denied_error ) + blueprint.register_error_handler( + RecordPermissionDeniedError, record_permission_denied_error + ) blueprint.register_error_handler(PIDDeletedError, record_tombstone_error) blueprint.register_error_handler(CommunityDeletedError, record_tombstone_error) blueprint.register_error_handler(PIDDoesNotExistError, not_found_error)