From 89a0acc3112dfa4955e78db440a098686d93c646 Mon Sep 17 00:00:00 2001 From: anikachurilova Date: Thu, 10 Aug 2023 18:08:18 +0200 Subject: [PATCH 1/2] access request: update guest request payload * add an overridable for the timeline header * inject permissions prop * closes https://github.com/inveniosoftware/invenio-rdm-records/issues/1395 --- .../js/invenio_requests/InvenioRequestsApp.js | 5 +++-- .../semantic-ui/js/invenio_requests/request/Request.js | 5 +++-- .../js/invenio_requests/request/RequestDetails.js | 5 +++-- .../semantic-ui/js/invenio_requests/requestsAppInit.js | 9 ++++++++- .../js/invenio_requests/timeline/TimelineFeed.js | 5 ++++- invenio_requests/services/requests/components.py | 2 ++ .../semantic-ui/invenio_requests/details/index.html | 1 + 7 files changed, 24 insertions(+), 8 deletions(-) diff --git a/invenio_requests/assets/semantic-ui/js/invenio_requests/InvenioRequestsApp.js b/invenio_requests/assets/semantic-ui/js/invenio_requests/InvenioRequestsApp.js index cbeb6186..afbeb65a 100644 --- a/invenio_requests/assets/semantic-ui/js/invenio_requests/InvenioRequestsApp.js +++ b/invenio_requests/assets/semantic-ui/js/invenio_requests/InvenioRequestsApp.js @@ -38,12 +38,12 @@ export class InvenioRequestsApp extends Component { } render() { - const { overriddenCmps, userAvatar } = this.props; + const { overriddenCmps, userAvatar, permissions } = this.props; return ( - + ); @@ -57,6 +57,7 @@ InvenioRequestsApp.propTypes = { request: PropTypes.object.isRequired, userAvatar: PropTypes.string.isRequired, defaultQueryParams: PropTypes.object, + permissions: PropTypes.object.isRequired, }; InvenioRequestsApp.defaultProps = { diff --git a/invenio_requests/assets/semantic-ui/js/invenio_requests/request/Request.js b/invenio_requests/assets/semantic-ui/js/invenio_requests/request/Request.js index 71fce9a9..2d8382fc 100644 --- a/invenio_requests/assets/semantic-ui/js/invenio_requests/request/Request.js +++ b/invenio_requests/assets/semantic-ui/js/invenio_requests/request/Request.js @@ -19,7 +19,7 @@ export class Request extends Component { } render() { - const { request, updateRequestAfterAction, userAvatar } = this.props; + const { request, updateRequestAfterAction, userAvatar, permissions } = this.props; return ( @@ -28,7 +28,7 @@ export class Request extends Component { request={request} actionSuccessCallback={updateRequestAfterAction} /> - + ); @@ -40,6 +40,7 @@ Request.propTypes = { initRequest: PropTypes.func.isRequired, updateRequestAfterAction: PropTypes.func.isRequired, userAvatar: PropTypes.string, + permissions: PropTypes.object.isRequired, }; Request.defaultProps = { diff --git a/invenio_requests/assets/semantic-ui/js/invenio_requests/request/RequestDetails.js b/invenio_requests/assets/semantic-ui/js/invenio_requests/request/RequestDetails.js index f50691ef..2193552a 100644 --- a/invenio_requests/assets/semantic-ui/js/invenio_requests/request/RequestDetails.js +++ b/invenio_requests/assets/semantic-ui/js/invenio_requests/request/RequestDetails.js @@ -13,13 +13,13 @@ import { Timeline } from "../timeline"; class RequestDetails extends Component { render() { - const { request, userAvatar } = this.props; + const { request, userAvatar, permissions } = this.props; return ( <> - + @@ -34,6 +34,7 @@ class RequestDetails extends Component { RequestDetails.propTypes = { request: PropTypes.object.isRequired, userAvatar: PropTypes.string, + permissions: PropTypes.object.isRequired, }; RequestDetails.defaultProps = { diff --git a/invenio_requests/assets/semantic-ui/js/invenio_requests/requestsAppInit.js b/invenio_requests/assets/semantic-ui/js/invenio_requests/requestsAppInit.js index c895bb67..17ce50ef 100644 --- a/invenio_requests/assets/semantic-ui/js/invenio_requests/requestsAppInit.js +++ b/invenio_requests/assets/semantic-ui/js/invenio_requests/requestsAppInit.js @@ -41,11 +41,13 @@ import { LabelTypeGuestAccess, LabelTypeUserAccess, } from "./contrib"; +import { overrideStore } from "react-overridable"; const requestDetailsDiv = document.getElementById("request-detail"); const request = JSON.parse(requestDetailsDiv.dataset.record); const defaultQueryParams = JSON.parse(requestDetailsDiv.dataset.defaultQueryConfig); const userAvatar = JSON.parse(requestDetailsDiv.dataset.userAvatar); +const permissions = JSON.parse(requestDetailsDiv.dataset.permissions); const overriddenComponents = { "TimelineEvent.layout.unknown": TimelineUnknownEvent, @@ -76,12 +78,17 @@ const overriddenComponents = { "RequestActionModal.title.decline": () => i18next.t("Decline request"), }; +for (const [key, value] of Object.entries(overriddenComponents)) { + overrideStore.add(key, value); +} + ReactDOM.render( , requestDetailsDiv ); diff --git a/invenio_requests/assets/semantic-ui/js/invenio_requests/timeline/TimelineFeed.js b/invenio_requests/assets/semantic-ui/js/invenio_requests/timeline/TimelineFeed.js index cfe51024..c308cbcd 100644 --- a/invenio_requests/assets/semantic-ui/js/invenio_requests/timeline/TimelineFeed.js +++ b/invenio_requests/assets/semantic-ui/js/invenio_requests/timeline/TimelineFeed.js @@ -41,7 +41,7 @@ class TimelineFeed extends Component { }; render() { - const { timeline, loading, error, setPage, size, page, userAvatar } = this.props; + const { timeline, loading, error, setPage, size, page, userAvatar, request, permissions } = this.props; const { modalOpen, modalAction } = this.state; return ( @@ -49,6 +49,7 @@ class TimelineFeed extends Component { + {timeline.hits?.hits.map((event) => ( data-record='{{ invenio_request | tojson }}' data-default-query-config='{{ dict(size=config["REQUESTS_TIMELINE_PAGE_SIZE"]) | tojson }}' data-user-avatar='{{ user_avatar | tojson }}' + data-permissions='{{ permissions | tojson }}' >{# react app root #}
From 232db7e7fc2e39a21f40a6e6739ccbb6e5fdab2c Mon Sep 17 00:00:00 2001 From: Nicola Tarocco Date: Fri, 11 Aug 2023 14:39:37 +0200 Subject: [PATCH 2/2] access requests UI: fix overridden cmps --- .../js/invenio_requests/requestsAppInit.js | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/invenio_requests/assets/semantic-ui/js/invenio_requests/requestsAppInit.js b/invenio_requests/assets/semantic-ui/js/invenio_requests/requestsAppInit.js index 17ce50ef..69895ef9 100644 --- a/invenio_requests/assets/semantic-ui/js/invenio_requests/requestsAppInit.js +++ b/invenio_requests/assets/semantic-ui/js/invenio_requests/requestsAppInit.js @@ -12,12 +12,20 @@ import { import { i18next } from "@translations/invenio_requests/i18next"; import React from "react"; import ReactDOM from "react-dom"; +import { overrideStore } from "react-overridable"; +import { InvenioRequestsApp } from "./InvenioRequestsApp"; import { RequestAcceptButton, RequestCancelButton, RequestDeclineButton, } from "./components/Buttons"; -import { InvenioRequestsApp } from "./InvenioRequestsApp"; +import { + LabelTypeCommunityInclusion, + LabelTypeCommunityInvitation, + LabelTypeCommunitySubmission, + LabelTypeGuestAccess, + LabelTypeUserAccess, +} from "./contrib"; import { AcceptStatus, CancelStatus, @@ -34,14 +42,6 @@ import { TimelineExpireEvent, TimelineUnknownEvent, } from "./timelineEvents"; -import { - LabelTypeCommunityInclusion, - LabelTypeCommunityInvitation, - LabelTypeCommunitySubmission, - LabelTypeGuestAccess, - LabelTypeUserAccess, -} from "./contrib"; -import { overrideStore } from "react-overridable"; const requestDetailsDiv = document.getElementById("request-detail"); const request = JSON.parse(requestDetailsDiv.dataset.record); @@ -49,7 +49,7 @@ const defaultQueryParams = JSON.parse(requestDetailsDiv.dataset.defaultQueryConf const userAvatar = JSON.parse(requestDetailsDiv.dataset.userAvatar); const permissions = JSON.parse(requestDetailsDiv.dataset.permissions); -const overriddenComponents = { +const defaultComponents = { "TimelineEvent.layout.unknown": TimelineUnknownEvent, "TimelineEvent.layout.declined": TimelineDeclineEvent, "TimelineEvent.layout.accepted": TimelineAcceptEvent, @@ -78,15 +78,13 @@ const overriddenComponents = { "RequestActionModal.title.decline": () => i18next.t("Decline request"), }; -for (const [key, value] of Object.entries(overriddenComponents)) { - overrideStore.add(key, value); -} +const overriddenComponents = overrideStore.getAll(); ReactDOM.render( ,