Skip to content

Commit

Permalink
Add view roles for the acl tab
Browse files Browse the repository at this point in the history
Add support for the access roles
ROLE_UI_EVENTS_DETAILS_ACL_USER_ROLES_VIEW
ROLE_UI_EVENTS_DETAILS_ACL_NONUSER_ROLES_VIEW
ROLE_UI_SERIES_DETAILS_ACL_USER_ROLES_VIEW
ROLE_UI_SERIES_DETAILS_ACL_NONUSER_ROLES_VIEW
  • Loading branch information
Arnei committed Dec 19, 2024
1 parent 4c5edf0 commit 6bc1722
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const EventDetailsAccessPolicyTab = ({
userPolicyTableRoleText={"EVENTS.EVENTS.DETAILS.ACCESS.ACCESS_POLICY.USER"}
userPolicyTableNewText={"EVENTS.EVENTS.DETAILS.ACCESS.ACCESS_POLICY.NEW_USER"}
editAccessRole={"ROLE_UI_EVENTS_DETAILS_ACL_EDIT"}
viewUsersAccessRole={"ROLE_UI_EVENTS_DETAILS_ACL_USER_ROLES_VIEW"}
viewNonUsersAccessRole={"ROLE_UI_EVENTS_DETAILS_ACL_NONUSER_ROLES_VIEW"}
policyChanged={policyChanged}
setPolicyChanged={setPolicyChanged}
/>
Expand Down
67 changes: 38 additions & 29 deletions src/components/events/partials/ModalTabsAndPages/NewAccessPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { getSeriesDetailsAcl } from "../../../../selectors/seriesDetailsSelector
import { TransformedAcl } from "../../../../slices/aclDetailsSlice";
import { AccessPolicyTable, TemplateSelector } from "../../../shared/modals/ResourceDetailsAccessPolicyTab";
import { getUserInformation } from "../../../../selectors/userInfoSelectors";
import { hasAccess } from "../../../../utils/utils";

/**
* This component renders the access page for new events and series in the wizards.
Expand All @@ -33,12 +34,16 @@ const NewAccessPage = <T extends RequiredFormProps>({
nextPage,
previousPage,
editAccessRole,
viewUsersAccessRole,
viewNonUsersAccessRole,
initEventAclWithSeriesAcl
}: {
formik: FormikProps<T>,
nextPage: (values: T) => void,
previousPage: (values: T, twoPagesBack?: boolean) => void,
editAccessRole: string,
viewUsersAccessRole: string,
viewNonUsersAccessRole: string,
initEventAclWithSeriesAcl: boolean
}) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -114,35 +119,39 @@ const NewAccessPage = <T extends RequiredFormProps>({

{roles.length > 0 && !roles[0].isSanitize &&
<>
<AccessPolicyTable
isUserTable={true}
policiesFiltered={policiesFiltered(formik.values.policies, true)}
rolesFilteredbyPolicies={rolesFilteredbyPolicies(roles, formik.values.policies, true)}
header={"EVENTS.EVENTS.DETAILS.ACCESS.ACCESS_POLICY.USERS"}
firstColumnHeader={"EVENTS.EVENTS.DETAILS.ACCESS.ACCESS_POLICY.USER"}
createLabel={"EVENTS.EVENTS.DETAILS.ACCESS.ACCESS_POLICY.NEW_USER"}
formik={formik}
hasActions={aclActions.length > 0 }
transactions={{read_only: false}}
aclActions={aclActions}
roles={roles}
editAccessRole={editAccessRole}
/>

<AccessPolicyTable
isUserTable={false}
policiesFiltered={policiesFiltered(formik.values.policies, false)}
rolesFilteredbyPolicies={rolesFilteredbyPolicies(roles, formik.values.policies, false)}
header={"EVENTS.EVENTS.DETAILS.ACCESS.ACCESS_POLICY.DETAILS"}
firstColumnHeader={"EVENTS.EVENTS.DETAILS.ACCESS.ACCESS_POLICY.ROLE"}
createLabel={"EVENTS.EVENTS.DETAILS.ACCESS.ACCESS_POLICY.NEW"}
formik={formik}
hasActions={aclActions.length > 0 }
transactions={{read_only: false}}
aclActions={aclActions}
roles={roles}
editAccessRole={editAccessRole}
/>
{hasAccess(viewUsersAccessRole, user) &&
<AccessPolicyTable
isUserTable={true}
policiesFiltered={policiesFiltered(formik.values.policies, true)}
rolesFilteredbyPolicies={rolesFilteredbyPolicies(roles, formik.values.policies, true)}
header={"EVENTS.EVENTS.DETAILS.ACCESS.ACCESS_POLICY.USERS"}
firstColumnHeader={"EVENTS.EVENTS.DETAILS.ACCESS.ACCESS_POLICY.USER"}
createLabel={"EVENTS.EVENTS.DETAILS.ACCESS.ACCESS_POLICY.NEW_USER"}
formik={formik}
hasActions={aclActions.length > 0 }
transactions={{read_only: false}}
aclActions={aclActions}
roles={roles}
editAccessRole={editAccessRole}
/>
}

{hasAccess(viewNonUsersAccessRole, user) &&
<AccessPolicyTable
isUserTable={false}
policiesFiltered={policiesFiltered(formik.values.policies, false)}
rolesFilteredbyPolicies={rolesFilteredbyPolicies(roles, formik.values.policies, false)}
header={"EVENTS.EVENTS.DETAILS.ACCESS.ACCESS_POLICY.DETAILS"}
firstColumnHeader={"EVENTS.EVENTS.DETAILS.ACCESS.ACCESS_POLICY.ROLE"}
createLabel={"EVENTS.EVENTS.DETAILS.ACCESS.ACCESS_POLICY.NEW"}
formik={formik}
hasActions={aclActions.length > 0 }
transactions={{read_only: false}}
aclActions={aclActions}
roles={roles}
editAccessRole={editAccessRole}
/>
}
</>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const SeriesDetailsAccessTab = ({
userPolicyTableRoleText={"EVENTS.SERIES.DETAILS.ACCESS.ACCESS_POLICY.USER"}
userPolicyTableNewText={"EVENTS.SERIES.DETAILS.ACCESS.ACCESS_POLICY.NEW_USER"}
editAccessRole={"ROLE_UI_SERIES_DETAILS_ACL_EDIT"}
viewUsersAccessRole={"ROLE_UI_SERIES_DETAILS_ACL_USER_ROLES_VIEW"}
viewNonUsersAccessRole={"ROLE_UI_SERIES_DETAILS_ACL_NONUSER_ROLES_VIEW"}
policyChanged={policyChanged}
setPolicyChanged={setPolicyChanged}
/>
Expand Down
2 changes: 2 additions & 0 deletions src/components/events/partials/wizards/NewEventWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ const NewEventWizard: React.FC<{
// @ts-expect-error TS(7006):
formik={formik}
editAccessRole="ROLE_UI_SERIES_DETAILS_ACL_EDIT"
viewUsersAccessRole="ROLE_UI_EVENTS_DETAILS_ACL_USER_ROLES_VIEW"
viewNonUsersAccessRole="ROLE_UI_EVENTS_DETAILS_ACL_NONUSER_ROLES_VIEW"
initEventAclWithSeriesAcl={initEventAclWithSeriesAcl}
/>
)}
Expand Down
2 changes: 2 additions & 0 deletions src/components/events/partials/wizards/NewSeriesWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ const NewSeriesWizard: React.FC<{
// @ts-expect-error TS(7006):
formik={formik}
editAccessRole="ROLE_UI_SERIES_DETAILS_ACL_EDIT"
viewUsersAccessRole="ROLE_UI_SERIES_DETAILS_ACL_USER_ROLES_VIEW"
viewNonUsersAccessRole="ROLE_UI_SERIES_DETAILS_ACL_NONUSER_ROLES_VIEW"
initEventAclWithSeriesAcl={false}
/>
)}
Expand Down
38 changes: 23 additions & 15 deletions src/components/shared/modals/ResourceDetailsAccessPolicyTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const ResourceDetailsAccessPolicyTab = ({
userPolicyTableRoleText,
userPolicyTableNewText,
editAccessRole,
viewUsersAccessRole,
viewNonUsersAccessRole,
policyChanged,
setPolicyChanged,
}: {
Expand All @@ -69,6 +71,8 @@ const ResourceDetailsAccessPolicyTab = ({
userPolicyTableRoleText: string,
userPolicyTableNewText: string,
editAccessRole: string,
viewUsersAccessRole: string,
viewNonUsersAccessRole: string,
policyChanged: boolean,
setPolicyChanged: (value: boolean) => void,
}) => {
Expand Down Expand Up @@ -294,21 +298,24 @@ const ResourceDetailsAccessPolicyTab = ({

{roles.length > 0 && !roles[0].isSanitize &&
<>
<AccessPolicyTable
isUserTable={true}
policiesFiltered={policiesFiltered(formik.values.policies, true)}
rolesFilteredbyPolicies={rolesFilteredbyPolicies(roles, formik.values.policies, true)}
header={userPolicyTableHeaderText}
firstColumnHeader={userPolicyTableRoleText}
createLabel={userPolicyTableNewText}
formik={formik}
hasActions={hasActions}
transactions={transactions}
aclActions={aclActions}
roles={roles}
editAccessRole={editAccessRole}
/>

{hasAccess(viewUsersAccessRole, user) &&
<AccessPolicyTable
isUserTable={true}
policiesFiltered={policiesFiltered(formik.values.policies, true)}
rolesFilteredbyPolicies={rolesFilteredbyPolicies(roles, formik.values.policies, true)}
header={userPolicyTableHeaderText}
firstColumnHeader={userPolicyTableRoleText}
createLabel={userPolicyTableNewText}
formik={formik}
hasActions={hasActions}
transactions={transactions}
aclActions={aclActions}
roles={roles}
editAccessRole={editAccessRole}
/>
}

{hasAccess(viewNonUsersAccessRole, user) &&
<AccessPolicyTable
isUserTable={false}
policiesFiltered={policiesFiltered(formik.values.policies, false)}
Expand All @@ -323,6 +330,7 @@ const ResourceDetailsAccessPolicyTab = ({
roles={roles}
editAccessRole={editAccessRole}
/>
}
</>
}

Expand Down

0 comments on commit 6bc1722

Please sign in to comment.