Skip to content

Commit 83eca46

Browse files
authored
Merge pull request #257 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents b794d23 + f871ae2 commit 83eca46

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Application Approval/Invoke-ExecAppDeploymentTemplate.ps1 renamed to Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Application Approval/Invoke-ExecAppApprovalTemplate.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function Invoke-ExecAppDeploymentTemplate {
1+
function Invoke-ExecAppApprovalTemplate {
22
<#
33
.FUNCTIONALITY
44
Entrypoint,AnyTenant
@@ -39,12 +39,12 @@ function Invoke-ExecAppDeploymentTemplate {
3939
# Convert to JSON, preserving the original structure
4040
$templateJson = $templateObject | ConvertTo-Json -Depth 10 -Compress
4141

42-
# Add to templates table with AppDeploymentTemplate partition key
42+
# Add to templates table with AppApprovalTemplate partition key
4343
$Table.Force = $true
4444
Add-CIPPAzDataTableEntity @Table -Entity @{
4545
JSON = [string]$templateJson
4646
RowKey = "$GUID"
47-
PartitionKey = 'AppDeploymentTemplate'
47+
PartitionKey = 'AppApprovalTemplate'
4848
}
4949

5050
# Return a proper array with ONE element containing the TemplateId
@@ -71,7 +71,7 @@ function Invoke-ExecAppDeploymentTemplate {
7171
$TemplateId = $Request.Body.TemplateId
7272

7373
# Get the template to delete
74-
$Template = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'AppDeploymentTemplate' and RowKey eq '$TemplateId'"
74+
$Template = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'AppApprovalTemplate' and RowKey eq '$TemplateId'"
7575

7676
if ($Template) {
7777
$TemplateData = $Template.JSON | ConvertFrom-Json
@@ -98,10 +98,10 @@ function Invoke-ExecAppDeploymentTemplate {
9898
}
9999
'Get' {
100100
# Check if TemplateId is provided to filter results
101-
$filter = "PartitionKey eq 'AppDeploymentTemplate'"
101+
$filter = "PartitionKey eq 'AppApprovalTemplate'"
102102
if ($Request.Query.TemplateId) {
103103
$templateId = $Request.Query.TemplateId
104-
$filter = "PartitionKey eq 'AppDeploymentTemplate' and RowKey eq '$templateId'"
104+
$filter = "PartitionKey eq 'AppApprovalTemplate' and RowKey eq '$templateId'"
105105
Write-LogMessage -headers $Request.Headers -API $APIName -message "Retrieved specific template: $templateId" -Sev 'Info'
106106
}
107107

@@ -125,7 +125,7 @@ function Invoke-ExecAppDeploymentTemplate {
125125
}
126126
default {
127127
# Default action - list all templates
128-
$filter = "PartitionKey eq 'AppDeploymentTemplate'"
128+
$filter = "PartitionKey eq 'AppApprovalTemplate'"
129129

130130
$Templates = Get-CIPPAzDataTableEntity @Table -Filter $filter
131131

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Application Approval/Invoke-ExecAppPermissionTemplate.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ function Invoke-ExecAppPermissionTemplate {
1717
switch ($Action) {
1818
'Save' {
1919
try {
20+
$RowKey = $Request.Body.TemplateId ?? [guid]::NewGuid().ToString()
2021
$Permissions = $Request.Body.Permissions
2122
$Entity = @{
2223
'PartitionKey' = 'Templates'
23-
'RowKey' = [string]($Request.Body.TemplateId ?? [guid]::NewGuid().ToString())
24+
'RowKey' = [string]$RowKey
2425
'TemplateName' = [string]$Request.Body.TemplateName
2526
'Permissions' = [string]($Permissions | ConvertTo-Json -Depth 10 -Compress)
2627
'UpdatedBy' = $User.UserDetails ?? 'CIPP-API'
@@ -30,11 +31,12 @@ function Invoke-ExecAppPermissionTemplate {
3031
'Results' = 'Template Saved'
3132
'Metadata' = @{
3233
'TemplateName' = $Entity.TemplateName
33-
'TemplateId' = $Entity.RowKey
34+
'TemplateId' = $RowKey
3435
}
3536
}
3637
Write-LogMessage -headers $Request.Headers -API 'ExecAppPermissionTemplate' -message "Permissions Saved for template: $($Request.Body.TemplateName)" -Sev 'Info' -LogData $Permissions
3738
} catch {
39+
Write-Information "Failed to save template: $($_.Exception.Message) - $($_.InvocationInfo.PositionMessage)"
3840
$Body = @{
3941
'Results' = $_.Exception.Message
4042
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Application Approval/Invoke-ListAppDeploymentTemplates.ps1 renamed to Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Application Approval/Invoke-ListAppApprovalTemplates.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function Invoke-ListAppDeploymentTemplates {
1+
function Invoke-ListAppApprovalTemplates {
22
<#
33
.FUNCTIONALITY
44
Entrypoint,AnyTenant
@@ -15,8 +15,8 @@ function Invoke-ListAppDeploymentTemplates {
1515
$Table = Get-CIPPTable -TableName 'templates'
1616

1717
try {
18-
# Use the templates table with AppDeploymentTemplate partition key
19-
$filter = "PartitionKey eq 'AppDeploymentTemplate'"
18+
# Use the templates table with AppApprovalTemplate partition key
19+
$filter = "PartitionKey eq 'AppApprovalTemplate'"
2020

2121
$Templates = Get-CIPPAzDataTableEntity @Table -Filter $filter
2222

Modules/CIPPCore/Public/Tools/Import-CommunityTemplate.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ function Import-CommunityTemplate {
4343
$NewJSON.excludedTenants = $excludedTenants
4444
}
4545
}
46+
47+
if ($Template.PartitionKey -eq 'AppApprovalTemplate') {
48+
# Extract the Permission Set name,id,permissions from the JSON and add to the AppPermissions table
49+
$AppPermissionsTable = Get-CIPPTable -TableName 'AppPermissions'
50+
$Permissions = $NewJSON.Permissions
51+
$Entity = @{
52+
'PartitionKey' = 'Templates'
53+
'RowKey' = $NewJSON.PermissionSetId
54+
'TemplateName' = $NewJSON.PermissionSetName
55+
'Permissions' = [string]($Permissions | ConvertTo-Json -Depth 10 -Compress)
56+
'UpdatedBy' = $NewJSON.UpdatedBy ?? $NewJSON.CreatedBy ?? 'System'
57+
}
58+
$null = Add-CIPPAzDataTableEntity @AppPermissionsTable -Entity $Entity -Force
59+
Write-Information 'Added App Permissions to AppPermissions table'
60+
}
61+
4662
# Re-compress JSON and save to table
4763
$NewJSON = [string]($NewJSON | ConvertTo-Json -Depth 100 -Compress)
4864
$Template.JSON = $NewJSON

0 commit comments

Comments
 (0)