From 77aa1b745c1a5e1e4e4d41bf9c845244fbfdae93 Mon Sep 17 00:00:00 2001 From: Guillaume Viger Date: Mon, 29 Jul 2024 15:30:56 -0400 Subject: [PATCH] membership-requests [#855]: add discussion page in community dashboard [+] - also fix top menu to display "Members" --- .../community_dashboard.html | 38 +++++++++++++++++++ invenio_app_rdm/requests_ui/views/requests.py | 30 ++++++++++++--- 2 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 invenio_app_rdm/requests_ui/templates/semantic-ui/invenio_requests/community-membership-request/community_dashboard.html diff --git a/invenio_app_rdm/requests_ui/templates/semantic-ui/invenio_requests/community-membership-request/community_dashboard.html b/invenio_app_rdm/requests_ui/templates/semantic-ui/invenio_requests/community-membership-request/community_dashboard.html new file mode 100644 index 000000000..b4e3e4bed --- /dev/null +++ b/invenio_app_rdm/requests_ui/templates/semantic-ui/invenio_requests/community-membership-request/community_dashboard.html @@ -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 %} +
+ {% block request_body %} + {{ super() }} + {% endblock request_body %} +
+{% endblock %} + +{% block page_body %} + {{ super.super() }} +{% endblock page_body %} diff --git a/invenio_app_rdm/requests_ui/views/requests.py b/invenio_app_rdm/requests_ui/views/requests.py index 34d39ceda..0d29771c7 100644 --- a/invenio_app_rdm/requests_ui/views/requests.py +++ b/invenio_app_rdm/requests_ui/views/requests.py @@ -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 @@ -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( @@ -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",