@@ -12,51 +12,66 @@ function Invoke-ExecAddMultiTenantApp {
12
12
$APIName = $Request.Params.CIPPEndpoint
13
13
$Headers = $Request.Headers
14
14
Write-LogMessage - headers $Headers - API $APIName - message ' Accessed this API' - Sev ' Debug'
15
- $DelegateResources = $request.body.permissions | Where-Object - Property origin -EQ ' Delegated' | ForEach-Object { @ { id = $_.id ; type = ' Scope' } }
16
- $DelegateResourceAccess = @ { ResourceAppId = ' 00000003-0000-0000-c000-000000000000' ; resourceAccess = $DelegateResources }
17
- $ApplicationResources = $request.body.permissions | Where-Object - Property origin -EQ ' Application' | ForEach-Object { @ { id = $_.id ; type = ' Role' } }
18
- $ApplicationResourceAccess = @ { ResourceAppId = ' 00000003-0000-0000-c000-000000000000' ; resourceAccess = $ApplicationResources }
19
15
20
- $Results = try {
21
- if ($Request.Body.CopyPermissions -eq $true ) {
22
- $Command = ' ExecApplicationCopy'
23
- } else {
24
- $Command = ' ExecAddMultiTenantApp'
25
- }
26
- if (' allTenants' -in $Request.Body.tenantFilter.value ) {
27
- $TenantFilter = (Get-Tenants ).defaultDomainName
28
- } else {
29
- $TenantFilter = $Request.Body.tenantFilter.value
30
- }
16
+ if ($Request.Body.configMode -eq ' manual' ) {
17
+ $DelegateResources = $request.body.permissions | Where-Object - Property origin -EQ ' Delegated' | ForEach-Object { @ { id = $_.id ; type = ' Scope' } }
18
+ $DelegateResourceAccess = @ { ResourceAppId = ' 00000003-0000-0000-c000-000000000000' ; resourceAccess = $DelegateResources }
19
+ $ApplicationResources = $request.body.permissions | Where-Object - Property origin -EQ ' Application' | ForEach-Object { @ { id = $_.id ; type = ' Role' } }
20
+ $ApplicationResourceAccess = @ { ResourceAppId = ' 00000003-0000-0000-c000-000000000000' ; resourceAccess = $ApplicationResources }
21
+
22
+ $Results = try {
23
+ if ($Request.Body.CopyPermissions -eq $true ) {
24
+ $Command = ' ExecApplicationCopy'
25
+ } else {
26
+ $Command = ' ExecAddMultiTenantApp'
27
+ }
28
+ if (' allTenants' -in $Request.Body.tenantFilter.value ) {
29
+ $TenantFilter = (Get-Tenants ).defaultDomainName
30
+ } else {
31
+ $TenantFilter = $Request.Body.tenantFilter.value
32
+ }
31
33
32
- $TenantCount = ($TenantFilter | Measure-Object ).Count
33
- $Queue = New-CippQueueEntry - Name ' Application Approval' - TotalTasks $TenantCount
34
- foreach ($Tenant in $TenantFilter ) {
35
- try {
36
- $InputObject = @ {
37
- OrchestratorName = ' ExecMultiTenantAppOrchestrator'
38
- Batch = @ ([pscustomobject ]@ {
39
- FunctionName = $Command
40
- Tenant = $tenant
41
- AppId = $Request.Body.AppId
42
- applicationResourceAccess = $ApplicationResourceAccess
43
- delegateResourceAccess = $DelegateResourceAccess
44
- QueueId = $Queue.RowKey
45
- })
46
- SkipLog = $true
34
+ $TenantCount = ($TenantFilter | Measure-Object ).Count
35
+ $Queue = New-CippQueueEntry - Name ' Application Approval' - TotalTasks $TenantCount
36
+ foreach ($Tenant in $TenantFilter ) {
37
+ try {
38
+ $InputObject = @ {
39
+ OrchestratorName = ' ExecMultiTenantAppOrchestrator'
40
+ Batch = @ ([pscustomobject ]@ {
41
+ FunctionName = $Command
42
+ Tenant = $tenant
43
+ AppId = $Request.Body.AppId
44
+ applicationResourceAccess = $ApplicationResourceAccess
45
+ delegateResourceAccess = $DelegateResourceAccess
46
+ QueueId = $Queue.RowKey
47
+ })
48
+ SkipLog = $true
49
+ }
50
+ $null = Start-NewOrchestration - FunctionName ' CIPPOrchestrator' - InputObject ($InputObject | ConvertTo-Json - Depth 5 - Compress)
51
+ " Queued application to tenant $Tenant . See the logbook for deployment details"
52
+ } catch {
53
+ " Error queuing application to tenant $Tenant - $ ( $_.Exception.Message ) "
47
54
}
48
- $null = Start-NewOrchestration - FunctionName ' CIPPOrchestrator' - InputObject ($InputObject | ConvertTo-Json - Depth 5 - Compress)
49
- " Queued application to tenant $Tenant . See the logbook for deployment details"
50
- } catch {
51
- " Error queuing application to tenant $Tenant - $ ( $_.Exception.Message ) "
52
55
}
56
+ $StatusCode = [HttpStatusCode ]::OK
57
+ } catch {
58
+ $ErrorMsg = Get-NormalizedError - message $ ($_.Exception.Message )
59
+ $Results = " Function Error: $ErrorMsg "
60
+ $StatusCode = [HttpStatusCode ]::BadRequest
53
61
}
62
+ } elseif ($Request.Body.configMode -eq ' template' ) {
63
+ Write-Information ' Application Approval - Template Mode'
64
+ Write-Information ($Request.Body | ConvertTo-Json - Depth 5 )
65
+
66
+
67
+
68
+
69
+
70
+
71
+ $Results = ' Deploying {0} to {1}' -f $Request.Body.selectedTemplate.label , ($Request.Body.tenantFilter.label -join ' , ' )
54
72
$StatusCode = [HttpStatusCode ]::OK
55
- } catch {
56
- $ErrorMsg = Get-NormalizedError - message $ ($_.Exception.Message )
57
- $Results = " Function Error: $ErrorMsg "
58
- $StatusCode = [HttpStatusCode ]::BadRequest
59
73
}
74
+
60
75
# Associate values to output bindings by calling 'Push-OutputBinding'.
61
76
Push-OutputBinding - Name Response - Value ([HttpResponseContext ]@ {
62
77
StatusCode = $StatusCode
0 commit comments