Skip to content

Commit

Permalink
global: serialize Community.theme
Browse files Browse the repository at this point in the history
  • Loading branch information
slint committed Feb 6, 2024
1 parent 77e347a commit a198a22
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 31 deletions.
26 changes: 0 additions & 26 deletions invenio_communities/communities/dumpers/community_theme.py

This file was deleted.

4 changes: 2 additions & 2 deletions invenio_communities/communities/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
IsVerifiedField,
)

from ..dumpers.community_theme import CommunityThemeDumperExt
from ..dumpers.featured import FeaturedDumperExt
from . import models
from .systemfields.access import CommunityAccessField
Expand Down Expand Up @@ -59,7 +58,6 @@ class Community(Record):

dumper = SearchDumper(
extensions=[
CommunityThemeDumperExt("theme"),
FeaturedDumperExt("featured"),
RelationDumperExt("relations"),
CalculatedFieldDumperExt("is_verified"),
Expand All @@ -73,6 +71,8 @@ class Community(Record):
#: Custom fields system field.
custom_fields = DictField(clear_none=True, create_if_missing=True)

theme = DictField()

bucket_id = ModelField(dump=False)
bucket = ModelField(dump=False)
files = FilesField(
Expand Down
4 changes: 1 addition & 3 deletions invenio_communities/communities/resources/ui_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,13 @@ def get_permissions(self, obj):

@post_dump
def post_dump(self, data, many, **kwargs):
"""Pop theme field if None."""
"""Pop tombstone field if not deleted/visible."""
is_deleted = (data.get("deletion_status") or {}).get("is_deleted", False)
tombstone_visible = (data.get("tombstone") or {}).get("is_visible", True)

if not is_deleted or not tombstone_visible:
data.pop("tombstone", None)

if data.get("theme") is None:
data.pop("theme", None)
return data


Expand Down
6 changes: 6 additions & 0 deletions invenio_communities/communities/services/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ def unmark(self, identity, data=None, record=None, **kwargs):
class CommunityThemeComponent(ServiceComponent):
"""Service component for Community theme."""

def create(self, identity, data=None, record=None, **kwargs):
"""Inject parsed theme to the record."""
if "theme" in data:
self.service.require_permission(identity, "set_theme", record=record)
record["theme"] = data["theme"]

def update(self, identity, data=None, record=None, errors=None, **kwargs):
"""Inject parsed theme to the record."""
stored_record_theme = record.get("theme")
Expand Down

0 comments on commit a198a22

Please sign in to comment.