Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect config option for adding series ACL to new event #321

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/components/events/partials/ModalTabsAndPages/NewAccessPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 11 additions & 2 deletions src/components/events/partials/wizards/NewEventWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand All @@ -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);
Expand Down Expand Up @@ -193,6 +201,7 @@ const NewEventWizard: React.FC<{
nextPage={nextPage}
formik={formik}
editAccessRole="ROLE_UI_SERIES_DETAILS_ACL_EDIT"
initEventAclWithSeriesAcl={initEventAclWithSeriesAcl}
/>
)}
{page === 6 && (
Expand Down
1 change: 1 addition & 0 deletions src/components/events/partials/wizards/NewSeriesWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ const NewSeriesWizard: React.FC<{
previousPage={previousPage}
formik={formik}
editAccessRole="ROLE_UI_SERIES_DETAILS_ACL_EDIT"
initEventAclWithSeriesAcl={false}
/>
)}
{page === 3 && (
Expand Down
Loading