2
2
import {
3
3
Archive ,
4
4
MailOutline ,
5
- Person ,
6
- Room ,
7
5
Visibility ,
8
- VisibilityOff ,
9
6
PhonelinkLock ,
10
7
Key ,
11
8
PostAdd ,
@@ -17,12 +14,134 @@ import {
17
14
MailLock ,
18
15
SettingsEthernet ,
19
16
CalendarMonth ,
17
+ PersonAdd ,
20
18
Email ,
21
19
} from "@mui/icons-material" ;
20
+ import { useSettings } from "/src/hooks/use-settings.js" ;
21
+ import { useMemo } from "react" ;
22
22
23
23
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
+
25
41
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
+ } ,
26
145
{
27
146
label : "Edit permissions" ,
28
147
link : "/identity/administration/users/user/exchange?userId=[ExternalDirectoryObjectId]" ,
@@ -70,7 +189,6 @@ export const CippExchangeActions = () => {
70
189
multiPost : false ,
71
190
} ,
72
191
{
73
- //tested
74
192
label : "Enable Online Archive" ,
75
193
type : "POST" ,
76
194
icon : < Archive /> ,
0 commit comments