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

records: expose theme field in search #1085

Merged
merged 5 commits into from
Feb 8, 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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
python-version: [3.8, 3.9]
requirements-level: [pypi]
db-service: [postgresql14]
search-service: [opensearch2,elasticsearch7]
search-service: [opensearch2]
include:
- db-service: postgresql14
DB_EXTRAS: "postgresql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import PropTypes from "prop-types";
import _truncate from "lodash/truncate";

import { Image, InvenioPopup } from "react-invenio-forms";
import { Icon, Label } from "semantic-ui-react";
import { Icon, Label, Item } from "semantic-ui-react";
import { CommunityTypeLabel, RestrictedLabel } from "../labels";

export const CommunityCompactItemComputer = ({
Expand All @@ -25,7 +25,7 @@ export const CommunityCompactItemComputer = ({
const { metadata, ui, links, access, id } = result;
const communityType = ui?.type?.title_l10n;
return (
<div
<Item
key={id}
className={`community-item tablet computer only display-grid auto-column-grid no-wrap ${itemClassName}`}
>
Expand All @@ -37,7 +37,6 @@ export const CommunityCompactItemComputer = ({
alt=""
className="community-image rel-mr-2"
/>

<div>
<div className="flex align-items-center rel-mb-1">
<a
Expand Down Expand Up @@ -95,7 +94,7 @@ export const CommunityCompactItemComputer = ({
)}
{actions}
</div>
</div>
</Item>
);
};

Expand Down
10 changes: 10 additions & 0 deletions invenio_communities/communities/dumpers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2024 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.


"""Communities dumpers module."""
1 change: 1 addition & 0 deletions invenio_communities/communities/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Community(Record):

#: Custom fields system field.
custom_fields = DictField(clear_none=True, create_if_missing=True)
theme = DictField(clear_none=True)

theme = DictField(clear_none=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,17 @@
"description": "Community theme settings.",
"additionalProperties": false,
"properties": {
"config": {
"description": "Theme config.",
"style": {
"description": "Theme style.",
"type": "object"
},
"brand": {
"description": "Theme brand name.",
"type": "string"
},
"enabled": {
"description": "Theme brand enabled flag.",
"type": "boolean"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
"brand": {
"type": "keyword"
},
"config": {
"style": {
"type": "object",
"enabled": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
"brand": {
"type": "keyword"
},
"config": {
"style": {
"type": "object",
"enabled": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
"brand": {
"type": "keyword"
},
"config": {
"style": {
"type": "object",
"enabled": false
}
Expand Down
17 changes: 15 additions & 2 deletions invenio_communities/communities/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,25 @@ class DeletionStatusSchema(Schema):
status = fields.String(dump_only=True)


class CommunityThemeStyleSchema(Schema):
"""Community Theme configuration schema."""

font = fields.Dict()
primaryColor = fields.Str()
secondaryColor = fields.Str()
tertiaryColor = fields.Str()
primaryTextColor = fields.Str()
secondaryTextColor = fields.Str()
tertiaryTextColor = fields.Str()
mainHeaderBackgroundColor = fields.Str()


class CommunityThemeSchema(Schema):
"""Community theme schema."""

enabled = fields.Boolean()
config = fields.Dict()
style = fields.Nested(CommunityThemeStyleSchema)
brand = fields.Str()
enabled = fields.Boolean()


class CommunitySchema(BaseRecordSchema, FieldPermissionsMixin):
Expand Down
1 change: 1 addition & 0 deletions invenio_communities/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"search": "/communities/search",
"new": "/communities/new",
"details": "/communities/<pid_value>",
"upload": "/communities/<pid_value>/upload",
"settings": "/communities/<pid_value>/settings",
"requests": "/communities/<pid_value>/requests",
"settings_privileges": "/communities/<pid_value>/settings/privileges",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,15 @@ <h1 class="ui medium header mb-0">{{ community.metadata.title }}</h1>
</div>
</div>
</div>

<div
class="sixteen wide mobile sixteen wide tablet three wide computer right aligned middle aligned column">
<a href="/uploads/new?community={{ community.slug }}"
class="ui positive button labeled icon rel-mt-1 theme-secondary">
<i class="upload icon" aria-hidden="true"></i>
{{ _("New upload") }}
</a>
{%- if not community_use_jinja_header %}
Copy link
Member

Choose a reason for hiding this comment

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

I might miss some context but why do we show the "New Upload" button only when we don't have a branded community (community_use_jinja_header flag)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we dont show the new upload button when we are already in the deposit form (discussed also in person)

<a href="/uploads/new?community={{ community.slug }}"
class="ui positive button labeled icon rel-mt-1 theme-secondary">
<i class="upload icon" aria-hidden="true"></i>
{{ _("New upload") }}
</a>
{% endif %}
{% if permissions.can_moderate %}
<a
href="{{ url_for('administration.communities', q='slug:'+community.slug) }}"
Expand All @@ -128,15 +129,15 @@ <h1 class="ui medium header mb-0">{{ community.metadata.title }}</h1>
<div
class="ui container secondary pointing stackable menu page-subheader pl-0 pr-0 theme-primary">
{% if community_menu_active %}
{% for item in current_menu.submenu('communities').children if (item.permissions == True or permissions[item.permissions]) and item.visible %}
<a
class="item {{ 'active' if active_community_header_menu_item == item.name }} {{ 'disabled' if not item.url }}"
href="{{ item.url }}"
>
<i aria-hidden="true" class="{{ item.icon }} icon"></i>
{{ item.text }}
</a>
{% endfor %}
{% for item in current_menu.submenu('communities').children if (item.permissions == True or permissions[item.permissions]) and item.visible %}
<a
class="item {{ 'active' if active_community_header_menu_item == item.name }} {{ 'disabled' if not item.url }}"
href="{{ item.url }}"
>
<i aria-hidden="true" class="{{ item.icon }} icon"></i>
{{ item.text }}
</a>
{% endfor %}
{% endif %}
</div>
</div>
Expand Down
27 changes: 14 additions & 13 deletions invenio_communities/views/communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@
]


def render_community_theme_template(template_name_or_list, theme_brand=None, **context):
def render_community_theme_template(template_name_or_list, theme=None, **context):
"""Render community theme."""
if theme_brand:
if theme and theme.get("enabled", False):
brand = theme.get("brand")
if isinstance(template_name_or_list, str):
loader = CommunityThemeChoiceJinjaLoader(theme_brand)
loader = CommunityThemeChoiceJinjaLoader(brand)

community_theme_view_env = current_app.jinja_env.overlay(loader=loader)

Expand Down Expand Up @@ -237,7 +238,7 @@ def communities_settings(pid_value, community, community_ui):

return render_community_theme_template(
"invenio_communities/details/settings/profile.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community,
community_ui=community_ui,
has_logo=True if logo else False,
Expand All @@ -260,7 +261,7 @@ def communities_requests(pid_value, community, community_ui):

return render_community_theme_template(
"invenio_communities/details/requests/index.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
)
Expand All @@ -285,7 +286,7 @@ def communities_settings_privileges(pid_value, community, community_ui):

return render_community_theme_template(
"invenio_communities/details/settings/privileges.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
form_config=dict(
access=dict(visibility=VISIBILITY_FIELDS),
Expand All @@ -306,7 +307,7 @@ def communities_settings_curation_policy(pid_value, community, community_ui):

return render_community_theme_template(
"invenio_communities/details/settings/curation_policy.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
form_config=dict(
Expand All @@ -333,7 +334,7 @@ def communities_settings_pages(pid_value, community, community_ui):

return render_community_theme_template(
"invenio_communities/details/settings/pages.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
form_config=dict(
Expand Down Expand Up @@ -363,7 +364,7 @@ def members(pid_value, community, community_ui):

return render_community_theme_template(
"invenio_communities/details/members/members.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
roles_can_update=_get_roles_can_update(community.id),
Expand All @@ -388,7 +389,7 @@ def invitations(pid_value, community, community_ui):
raise PermissionDeniedError()
return render_community_theme_template(
"invenio_communities/details/members/invitations.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
roles_can_invite=_get_roles_can_invite(community.id),
permissions=permissions,
Expand All @@ -411,7 +412,7 @@ def communities_about(pid_value, community, community_ui):

return render_community_theme_template(
"invenio_communities/details/about/index.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
custom_fields_ui=load_custom_fields(dump_only_required=False)["ui"],
Expand All @@ -433,7 +434,7 @@ def communities_curation_policy(pid_value, community, community_ui):
raise PermissionDeniedError()
return render_community_theme_template(
"invenio_communities/details/curation_policy/index.html",
theme_brand=community_ui.get("theme", {}).get("brand"),
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
)
Expand All @@ -442,7 +443,7 @@ def communities_curation_policy(pid_value, community, community_ui):
@pass_community(serialize=False)
def community_theme_css_config(pid_value, revision, community):
"""Community brand theme view to serve css config."""
theme_config = community.data.get("theme", {}).get("config")
theme_config = community.data.get("theme", {}).get("style")

if theme_config is None:
template = ""
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ tests =
invenio-db[postgresql,mysql]>=1.0.14,<2.0.0
pytest-invenio>=2.1.4,<3.0.0
sphinx>=4.5.0
elasticsearch7 =
invenio-search[elasticsearch7]>=2.1.0,<3.0.0
opensearch1 =
invenio-search[opensearch1]>=2.1.0,<3.0.0
opensearch2 =
Expand Down
2 changes: 1 addition & 1 deletion tests/communities/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def test_theme_updates(

theme_data = {
"theme": {
"config": {
"style": {
"primaryColor": "#004494",
"tertiaryColor": "#e3eefd",
"secondaryColor": "#FFD617",
Expand Down
2 changes: 1 addition & 1 deletion tests/communities/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_template_loader(theme_app):
@theme_app.route("/community_theme")
def community_theme():
return render_community_theme_template(
"invenio_test/frontpage.html", theme_brand="horizon"
"invenio_test/frontpage.html", theme={"brand": "horizon", "enabled": True}
)

@theme_app.route("/")
Expand Down
Loading