diff --git a/src/components/events/partials/ModalTabsAndPages/NewAccessPage.tsx b/src/components/events/partials/ModalTabsAndPages/NewAccessPage.tsx index 1542cd2a2b..d4557d6ef2 100644 --- a/src/components/events/partials/ModalTabsAndPages/NewAccessPage.tsx +++ b/src/components/events/partials/ModalTabsAndPages/NewAccessPage.tsx @@ -17,6 +17,8 @@ import { hasAccess } from "../../../../utils/utils"; import DropDown from "../../../shared/DropDown"; import { filterRoles, getAclTemplateText } from "../../../../utils/aclUtils"; 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. @@ -30,6 +32,8 @@ const NewAccessPage = ({ formik, // @ts-expect-error TS(7031): Binding element 'editAccessRole' implicitly has an... Remove this comment to see the full error message editAccessRole, + // @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(); @@ -41,6 +45,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 @@ -58,6 +63,22 @@ const NewAccessPage = ({ fetchData(); }, []); + // If we have to use 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 use series ACL, overwrite existing rules + useEffect(() => { + if (initEventAclWithSeriesAcl && formik.values.isPartOf && seriesAcl) { + formik.setFieldValue("acls", seriesAcl) + } + // 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/src/components/events/partials/wizards/NewEventWizard.tsx b/src/components/events/partials/wizards/NewEventWizard.tsx index 5cd23e4847..e833c83495 100644 --- a/src/components/events/partials/wizards/NewEventWizard.tsx +++ b/src/components/events/partials/wizards/NewEventWizard.tsx @@ -18,8 +18,8 @@ import { getExtendedEventMetadata, } from "../../../../selectors/eventSelectors"; import { useAppDispatch, useAppSelector } from "../../../../store"; +import { getOrgProperties, getUserInformation } from "../../../../selectors/userInfoSelectors"; import { MetadataCatalog, UploadAssetOption, postNewEvent } from "../../../../slices/eventSlice"; -import { getUserInformation } from "../../../../selectors/userInfoSelectors"; import { UserInfoState } from "../../../../slices/userInfoSlice"; /** @@ -36,12 +36,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, ); const [page, setPage] = useState(0); @@ -193,6 +201,7 @@ const NewEventWizard: React.FC<{ nextPage={nextPage} formik={formik} editAccessRole="ROLE_UI_SERIES_DETAILS_ACL_EDIT" + initEventAclWithSeriesAcl={initEventAclWithSeriesAcl} /> )} {page === 6 && ( diff --git a/src/components/events/partials/wizards/NewSeriesWizard.tsx b/src/components/events/partials/wizards/NewSeriesWizard.tsx index 3ca7dfa04b..488a602f74 100644 --- a/src/components/events/partials/wizards/NewSeriesWizard.tsx +++ b/src/components/events/partials/wizards/NewSeriesWizard.tsx @@ -174,6 +174,7 @@ const NewSeriesWizard: React.FC<{ previousPage={previousPage} formik={formik} editAccessRole="ROLE_UI_SERIES_DETAILS_ACL_EDIT" + initEventAclWithSeriesAcl={false} /> )} {page === 3 && (