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

config: add LogoNotFoundError #1251

Merged
merged 1 commit into from
Nov 22, 2024
Merged
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
3 changes: 2 additions & 1 deletion invenio_communities/communities/resources/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from invenio_communities.errors import (
CommunityDeletedError,
CommunityFeaturedEntryDoesNotExistError,
LogoNotFoundError,
LogoSizeLimitError,
OpenRequestsForCommunityDeletionError,
SetDefaultCommunityError,
Expand All @@ -39,7 +40,7 @@
community_error_handlers = RecordResourceConfig.error_handlers.copy()
community_error_handlers.update(
{
FileNotFoundError: create_error_handler(
LogoNotFoundError: create_error_handler(
HTTPJSONException(
code=404,
description="No logo exists for this community.",
Expand Down
5 changes: 3 additions & 2 deletions invenio_communities/communities/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
)
from invenio_communities.errors import (
CommunityFeaturedEntryDoesNotExistError,
LogoNotFoundError,
LogoSizeLimitError,
OpenRequestsForCommunityDeletionError,
)
Expand Down Expand Up @@ -235,7 +236,7 @@ def read_logo(self, identity, id_):
self.require_permission(identity, "read", record=record)
logo_file = record.files.get("logo")
if logo_file is None:
raise FileNotFoundError()
raise LogoNotFoundError()
return self.files.file_result_item(
self.files,
identity,
Expand Down Expand Up @@ -277,7 +278,7 @@ def delete_logo(self, identity, id_, uow=None):
self.require_permission(identity, "update", record=record)
deleted_file = record.files.pop("logo", None)
if deleted_file is None:
raise FileNotFoundError()
raise LogoNotFoundError()

deleted_file.delete(force=True)

Expand Down
8 changes: 8 additions & 0 deletions invenio_communities/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def __init__(self, query_arguments):
)


class LogoNotFoundError(CommunityError):
"""The logo was not found."""

def __init__(self):
"""Initialise error."""
super().__init__(_("No logo exists for this community."))


class LogoSizeLimitError(CommunityError):
"""The provided logo size exceeds limit."""

Expand Down
4 changes: 2 additions & 2 deletions invenio_communities/views/communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from invenio_communities.proxies import current_communities

from ..communities.resources.ui_schema import TypesSchema
from ..members.records.api import Member
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This removed line isn't on master so I'm confused

https://github.com/carlinmack/invenio-communities/blob/master/invenio_communities/views/communities.py

I removed it as Member isn't used

from ..errors import LogoNotFoundError
from .decorators import pass_community
from .template_loader import CommunityThemeChoiceJinjaLoader

Expand Down Expand Up @@ -360,7 +360,7 @@ def communities_settings(pid_value, community, community_ui):
try:
current_communities.service.read_logo(g.identity, pid_value)
logo = True
except FileNotFoundError:
except LogoNotFoundError:
logo = False

logo_size_limit = 10**6
Expand Down
4 changes: 2 additions & 2 deletions invenio_communities/views/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
from invenio_communities.proxies import current_communities

from ..errors import CommunityDeletedError
from ..errors import CommunityDeletedError, LogoNotFoundError
from ..searchapp import search_app_context
from .communities import (
communities_about,
Expand Down Expand Up @@ -256,7 +256,7 @@ def resolve_community_logo(logo_link, community_id):
identity=g.identity,
id_=community_id,
)
except FileNotFoundError:
except LogoNotFoundError:
return url_for("static", filename="images/square-placeholder.png")

return logo_link
Expand Down
Loading