Skip to content

Commit

Permalink
Respect config option for adding series ACL to new event
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Arnei committed Apr 5, 2024
1 parent d8f98ba commit 33d53a4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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([]);
Expand All @@ -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
Expand All @@ -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
Expand Down
15 changes: 12 additions & 3 deletions app/src/components/events/partials/wizards/NewEventWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

Expand Down Expand Up @@ -200,6 +208,7 @@ const NewEventWizard: React.FC<{
nextPage={nextPage}
formik={formik}
editAccessRole="ROLE_UI_SERIES_DETAILS_ACL_EDIT"
initEventAclWithSeriesAcl={initEventAclWithSeriesAcl}
/>
)}
{page === 6 && (
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const NewSeriesWizard: React.FC<{
previousPage={previousPage}
formik={formik}
editAccessRole="ROLE_UI_SERIES_DETAILS_ACL_EDIT"
initEventAclWithSeriesAcl={false}
/>
)}
{page === 3 && (
Expand Down

0 comments on commit 33d53a4

Please sign in to comment.