Skip to content

Enhance CippExchangeSettingsForm and user exchange page with mailbox permissions management #4187

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

Merged
merged 9 commits into from
Jun 4, 2025
2 changes: 2 additions & 0 deletions src/components/CippCards/CippBannerListCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export const CippBannerListCard = (props) => {
<Typography variant="body2">{item.statusText}</Typography>
</Stack>
)}
{item?.cardLabelBoxActions && item.cardLabelBoxActions}
{isCollapsible && (
<IconButton onClick={() => handleExpand(item.id)}>
<SvgIcon
Expand Down Expand Up @@ -190,6 +191,7 @@ CippBannerListCard.propTypes = {
actionButton: PropTypes.element,
isFetching: PropTypes.bool,
children: PropTypes.node,
cardLabelBoxActions: PropTypes.element,
})
).isRequired,
isCollapsible: PropTypes.bool,
Expand Down
182 changes: 2 additions & 180 deletions src/components/CippFormPages/CippExchangeSettingsForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ApiGetCall, ApiPostCall } from "../../api/ApiCall";
import { useSettings } from "../../hooks/use-settings";
import { Grid } from "@mui/system";
import { CippApiResults } from "../CippComponents/CippApiResults";
import { useWatch, useFormContext } from "react-hook-form";
import { useWatch } from "react-hook-form";

const CippExchangeSettingsForm = (props) => {
const userSettingsDefaults = useSettings();
Expand Down Expand Up @@ -50,9 +50,7 @@ const CippExchangeSettingsForm = (props) => {
});

const handleSubmit = (type) => {
if (type === "permissions") {
setRelatedQueryKeys([`Mailbox-${userId}`]);
} else if (type === "calendar") {
if (type === "calendar") {
setRelatedQueryKeys([`CalendarPermissions-${userId}`]);
} else if (type === "forwarding") {
setRelatedQueryKeys([`Mailbox-${userId}`]);
Expand Down Expand Up @@ -83,7 +81,6 @@ const CippExchangeSettingsForm = (props) => {
}
});
const url = {
permissions: "/api/ExecEditMailboxPermissions",
calendar: "/api/ExecEditCalendarPermissions",
forwarding: "/api/ExecEmailForward",
ooo: "/api/ExecSetOoO",
Expand All @@ -101,181 +98,6 @@ const CippExchangeSettingsForm = (props) => {

// Data for each section
const sections = [
{
id: "mailboxPermissions",
cardLabelBox: "-",
text: "Mailbox Permissions",
subtext: "Manage mailbox permissions for users",
formContent: (
<Stack spacing={1.5}>
{/* Full Access Section */}
<Box sx={{
p: 2,
border: '1px solid',
borderColor: 'divider',
borderRadius: 1,
backgroundColor: 'background.paper'
}}>
<Typography variant="subtitle2" gutterBottom>Full Access</Typography>
<Typography variant="caption" color="text.secondary" gutterBottom>
Manage who has full access to this mailbox
</Typography>
<Stack spacing={2} sx={{ mt: 2 }}>
<CippFormComponent
type="autoComplete"
label="Remove Full Access"
name="permissions.RemoveFullAccess"
isFetching={isFetching || usersList.isFetching}
options={
usersList?.data?.Results?.filter((user) =>
currentSettings?.Permissions?.some(
(perm) =>
perm.AccessRights === "FullAccess" && perm.User === user.userPrincipalName
)
).map((user) => ({
value: user.userPrincipalName,
label: `${user.displayName} (${user.userPrincipalName})`,
})) || []
}
formControl={formControl}
/>
<CippFormComponent
type="autoComplete"
label="Add Full Access - Automapping Enabled"
name="permissions.AddFullAccess"
isFetching={isFetching || usersList.isFetching}
options={
usersList?.data?.Results?.map((user) => ({
value: user.userPrincipalName,
label: `${user.displayName} (${user.userPrincipalName})`,
})) || []
}
formControl={formControl}
/>
<CippFormComponent
type="autoComplete"
label="Add Full Access - Automapping Disabled"
name="permissions.AddFullAccessNoAutoMap"
isFetching={isFetching || usersList.isFetching}
options={
usersList?.data?.Results?.map((user) => ({
value: user.userPrincipalName,
label: `${user.displayName} (${user.userPrincipalName})`,
})) || []
}
formControl={formControl}
/>
</Stack>
</Box>

{/* Send As Section */}
<Box sx={{
p: 2,
border: '1px solid',
borderColor: 'divider',
borderRadius: 1,
backgroundColor: 'background.paper'
}}>
<Typography variant="subtitle2" gutterBottom>Send As</Typography>
<Typography variant="caption" color="text.secondary" gutterBottom>
Manage who can send emails as this user
</Typography>
<Stack spacing={2} sx={{ mt: 2 }}>
<CippFormComponent
type="autoComplete"
label="Remove Send-as Permissions"
name="permissions.RemoveSendAs"
isFetching={isFetching || usersList.isFetching}
options={
usersList?.data?.Results?.filter((user) =>
currentSettings?.Permissions?.some(
(perm) => perm.AccessRights === "SendAs" && perm.User === user.userPrincipalName
)
).map((user) => ({
value: user.userPrincipalName,
label: `${user.displayName} (${user.userPrincipalName})`,
})) || []
}
formControl={formControl}
/>
<CippFormComponent
type="autoComplete"
label="Add Send-as Permissions"
name="permissions.AddSendAs"
isFetching={isFetching || usersList.isFetching}
options={
usersList?.data?.Results?.map((user) => ({
value: user.userPrincipalName,
label: `${user.displayName} (${user.userPrincipalName})`,
})) || []
}
formControl={formControl}
/>
</Stack>
</Box>

{/* Send On Behalf Section */}
<Box sx={{
p: 2,
border: '1px solid',
borderColor: 'divider',
borderRadius: 1,
backgroundColor: 'background.paper'
}}>
<Typography variant="subtitle2" gutterBottom>Send On Behalf</Typography>
<Typography variant="caption" color="text.secondary" gutterBottom>
Manage who can send emails on behalf of this user
</Typography>
<Stack spacing={2} sx={{ mt: 2 }}>
<CippFormComponent
type="autoComplete"
label="Remove Send On Behalf Permissions"
name="permissions.RemoveSendOnBehalf"
isFetching={isFetching || usersList.isFetching}
options={
usersList?.data?.Results?.filter((user) =>
currentSettings?.Permissions?.some(
(perm) =>
perm.AccessRights === "SendOnBehalf" && perm.User === user.userPrincipalName
)
).map((user) => ({
value: user.userPrincipalName,
label: `${user.displayName} (${user.userPrincipalName})`,
})) || []
}
formControl={formControl}
/>
<CippFormComponent
type="autoComplete"
label="Add Send On Behalf Permissions"
name="permissions.AddSendOnBehalf"
isFetching={isFetching || usersList.isFetching}
options={
usersList?.data?.Results?.map((user) => ({
value: user.userPrincipalName,
label: `${user.displayName} (${user.userPrincipalName})`,
})) || []
}
formControl={formControl}
/>
</Stack>
</Box>

<Grid item size={12}>
<CippApiResults apiObject={postRequest} />
</Grid>
<Grid>
<Button
onClick={() => handleSubmit("permissions")}
variant="contained"
disabled={!formControl.formState.isValid || postRequest.isPending}
>
Submit
</Button>
</Grid>
</Stack>
),
},
{
id: "calendarPermissions",
cardLabelBox: "-",
Expand Down
Loading
Loading