Skip to content

Commit 093dce1

Browse files
committed
Add bulk mailbox permissions action
Introduces a new 'Bulk Add Mailbox Permissions' action to CippExchangeActions, allowing admins to assign Full Access, Send As, and Send On Behalf permissions to multiple mailboxes at once. Utilizes user selection fields with API integration and a custom data formatter for bulk requests.
1 parent e4b3f4a commit 093dce1

File tree

1 file changed

+123
-5
lines changed

1 file changed

+123
-5
lines changed

src/components/CippComponents/CippExchangeActions.jsx

Lines changed: 123 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
import {
33
Archive,
44
MailOutline,
5-
Person,
6-
Room,
75
Visibility,
8-
VisibilityOff,
96
PhonelinkLock,
107
Key,
118
PostAdd,
@@ -17,12 +14,134 @@ import {
1714
MailLock,
1815
SettingsEthernet,
1916
CalendarMonth,
17+
PersonAdd,
2018
Email,
2119
} from "@mui/icons-material";
20+
import { useSettings } from "/src/hooks/use-settings.js";
21+
import { useMemo } from "react";
2222

2323
export const CippExchangeActions = () => {
24-
// const tenant = useSettings().currentTenant;
24+
const tenant = useSettings().currentTenant;
25+
26+
// API configuration for all user selection fields
27+
const userApiConfig = useMemo(() => ({
28+
url: "/api/ListGraphRequest",
29+
dataKey: "Results",
30+
labelField: (option) => `${option.displayName} (${option.userPrincipalName})`,
31+
valueField: "userPrincipalName",
32+
queryKey: `users-${tenant}`,
33+
data: {
34+
Endpoint: "users",
35+
tenantFilter: tenant,
36+
$select: "id,displayName,userPrincipalName,mail",
37+
$top: 999,
38+
},
39+
}), [tenant]);
40+
2541
return [
42+
{
43+
label: "Bulk Add Mailbox Permissions",
44+
type: "POST",
45+
url: "/api/ExecModifyMBPerms",
46+
icon: <PersonAdd />,
47+
data: {
48+
userID: "UPN",
49+
},
50+
confirmText: "Add the specified permissions to selected mailboxes?",
51+
multiPost: false,
52+
data: {
53+
},
54+
fields: [
55+
{
56+
type: "autoComplete",
57+
name: "fullAccessUser",
58+
label: "Add Full Access User",
59+
multiple: true,
60+
creatable: false,
61+
api: userApiConfig,
62+
},
63+
{
64+
type: "switch",
65+
name: "autoMap",
66+
label: "Enable Automapping",
67+
defaultValue: true,
68+
labelLocation: "behind",
69+
},
70+
{
71+
type: "autoComplete",
72+
name: "sendAsUser",
73+
label: "Add Send As User",
74+
multiple: true,
75+
creatable: false,
76+
api: userApiConfig,
77+
},
78+
{
79+
type: "autoComplete",
80+
name: "sendOnBehalfUser",
81+
label: "Add Send On Behalf User",
82+
multiple: true,
83+
creatable: false,
84+
api: userApiConfig,
85+
},
86+
],
87+
customDataformatter: (rows, action, formData) => {
88+
89+
const mailboxArray = Array.isArray(rows) ? rows : [rows];
90+
91+
// Create bulk request array - one object per mailbox
92+
const bulkRequestData = mailboxArray.map(mailbox => {
93+
const permissions = [];
94+
const autoMap = formData.autoMap === undefined ? true : formData.autoMap;
95+
96+
// Add type: "user" to match format
97+
const addTypeToUsers = (users) => {
98+
return users.map(user => ({
99+
...user,
100+
type: "user"
101+
}));
102+
};
103+
104+
// Handle FullAccess - formData.fullAccessUser is an array since multiple: true
105+
if (formData.fullAccessUser && formData.fullAccessUser.length > 0) {
106+
permissions.push({
107+
UserID: addTypeToUsers(formData.fullAccessUser),
108+
PermissionLevel: "FullAccess",
109+
Modification: "Add",
110+
AutoMap: autoMap,
111+
});
112+
}
113+
114+
// Handle SendAs - formData.sendAsUser is an array since multiple: true
115+
if (formData.sendAsUser && formData.sendAsUser.length > 0) {
116+
permissions.push({
117+
UserID: addTypeToUsers(formData.sendAsUser),
118+
PermissionLevel: "SendAs",
119+
Modification: "Add",
120+
});
121+
}
122+
123+
// Handle SendOnBehalf - formData.sendOnBehalfUser is an array since multiple: true
124+
if (formData.sendOnBehalfUser && formData.sendOnBehalfUser.length > 0) {
125+
permissions.push({
126+
UserID: addTypeToUsers(formData.sendOnBehalfUser),
127+
PermissionLevel: "SendOnBehalf",
128+
Modification: "Add",
129+
});
130+
}
131+
132+
return {
133+
userID: mailbox.UPN,
134+
permissions: permissions,
135+
};
136+
});
137+
138+
return {
139+
mailboxRequests: bulkRequestData,
140+
tenantFilter: tenant
141+
};
142+
},
143+
color: "primary",
144+
},
26145
{
27146
label: "Edit permissions",
28147
link: "/identity/administration/users/user/exchange?userId=[ExternalDirectoryObjectId]",
@@ -70,7 +189,6 @@ export const CippExchangeActions = () => {
70189
multiPost: false,
71190
},
72191
{
73-
//tested
74192
label: "Enable Online Archive",
75193
type: "POST",
76194
icon: <Archive />,

0 commit comments

Comments
 (0)