Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors: Add CommunityNotSelectedError for conditional check on config #595

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions invenio_records_resources/resources/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

Check failure on line 1 in invenio_records_resources/resources/errors.py

View workflow job for this annotation

GitHub Actions / Tests / Tests (3.9, postgresql14, opensearch2)

isort-check from ..errors import validation_error_to_list_errors from ..services.errors import ( + CannotRemoveCommunityError, + CommunityNotSelectedError, FacetNotFoundError, FailedFileUploadException, FileKeyNotFoundError, QuerystringValidationError, RecordPermissionDeniedError, RevisionIdMismatchError, - CommunityNotSelectedError, - CannotRemoveCommunityError, )

Check failure on line 1 in invenio_records_resources/resources/errors.py

View workflow job for this annotation

GitHub Actions / Tests / Tests (3.12, postgresql14, opensearch2)

isort-check from ..errors import validation_error_to_list_errors from ..services.errors import ( + CannotRemoveCommunityError, + CommunityNotSelectedError, FacetNotFoundError, FailedFileUploadException, FileKeyNotFoundError, QuerystringValidationError, RecordPermissionDeniedError, RevisionIdMismatchError, - CommunityNotSelectedError, - CannotRemoveCommunityError, )
#
# Copyright (C) 2020 CERN.
# Copyright (C) 2020 Northwestern University
Expand Down Expand Up @@ -40,6 +40,8 @@
QuerystringValidationError,
RecordPermissionDeniedError,
RevisionIdMismatchError,
CommunityNotSelectedError,
CannotRemoveCommunityError,
)


Expand Down Expand Up @@ -207,4 +209,16 @@
description="Uploading selected files will result in exceeding the max amount per record.",
)
),
CommunityNotSelectedError: create_error_handler(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this module is not aware of communities (invenio-communities depends on invenio-records-resources, not the other way around) so this handler should be declared either in communities or in rdm-records (a module that is aware both of the record and communities is the correct place)

HTTPJSONException(
code=400,
description="Cannot publish without selecting a community.",
)
),
CannotRemoveCommunityError: create_error_handler(
HTTPJSONException(
code=400,
description="Cannot remove. A record should be part of atleast 1 community.",
)
),
}
19 changes: 19 additions & 0 deletions invenio_records_resources/services/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

Check failure on line 1 in invenio_records_resources/services/errors.py

View workflow job for this annotation

GitHub Actions / Tests / Tests (3.9, postgresql14, opensearch2)

Black format check --- /home/runner/work/invenio-records-resources/invenio-records-resources/invenio_records_resources/services/errors.py 2024-09-16 15:17:54.098143+00:00 +++ /home/runner/work/invenio-records-resources/invenio-records-resources/invenio_records_resources/services/errors.py 2024-09-16 15:20:34.389149+00:00 @@ -115,17 +115,14 @@ class CommunityNotSelectedError(Exception): """Error thrown when a record is being created/updated with less than 1 community.""" def __init__(self): """Constructor.""" - super().__init__( - _("Cannot publish without selecting a community.") - ) + super().__init__(_("Cannot publish without selecting a community.")) + class CannotRemoveCommunityError(Exception): """Error thrown when the last community is being removed from the record.""" def __init__(self): """Constructor.""" - super().__init__( - _("A record should be part of atleast 1 community.") - ) + super().__init__(_("A record should be part of atleast 1 community."))

Check failure on line 1 in invenio_records_resources/services/errors.py

View workflow job for this annotation

GitHub Actions / Tests / Tests (3.12, postgresql14, opensearch2)

Black format check --- /home/runner/work/invenio-records-resources/invenio-records-resources/invenio_records_resources/services/errors.py 2024-09-16 15:17:56.019520+00:00 +++ /home/runner/work/invenio-records-resources/invenio-records-resources/invenio_records_resources/services/errors.py 2024-09-16 15:21:04.545785+00:00 @@ -115,17 +115,14 @@ class CommunityNotSelectedError(Exception): """Error thrown when a record is being created/updated with less than 1 community.""" def __init__(self): """Constructor.""" - super().__init__( - _("Cannot publish without selecting a community.") - ) + super().__init__(_("Cannot publish without selecting a community.")) + class CannotRemoveCommunityError(Exception): """Error thrown when the last community is being removed from the record.""" def __init__(self): """Constructor.""" - super().__init__( - _("A record should be part of atleast 1 community.") - ) + super().__init__(_("A record should be part of atleast 1 community."))
#
# Copyright (C) 2020 CERN.
# Copyright (C) 2020 Northwestern University.
Expand Down Expand Up @@ -110,3 +110,22 @@
)
)
)


class CommunityNotSelectedError(Exception):
"""Error thrown when a record is being created/updated with less than 1 community."""

def __init__(self):
"""Constructor."""
super().__init__(
_("Cannot publish without selecting a community.")
)

class CannotRemoveCommunityError(Exception):
"""Error thrown when the last community is being removed from the record."""

def __init__(self):
"""Constructor."""
super().__init__(
_("A record should be part of atleast 1 community.")
)
Loading