From 33d53a43a7f4b2dffc942075a4f2440d4679cd45 Mon Sep 17 00:00:00 2001 From: Arnei Date: Fri, 5 Apr 2024 14:43:10 +0200 Subject: [PATCH] Respect config option for adding series ACL to new event The backend configuration file `org.opencastproject.organization-mh_default_org.cfg` has a config option called `admin.init.event.acl.with.series.acl`. It determines whether the ACL of a new event is initialized with the ACL of its series, and true per default. We were not respecting this config option at all. This PR changes that. --- .../ModalTabsAndPages/NewAccessPage.tsx | 34 ++++++++++++++++++- .../partials/wizards/NewEventWizard.tsx | 15 ++++++-- .../partials/wizards/NewSeriesWizard.tsx | 1 + 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/app/src/components/events/partials/ModalTabsAndPages/NewAccessPage.tsx b/app/src/components/events/partials/ModalTabsAndPages/NewAccessPage.tsx index 9006cfd766..58dc08a7d1 100644 --- a/app/src/components/events/partials/ModalTabsAndPages/NewAccessPage.tsx +++ b/app/src/components/events/partials/ModalTabsAndPages/NewAccessPage.tsx @@ -16,7 +16,9 @@ import { getUserInformation } from "../../../../selectors/userInfoSelectors"; import { hasAccess } from "../../../../utils/utils"; import DropDown from "../../../shared/DropDown"; import { filterRoles, getAclTemplateText } from "../../../../utils/aclUtils"; -import { useAppSelector } from "../../../../store"; +import { useAppDispatch, useAppSelector } from "../../../../store"; +import { fetchSeriesDetailsAcls } from "../../../../slices/seriesDetailsSlice"; +import { getSeriesDetailsAcl } from "../../../../selectors/seriesDetailsSelectors"; /** * This component renders the access page for new events and series in the wizards. @@ -32,8 +34,11 @@ const NewAccessPage = ({ editAccessRole, // @ts-expect-error TS(7031): Binding element 'checkAcls' implicitly has an 'any... Remove this comment to see the full error message checkAcls, + // @ts-expect-error TS(7031): Binding element 'checkAcls' implicitly has an 'any... Remove this comment to see the full error messag + initEventAclWithSeriesAcl //boolean }) => { const { t } = useTranslation(); + const dispatch = useAppDispatch(); // States containing response from server concerning acl templates, actions and roles const [aclTemplates, setAclTemplates] = useState([]); @@ -42,6 +47,7 @@ const NewAccessPage = ({ const [loading, setLoading] = useState(false); const user = useAppSelector(state => getUserInformation(state)); + const seriesAcl = useAppSelector(state => getSeriesDetailsAcl(state)); useEffect(() => { // fetch data about roles, acl templates and actions from backend @@ -61,6 +67,32 @@ const NewAccessPage = ({ fetchData(); }, []); + // If we have to add series ACL, fetch it + useEffect(() => { + if (initEventAclWithSeriesAcl && formik.values.isPartOf) { + dispatch(fetchSeriesDetailsAcls(formik.values.isPartOf)) + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [formik.values, initEventAclWithSeriesAcl]); + + // If we have to add series ACL, add it + useEffect(() => { + if (initEventAclWithSeriesAcl && formik.values.isPartOf && seriesAcl) { + let rolesToAdd = [] + for (const ace of seriesAcl) { + // @ts-expect-error TS(2345): + if (!formik.values.acls.some(acl => acl.role === ace.role)) { + rolesToAdd.push(ace) + } + } + + if (rolesToAdd.length > 0) { + formik.setFieldValue("acls", [ ...formik.values.acls, ...rolesToAdd ]) + } + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [initEventAclWithSeriesAcl, seriesAcl]); + // @ts-expect-error TS(7006): Parameter 'value' implicitly has an 'any' type. const handleTemplateChange = async (value) => { // fetch information about chosen template from backend diff --git a/app/src/components/events/partials/wizards/NewEventWizard.tsx b/app/src/components/events/partials/wizards/NewEventWizard.tsx index 5a6c759c1c..6c3137396c 100644 --- a/app/src/components/events/partials/wizards/NewEventWizard.tsx +++ b/app/src/components/events/partials/wizards/NewEventWizard.tsx @@ -19,7 +19,7 @@ import { } from "../../../../selectors/eventSelectors"; import { useAppDispatch, useAppSelector } from "../../../../store"; import { postNewEvent } from "../../../../slices/eventSlice"; -import { getUserInformation } from "../../../../selectors/userInfoSelectors"; +import { getOrgProperties, getUserInformation } from "../../../../selectors/userInfoSelectors"; /** * This component manages the pages of the new event wizard and the submission of values @@ -35,12 +35,20 @@ const NewEventWizard: React.FC<{ const metadataFields = useAppSelector(state => getEventMetadata(state)); const extendedMetadata = useAppSelector(state => getExtendedEventMetadata(state)); const user = useAppSelector(state => getUserInformation(state)); + const orgProperties = useAppSelector(state => getOrgProperties(state)); + + // Whether the ACL of a new event is initialized with the ACL of its series. + let initEventAclWithSeriesAcl = true + const ADMIN_INIT_EVENT_ACL_WITH_SERIES_ACL = "admin.init.event.acl.with.series.acl"; + if (!!orgProperties && !!orgProperties[ADMIN_INIT_EVENT_ACL_WITH_SERIES_ACL]) { + initEventAclWithSeriesAcl = user.org.properties[ADMIN_INIT_EVENT_ACL_WITH_SERIES_ACL] === 'true'; + } const initialValues = getInitialValues( metadataFields, extendedMetadata, uploadAssetOptions, - user + user, ); let workflowPanelRef = React.useRef(); @@ -200,6 +208,7 @@ const NewEventWizard: React.FC<{ nextPage={nextPage} formik={formik} editAccessRole="ROLE_UI_SERIES_DETAILS_ACL_EDIT" + initEventAclWithSeriesAcl={initEventAclWithSeriesAcl} /> )} {page === 6 && ( @@ -228,7 +237,7 @@ const getInitialValues = ( // @ts-expect-error TS(7006): Parameter 'uploadAssetOptions' implicitly has an '... Remove this comment to see the full error message uploadAssetOptions, // @ts-expect-error TS(7006): Parameter 'uploadAssetOptions' implicitly has an '... Remove this comment to see the full error message - user + user, ) => { // Transform metadata fields provided by backend (saved in redux) let initialValues = getInitialMetadataFieldValues( diff --git a/app/src/components/events/partials/wizards/NewSeriesWizard.tsx b/app/src/components/events/partials/wizards/NewSeriesWizard.tsx index 02185dd387..925d132c39 100644 --- a/app/src/components/events/partials/wizards/NewSeriesWizard.tsx +++ b/app/src/components/events/partials/wizards/NewSeriesWizard.tsx @@ -155,6 +155,7 @@ const NewSeriesWizard: React.FC<{ previousPage={previousPage} formik={formik} editAccessRole="ROLE_UI_SERIES_DETAILS_ACL_EDIT" + initEventAclWithSeriesAcl={false} /> )} {page === 3 && (