Skip to content

Commit 2195794

Browse files
authored
Merge pull request #863 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 84909fe + 8dc3091 commit 2195794

6 files changed

Lines changed: 146 additions & 13 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Administration/Invoke-ExecScheduleOOOVacation.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,36 @@ function Invoke-ExecScheduleOOOVacation {
2626
$UserDisplay = ($UserUPNs | Select-Object -First 3) -join ', '
2727
if ($UserUPNs.Count -gt 3) { $UserDisplay += " (+$($UserUPNs.Count - 3) more)" }
2828

29+
# Convert epoch timestamps to datetime strings for Scheduled mode
30+
$StartTimeStr = [DateTimeOffset]::FromUnixTimeSeconds([int64]$StartDate).DateTime.ToString()
31+
$EndTimeStr = [DateTimeOffset]::FromUnixTimeSeconds([int64]$EndDate).DateTime.ToString()
32+
2933
$SharedParams = [PSCustomObject]@{
3034
TenantFilter = $TenantFilter
3135
Users = $UserUPNs
3236
InternalMessage = $InternalMessage
3337
ExternalMessage = $ExternalMessage
3438
APIName = $APIName
39+
StartTime = $StartTimeStr
40+
EndTime = $EndTimeStr
41+
}
42+
43+
# Calendar options — conditionally add when truthy in the request body
44+
if ($Request.Body.CreateOOFEvent) {
45+
$SharedParams | Add-Member -NotePropertyName 'CreateOOFEvent' -NotePropertyValue $true
46+
}
47+
if (-not [string]::IsNullOrWhiteSpace($Request.Body.OOFEventSubject)) {
48+
$SharedParams | Add-Member -NotePropertyName 'OOFEventSubject' -NotePropertyValue $Request.Body.OOFEventSubject
49+
}
50+
if ($Request.Body.AutoDeclineFutureRequestsWhenOOF) {
51+
$SharedParams | Add-Member -NotePropertyName 'AutoDeclineFutureRequestsWhenOOF' -NotePropertyValue $true
52+
}
53+
if ($Request.Body.DeclineEventsForScheduledOOF) {
54+
$SharedParams | Add-Member -NotePropertyName 'DeclineEventsForScheduledOOF' -NotePropertyValue $true
55+
$SharedParams | Add-Member -NotePropertyName 'DeclineAllEventsForScheduledOOF' -NotePropertyValue $true
56+
}
57+
if (-not [string]::IsNullOrWhiteSpace($Request.Body.DeclineMeetingMessage)) {
58+
$SharedParams | Add-Member -NotePropertyName 'DeclineMeetingMessage' -NotePropertyValue $Request.Body.DeclineMeetingMessage
3559
}
3660

3761
# Add task — enables OOO with messages at start date

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Administration/Invoke-ExecSetOoO.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,27 @@ function Invoke-ExecSetOoO {
5151
$EndTime = $Request.Body.EndTime -match '^\d+$' ? [DateTimeOffset]::FromUnixTimeSeconds([int]$Request.Body.EndTime).DateTime : $Request.Body.EndTime
5252
$SplatParams.StartTime = $StartTime
5353
$SplatParams.EndTime = $EndTime
54+
55+
# Calendar options — only pass when explicitly provided in the request body
56+
if ($null -ne $Request.Body.CreateOOFEvent) {
57+
$SplatParams.CreateOOFEvent = [bool]$Request.Body.CreateOOFEvent
58+
}
59+
if (-not [string]::IsNullOrWhiteSpace($Request.Body.OOFEventSubject)) {
60+
$SplatParams.OOFEventSubject = $Request.Body.OOFEventSubject
61+
}
62+
if ($null -ne $Request.Body.AutoDeclineFutureRequestsWhenOOF) {
63+
$SplatParams.AutoDeclineFutureRequestsWhenOOF = [bool]$Request.Body.AutoDeclineFutureRequestsWhenOOF
64+
}
65+
if ($null -ne $Request.Body.DeclineEventsForScheduledOOF) {
66+
$SplatParams.DeclineEventsForScheduledOOF = [bool]$Request.Body.DeclineEventsForScheduledOOF
67+
$SplatParams.DeclineAllEventsForScheduledOOF = [bool]$Request.Body.DeclineEventsForScheduledOOF
68+
}
69+
if (-not [string]::IsNullOrWhiteSpace($Request.Body.DeclineMeetingMessage)) {
70+
$SplatParams.DeclineMeetingMessage = $Request.Body.DeclineMeetingMessage
71+
}
5472
}
5573

74+
Write-Information "Setting Out of Office with the following parameters: $($SplatParams | ConvertTo-Json -Depth 10)"
5675
$Results = Set-CIPPOutOfOffice @SplatParams
5776
$StatusCode = [HttpStatusCode]::OK
5877
} catch {

Modules/CIPPCore/Public/Entrypoints/Invoke-ListRoles.ps1

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,25 @@ function Invoke-ListRoles {
1111
$TenantFilter = $Request.Query.tenantFilter
1212

1313
try {
14-
[System.Collections.Generic.List[PSCustomObject]]$Roles = New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/directoryRoles?`$expand=members" -tenantid $TenantFilter
14+
[System.Collections.Generic.List[PSCustomObject]]$Roles = New-GraphGetRequest -uri 'https://graph.microsoft.com/v1.0/directoryRoles' -tenantid $TenantFilter
15+
16+
$MemberRequests = $Roles | ForEach-Object {
17+
@{
18+
id = $_.id
19+
method = 'GET'
20+
url = "/directoryRoles/$($_.id)/members"
21+
}
22+
}
23+
$MemberResponses = New-GraphBulkRequest -Requests $MemberRequests -tenantid $TenantFilter -Version 'v1.0'
24+
25+
$MemberMap = @{}
26+
foreach ($Response in $MemberResponses) {
27+
$MemberMap[$Response.id] = $Response.body.value
28+
}
29+
1530
$GraphRequest = foreach ($Role in $Roles) {
16-
$Members = if ($Role.members) {
17-
$Role.members | ForEach-Object { [PSCustomObject]@{
31+
$Members = if ($MemberMap[$Role.id]) {
32+
$MemberMap[$Role.id] | ForEach-Object { [PSCustomObject]@{
1833
displayName = $_.displayName
1934
userPrincipalName = $_.userPrincipalName
2035
id = $_.id

Modules/CIPPCore/Public/Get-CIPPOutOfOffice.ps1

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ function Get-CIPPOutOfOffice {
1010
try {
1111
$OutOfOffice = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-MailboxAutoReplyConfiguration' -cmdParams @{Identity = $UserID } -Anchor $UserID
1212
$Results = @{
13-
AutoReplyState = $OutOfOffice.AutoReplyState
14-
StartTime = $OutOfOffice.StartTime.ToString('yyyy-MM-dd HH:mm')
15-
EndTime = $OutOfOffice.EndTime.ToString('yyyy-MM-dd HH:mm')
16-
InternalMessage = $OutOfOffice.InternalMessage
17-
ExternalMessage = $OutOfOffice.ExternalMessage
13+
AutoReplyState = $OutOfOffice.AutoReplyState
14+
StartTime = $OutOfOffice.StartTime ? $OutOfOffice.StartTime.ToString('yyyy-MM-dd HH:mm') : $null
15+
EndTime = $OutOfOffice.EndTime ? $OutOfOffice.EndTime.ToString('yyyy-MM-dd HH:mm') : $null
16+
InternalMessage = $OutOfOffice.InternalMessage
17+
ExternalMessage = $OutOfOffice.ExternalMessage
18+
CreateOOFEvent = $OutOfOffice.CreateOOFEvent
19+
OOFEventSubject = $OutOfOffice.OOFEventSubject
20+
AutoDeclineFutureRequestsWhenOOF = $OutOfOffice.AutoDeclineFutureRequestsWhenOOF
21+
DeclineEventsForScheduledOOF = $OutOfOffice.DeclineEventsForScheduledOOF
22+
DeclineAllEventsForScheduledOOF = $OutOfOffice.DeclineAllEventsForScheduledOOF
23+
DeclineMeetingMessage = $OutOfOffice.DeclineMeetingMessage
1824
} | ConvertTo-Json
1925
return $Results
2026
} catch {

Modules/CIPPCore/Public/Set-CIPPOutOfoffice.ps1

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ function Set-CIPPOutOfOffice {
1212
$APIName = 'Set Out of Office',
1313
$Headers,
1414
$StartTime,
15-
$EndTime
15+
$EndTime,
16+
[bool]$CreateOOFEvent,
17+
[string]$OOFEventSubject,
18+
[bool]$AutoDeclineFutureRequestsWhenOOF,
19+
[bool]$DeclineEventsForScheduledOOF,
20+
[bool]$DeclineAllEventsForScheduledOOF,
21+
[string]$DeclineMeetingMessage
1622
)
1723

1824
try {
@@ -38,6 +44,26 @@ function Set-CIPPOutOfOffice {
3844
$EndTime = $EndTime ? $EndTime : (Get-Date $StartTime).AddDays(7)
3945
$CmdParams.StartTime = $StartTime
4046
$CmdParams.EndTime = $EndTime
47+
48+
# Calendar options — only included when explicitly provided
49+
if ($PSBoundParameters.ContainsKey('CreateOOFEvent')) {
50+
$CmdParams.CreateOOFEvent = $CreateOOFEvent
51+
}
52+
if ($PSBoundParameters.ContainsKey('OOFEventSubject')) {
53+
$CmdParams.OOFEventSubject = $OOFEventSubject
54+
}
55+
if ($PSBoundParameters.ContainsKey('AutoDeclineFutureRequestsWhenOOF')) {
56+
$CmdParams.AutoDeclineFutureRequestsWhenOOF = $AutoDeclineFutureRequestsWhenOOF
57+
}
58+
if ($PSBoundParameters.ContainsKey('DeclineEventsForScheduledOOF')) {
59+
$CmdParams.DeclineEventsForScheduledOOF = $DeclineEventsForScheduledOOF
60+
}
61+
if ($PSBoundParameters.ContainsKey('DeclineAllEventsForScheduledOOF')) {
62+
$CmdParams.DeclineAllEventsForScheduledOOF = $DeclineAllEventsForScheduledOOF
63+
}
64+
if ($PSBoundParameters.ContainsKey('DeclineMeetingMessage')) {
65+
$CmdParams.DeclineMeetingMessage = $DeclineMeetingMessage
66+
}
4167
}
4268

4369
$null = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-MailboxAutoReplyConfiguration' -cmdParams $CmdParams -Anchor $UserID

Modules/CIPPCore/Public/Set-CIPPVacationOOO.ps1

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,73 @@ function Set-CIPPVacationOOO {
66
[string]$InternalMessage,
77
[string]$ExternalMessage,
88
[string]$APIName = 'OOO Vacation Mode',
9-
$Headers
9+
$Headers,
10+
$StartTime,
11+
$EndTime,
12+
[bool]$CreateOOFEvent,
13+
[string]$OOFEventSubject,
14+
[bool]$AutoDeclineFutureRequestsWhenOOF,
15+
[bool]$DeclineEventsForScheduledOOF,
16+
[bool]$DeclineAllEventsForScheduledOOF,
17+
[string]$DeclineMeetingMessage
1018
)
1119

1220
$Results = [System.Collections.Generic.List[string]]::new()
1321

1422
foreach ($upn in $Users) {
1523
if ([string]::IsNullOrWhiteSpace($upn)) { continue }
1624
try {
25+
# Use Scheduled when StartTime/EndTime are provided (vacation always has dates),
26+
# otherwise fall back to Enabled for backwards compatibility with in-flight tasks
27+
$State = if ($Action -eq 'Add') {
28+
if ($PSBoundParameters.ContainsKey('StartTime') -and $PSBoundParameters.ContainsKey('EndTime')) { 'Scheduled' } else { 'Enabled' }
29+
} else { 'Disabled' }
30+
1731
$SplatParams = @{
1832
UserID = $upn
1933
TenantFilter = $TenantFilter
20-
State = if ($Action -eq 'Add') { 'Enabled' } else { 'Disabled' }
34+
State = $State
2135
APIName = $APIName
2236
Headers = $Headers
2337
}
24-
# Only pass messages on Add — Remove only disables, preserving any messages
25-
# the user may have updated themselves during vacation
38+
2639
if ($Action -eq 'Add') {
40+
# Pass start/end times when available
41+
if ($PSBoundParameters.ContainsKey('StartTime')) {
42+
$SplatParams.StartTime = $StartTime
43+
}
44+
if ($PSBoundParameters.ContainsKey('EndTime')) {
45+
$SplatParams.EndTime = $EndTime
46+
}
47+
48+
# Only pass messages on Add — Remove only disables, preserving any messages
49+
# the user may have updated themselves during vacation
2750
if (-not [string]::IsNullOrWhiteSpace($InternalMessage)) {
2851
$SplatParams.InternalMessage = $InternalMessage
2952
}
3053
if (-not [string]::IsNullOrWhiteSpace($ExternalMessage)) {
3154
$SplatParams.ExternalMessage = $ExternalMessage
3255
}
56+
57+
# Calendar options — pass through when explicitly provided
58+
if ($PSBoundParameters.ContainsKey('CreateOOFEvent')) {
59+
$SplatParams.CreateOOFEvent = $CreateOOFEvent
60+
}
61+
if ($PSBoundParameters.ContainsKey('OOFEventSubject')) {
62+
$SplatParams.OOFEventSubject = $OOFEventSubject
63+
}
64+
if ($PSBoundParameters.ContainsKey('AutoDeclineFutureRequestsWhenOOF')) {
65+
$SplatParams.AutoDeclineFutureRequestsWhenOOF = $AutoDeclineFutureRequestsWhenOOF
66+
}
67+
if ($PSBoundParameters.ContainsKey('DeclineEventsForScheduledOOF')) {
68+
$SplatParams.DeclineEventsForScheduledOOF = $DeclineEventsForScheduledOOF
69+
}
70+
if ($PSBoundParameters.ContainsKey('DeclineAllEventsForScheduledOOF')) {
71+
$SplatParams.DeclineAllEventsForScheduledOOF = $DeclineAllEventsForScheduledOOF
72+
}
73+
if ($PSBoundParameters.ContainsKey('DeclineMeetingMessage')) {
74+
$SplatParams.DeclineMeetingMessage = $DeclineMeetingMessage
75+
}
3376
}
3477
$result = Set-CIPPOutOfOffice @SplatParams
3578
$Results.Add($result)

0 commit comments

Comments
 (0)