Skip to content

Commit

Permalink
Merge pull request opencast#300 from Arnei/user-role-when-creating
Browse files Browse the repository at this point in the history
Fix user not having access to created event
  • Loading branch information
Arnei authored Mar 28, 2024
2 parents e2dc4bc + 29f7b99 commit af77cef
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
19 changes: 17 additions & 2 deletions app/src/components/events/partials/wizards/NewEventWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from "../../../../selectors/eventSelectors";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { postNewEvent } from "../../../../slices/eventSlice";
import { getUserInformation } from "../../../../selectors/userInfoSelectors";

/**
* This component manages the pages of the new event wizard and the submission of values
Expand All @@ -33,11 +34,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();

Expand Down Expand Up @@ -223,7 +226,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(
Expand Down Expand Up @@ -297,6 +302,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;
};

Expand Down
16 changes: 14 additions & 2 deletions app/src/components/events/partials/wizards/NewSeriesWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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;
};

Expand Down
18 changes: 2 additions & 16 deletions app/src/configs/modalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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: "",
};

Expand Down

0 comments on commit af77cef

Please sign in to comment.