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

membership-request [#855]: 6) integration in invenio-app-rdm #2764

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 23 additions & 4 deletions invenio_app_rdm/communities_ui/views/communities.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019-2024 CERN.
# Copyright (C) 2019-2022 Northwestern University.
# Copyright (C) 2019-2024 Northwestern University.
# Copyright (C) 2022 TU Wien.
#
# Invenio App RDM is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
"""Request views module."""

from flask import abort, g, redirect, request, url_for
from invenio_communities.proxies import current_communities
from invenio_communities.views.communities import (
HEADER_PERMISSIONS,
render_community_theme_template,
Expand All @@ -26,17 +27,22 @@ def communities_detail(pid_value, community, community_ui):
"""Community detail page."""
permissions = community.has_permissions_to(HEADER_PERMISSIONS)
endpoint = "/api/communities/{pid_value}/records"
members_service = current_communities.service.members

return render_community_theme_template(
"invenio_communities/records/index.html",
theme=community_ui.get("theme", {}),
community=community,
community_ui=community_ui,
community=community_ui,
# Pass permissions so we can disable partially UI components
# e.g Settings tab
permissions=permissions,
active_community_header_menu_item="search",
endpoint=endpoint.format(pid_value=community.to_dict()["id"]),
associated_request_id=(
members_service.get_pending_request_id_if_any(
g.identity.id, community.id
)
)
)


Expand Down Expand Up @@ -96,13 +102,21 @@ def communities_home(pid_value, community, community_ui):
"hits"
]

members_service = current_communities.service.members


return render_community_theme_template(
"invenio_communities/details/home/index.html",
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
records=records_ui,
metrics=metrics,
associated_request_id=( # in case public
members_service.get_pending_request_id_if_any(
g.identity.id, community.id
)
)
)


Expand All @@ -115,14 +129,19 @@ def community_static_page(pid_value, community, community_ui, **kwargs):

try:
page = current_pages_service.read_by_url(g.identity, request.path).to_dict()

except PageNotFoundError:
abort(404)

members_service = current_communities.service.members

return render_community_theme_template(
page["template_name"],
theme=community_ui.get("theme", {}),
page=page,
community=community_ui,
permissions=permissions,
associated_request_id=( # in case public
members_service.get_pending_request_id_if_any(
g.identity.id, community.id)
)
)
11 changes: 11 additions & 0 deletions invenio_app_rdm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
CommunityInvitationDeclineNotificationBuilder,
CommunityInvitationExpireNotificationBuilder,
CommunityInvitationSubmittedNotificationBuilder,
CommunityMembershipRequestAcceptNotificationBuilder,
CommunityMembershipRequestCancelNotificationBuilder,
CommunityMembershipRequestDeclineNotificationBuilder,
CommunityMembershipRequestExpireNotificationBuilder,
CommunityMembershipRequestSubmittedNotificationBuilder,
)
from invenio_notifications.backends import EmailNotificationBackend
from invenio_rdm_records.notifications.builders import (
Expand Down Expand Up @@ -1320,6 +1325,12 @@ def github_link_render(record):
community_notifications.SubCommunityCreate.type: community_notifications.SubCommunityCreate,
community_notifications.SubCommunityAccept.type: community_notifications.SubCommunityAccept,
community_notifications.SubCommunityDecline.type: community_notifications.SubCommunityDecline,
# Community membership request
CommunityMembershipRequestAcceptNotificationBuilder.type: CommunityMembershipRequestAcceptNotificationBuilder,
CommunityMembershipRequestCancelNotificationBuilder.type: CommunityMembershipRequestCancelNotificationBuilder,
CommunityMembershipRequestDeclineNotificationBuilder.type: CommunityMembershipRequestDeclineNotificationBuilder,
CommunityMembershipRequestExpireNotificationBuilder.type: CommunityMembershipRequestExpireNotificationBuilder,
CommunityMembershipRequestSubmittedNotificationBuilder.type: CommunityMembershipRequestSubmittedNotificationBuilder,
}
"""Notification builders."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
#}
{% set title = invenio_request.title %}
{% extends "invenio_requests/details/index.html" %}
{% from "invenio_requests/macros/request_header.html" import invitation_request_header %}
{% from "invenio_requests/macros/request_header.html" import member_request_header %}

{% set active_community_header_menu_item = 'members' %}
{% set active_members_menu_item = 'invitations' %}

{% block request_header %}
{% set back_button_url = url_for("invenio_communities.invitations", pid_value=invenio_request.created_by.community) %}
{{
invitation_request_header(
member_request_header(
back_button_url=back_button_url,
back_button_text=_("Back to invitations"),
request=invenio_request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#}
{% set title = invenio_request.title %}
{% extends "invenio_requests/details/index.html" %}
{% from "invenio_requests/macros/request_header.html" import invitation_request_header %}
{% from "invenio_requests/macros/request_header.html" import member_request_header %}


{% block request_header %}
{% set back_button_url = url_for("invenio_app_rdm_users.requests") %}
{{
invitation_request_header(
member_request_header(
back_button_url=back_button_url,
back_button_text=_("Back to requests"),
request=invenio_request,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{# -*- coding: utf-8 -*-

This file is part of Invenio.
Copyright (C) 2022 CERN.
Copyright (C) 2024 Northwestern University

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.
#}
{% set title = invenio_request.title %}
{% extends "invenio_requests/details/index.html" %}
{% from "invenio_requests/macros/request_header.html" import member_request_header %}

{% set active_community_header_menu_item = 'members' %}
{% set active_members_menu_item = 'membership_requests' %}

{% block request_header %}
{{
member_request_header(
back_button_url=url_for("invenio_communities.membership_requests", pid_value=invenio_request.receiver.community),
back_button_text=_("Back to membership requests"),
request=invenio_request
)
}}
{% endblock %}


{% block settings_body %}
<div class="sixteen wide mobile sixteen wide tablet thirteen wide computer column right floated">
{% block request_body %}
{{ super() }}
{% endblock request_body %}
</div>
{% endblock %}

{% block page_body %}
{{ super.super() }}
{% endblock page_body %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{# -*- coding: utf-8 -*-

This file is part of Invenio.
Copyright (C) 2022 CERN.
Copyright (C) 2024 Northwestern University.

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.
#}
{% set title = invenio_request.title %}
{% extends "invenio_requests/details/index.html" %}
{% from "invenio_requests/macros/request_header.html" import member_request_header %}


{% block request_header %}
{{
member_request_header(
back_button_url=url_for("invenio_app_rdm_users.requests"),
back_button_text=_("Back to requests"),
request=invenio_request,
accepted=request_is_accepted
)
}}
{% endblock %}

{% set active_dashboard_menu_item = 'requests' %}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{%- from "invenio_app_rdm/records/macros/creatibutors.html" import show_creatibutors %}

{% macro invitation_request_header(back_button_url=None, back_button_text=None, request=None, accepted=False) %}
{% macro member_request_header(back_button_url=None, back_button_text=None, request=None, accepted=False) %}
{#
Renders the member invitation request header block with:
Renders the member invitation/membership request header block with:
- a back button
- a `View community` button, when accepted
- the request's title
Expand Down
30 changes: 25 additions & 5 deletions invenio_app_rdm/requests_ui/views/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
from flask import g, render_template
from flask_login import current_user, login_required
from invenio_communities.config import COMMUNITIES_ROLES
from invenio_communities.members.services.request import CommunityInvitation
from invenio_communities.members.services.request import (
CommunityInvitation,
MembershipRequestRequestType,
)
from invenio_communities.proxies import current_identities_cache
from invenio_communities.subcommunities.services.request import SubCommunityRequest
from invenio_communities.utils import identity_cache_key
Expand Down Expand Up @@ -240,8 +243,11 @@ def community_dashboard_request_view(request, community, community_ui, **kwargs)

is_draft_submission = request_type == CommunitySubmission.type_id
is_record_inclusion = request_type == CommunityInclusion.type_id
is_member_invitation = request_type == CommunityInvitation.type_id
is_subcommunity_request = request_type == SubCommunityRequest.type_id
types_of_member_requests = [
CommunityInvitation.type_id,
MembershipRequestRequestType.type_id,
]
request_is_accepted = request["status"] == AcceptAction.status_to

permissions = community.has_permissions_to(
Expand Down Expand Up @@ -277,9 +283,23 @@ def community_dashboard_request_view(request, community, community_ui, **kwargs)
include_deleted=False,
)

elif is_member_invitation:
if not permissions["can_search_invites"]:
raise PermissionDeniedError()
elif request_type in types_of_member_requests:
permissions = community.has_permissions_to(
[
"update",
"read",
"search_requests",
"members_search_public",
"search_invites",
"search_membership_requests",
]
)
if request_type == CommunityInvitation.type_id:
if not permissions["can_search_invites"]:
raise PermissionDeniedError()
else: # is a membership request
if not permissions["can_search_membership_requests"]:
raise PermissionDeniedError()

return render_community_theme_template(
f"invenio_requests/{request_type}/community_dashboard.html",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Invenio App RDM Input Overrides
***********************************************/

.input.invitation-searchbar {
.input.invitation-searchbar,
.input.member-requests-searchbar {
width: 100%;
}

Expand Down
Loading