From 29f7b9944b9dddbcd882cfc743589ebbbdfc631d Mon Sep 17 00:00:00 2001 From: Arnei Date: Tue, 5 Mar 2024 13:42:18 +0100 Subject: [PATCH] Fix user not having access to created event When creating a new event (or series), the access tab will suggest to create it with the role `ROLE_USER_ADMIN`. If you are not an admin, this means you won't be able to access the created event later on. Instead of always setting `ROLE_USER_ADMIN` as the default, this tries to get the user role from `/info/me.json` instead and suggest that as the default. Should be more in line with how it works in the old admin ui too --- .../partials/wizards/NewEventWizard.tsx | 19 +++++++++++++++++-- .../partials/wizards/NewSeriesWizard.tsx | 16 ++++++++++++++-- app/src/configs/modalConfig.ts | 18 ++---------------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/app/src/components/events/partials/wizards/NewEventWizard.tsx b/app/src/components/events/partials/wizards/NewEventWizard.tsx index 830adc6665..51ad40e1e6 100644 --- a/app/src/components/events/partials/wizards/NewEventWizard.tsx +++ b/app/src/components/events/partials/wizards/NewEventWizard.tsx @@ -22,6 +22,7 @@ import { } from "../../../../selectors/eventSelectors"; import { useAppDispatch, useAppSelector } from "../../../../store"; import { postNewEvent } from "../../../../slices/eventSlice"; +import { getUserInformation } from "../../../../selectors/userInfoSelectors"; // Get info about the current language and its date locale const currentLanguage = getCurrentLanguageInformation(); @@ -39,11 +40,13 @@ const NewEventWizard: React.FC<{ const uploadAssetOptions = useAppSelector(state => getAssetUploadOptions(state)); const metadataFields = useAppSelector(state => getEventMetadata(state)); const extendedMetadata = useAppSelector(state => getExtendedEventMetadata(state)); + const user = useAppSelector(state => getUserInformation(state)); const initialValues = getInitialValues( metadataFields, extendedMetadata, - uploadAssetOptions + uploadAssetOptions, + user ); let workflowPanelRef = React.useRef(); @@ -237,7 +240,9 @@ const getInitialValues = ( // @ts-expect-error TS(7006): Parameter 'extendedMetadata' implicitly has an 'an... Remove this comment to see the full error message extendedMetadata, // @ts-expect-error TS(7006): Parameter 'uploadAssetOptions' implicitly has an '... Remove this comment to see the full error message - uploadAssetOptions + uploadAssetOptions, +// @ts-expect-error TS(7006): Parameter 'uploadAssetOptions' implicitly has an '... Remove this comment to see the full error message + user ) => { // Transform metadata fields provided by backend (saved in redux) let initialValues = getInitialMetadataFieldValues( @@ -311,6 +316,16 @@ const getInitialValues = ( // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message initialValues["scheduleEndMinute"] = "55"; +// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message + initialValues["acls"] = [ + { + role: user.userRole, + read: true, + write: true, + actions: [], + }, + ]; + return initialValues; }; diff --git a/app/src/components/events/partials/wizards/NewSeriesWizard.tsx b/app/src/components/events/partials/wizards/NewSeriesWizard.tsx index 1f8ec884ff..02185dd387 100644 --- a/app/src/components/events/partials/wizards/NewSeriesWizard.tsx +++ b/app/src/components/events/partials/wizards/NewSeriesWizard.tsx @@ -15,6 +15,7 @@ import { NewSeriesSchema } from "../../../../utils/validate"; import { getInitialMetadataFieldValues } from "../../../../utils/resourceUtils"; import { useAppDispatch, useAppSelector } from "../../../../store"; import { postNewSeries } from "../../../../slices/seriesSlice"; +import { getUserInformation } from "../../../../selectors/userInfoSelectors"; /** * This component manages the pages of the new series wizard and the submission of values @@ -28,8 +29,9 @@ const NewSeriesWizard: React.FC<{ const metadataFields = useAppSelector(state => getSeriesMetadata(state)); const extendedMetadata = useAppSelector(state => getSeriesExtendedMetadata(state)); + const user = useAppSelector(state => getUserInformation(state)); - const initialValues = getInitialValues(metadataFields, extendedMetadata); + const initialValues = getInitialValues(metadataFields, extendedMetadata, user); const [page, setPage] = useState(0); const [snapshot, setSnapshot] = useState(initialValues); @@ -179,7 +181,7 @@ const NewSeriesWizard: React.FC<{ }; // @ts-expect-error TS(7006): Parameter 'metadataFields' implicitly has an 'any'... Remove this comment to see the full error message -const getInitialValues = (metadataFields, extendedMetadata) => { +const getInitialValues = (metadataFields, extendedMetadata, user) => { // Transform metadata fields provided by backend (saved in redux) let initialValues = getInitialMetadataFieldValues( metadataFields, @@ -192,6 +194,16 @@ const getInitialValues = (metadataFields, extendedMetadata) => { initialValues[key] = value; } +// @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message + initialValues["acls"] = [ + { + role: user.userRole, + read: true, + write: true, + actions: [], + }, + ]; + return initialValues; }; diff --git a/app/src/configs/modalConfig.ts b/app/src/configs/modalConfig.ts index 184bb55484..1e622bc6b0 100644 --- a/app/src/configs/modalConfig.ts +++ b/app/src/configs/modalConfig.ts @@ -24,14 +24,7 @@ export const initialFormValuesNewEvents = { processingWorkflow: "", configuration: {}, aclTemplate: "", - acls: [ - { - role: "ROLE_USER_ADMIN", - read: true, - write: true, - actions: [], - }, - ], + acls: [], }; // constants for hours and minutes (used in selection for start/end time and duration) @@ -76,14 +69,7 @@ export const WORKFLOW_UPLOAD_ASSETS_NON_TRACK = "publish-uploaded-assets"; // All fields for new series form that are fix and not depending on response of backend // InitialValues of Formik form (others computed dynamically depending on responses from backend) export const initialFormValuesNewSeries = { - acls: [ - { - role: "ROLE_USER_ADMIN", - read: true, - write: true, - actions: [], - }, - ], + acls: [], theme: "", };