Skip to content

Commit 2f2ec54

Browse files
authored
Merge pull request #151 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents c307491 + e566c5f commit 2f2ec54

File tree

3 files changed

+80
-13
lines changed

3 files changed

+80
-13
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecCustomData.ps1

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,16 @@ function Invoke-ExecCustomData {
360360
try {
361361
$Mappings = Get-CIPPAzDataTableEntity @CustomDataMappingsTable | ForEach-Object {
362362
$Mapping = $_.JSON | ConvertFrom-Json -AsHashtable
363+
364+
Write-Information ($Mapping | ConvertTo-Json -Depth 5)
363365
[PSCustomObject]@{
364-
id = $_.RowKey
365-
tenant = $Mapping.tenantFilter.label
366-
sourceDataset = $Mapping.sourceDataset.label
366+
id = $_.RowKey
367+
tenant = $Mapping.tenantFilter.label
368+
dataset = $Mapping.extensionSyncDataset.label
369+
sourceType = $Mapping.sourceType.label
370+
directoryObject = $Mapping.directoryObjectType.label
371+
syncProperty = $Mapping.extensionSyncProperty.label ?? @($Mapping.extensionSyncDataset.addedFields.select -split ',')
372+
customDataAttribute = $Mapping.customDataAttribute.label
367373
}
368374
}
369375
$Body = @{
@@ -380,16 +386,16 @@ function Invoke-ExecCustomData {
380386
}
381387
}
382388
}
383-
'AddMapping' {
389+
'AddEditMapping' {
384390
try {
385391
$Mapping = $Request.Body.Mapping
386392
if (!$Mapping) {
387393
throw 'Mapping data is missing in the request body.'
388394
}
389-
$id = [Guid]::NewGuid().ToString()
395+
$MappingId = $Request.Body.id ?? [Guid]::NewGuid().ToString()
390396
$Entity = @{
391397
PartitionKey = 'Mapping'
392-
RowKey = $id
398+
RowKey = [string]$MappingId
393399
JSON = [string]($Mapping | ConvertTo-Json -Depth 5 -Compress)
394400
}
395401

@@ -399,7 +405,7 @@ function Invoke-ExecCustomData {
399405
$Body = @{
400406
Results = @{
401407
state = 'success'
402-
resultText = "Mapping with ID '$($id)' added successfully."
408+
resultText = 'Mapping saved successfully.'
403409
}
404410
}
405411
} catch {
@@ -413,6 +419,67 @@ function Invoke-ExecCustomData {
413419
}
414420
}
415421
}
422+
'DeleteMapping' {
423+
try {
424+
$MappingId = $Request.Body.id
425+
if (!$MappingId) {
426+
throw 'Mapping ID is missing in the request body.'
427+
}
428+
429+
# Retrieve the mapping entity
430+
$MappingEntity = Get-CIPPAzDataTableEntity @CustomDataMappingsTable -Filter "PartitionKey eq 'Mapping' and RowKey eq '$MappingId'"
431+
if (!$MappingEntity) {
432+
throw "Mapping with ID '$MappingId' not found."
433+
}
434+
435+
# Delete the mapping entity
436+
Remove-AzDataTableEntity @CustomDataMappingsTable -Entity $MappingEntity
437+
Register-CIPPExtensionScheduledTasks
438+
$Body = @{
439+
Results = @{
440+
state = 'success'
441+
resultText = 'Mapping deleted successfully.'
442+
}
443+
}
444+
} catch {
445+
$Body = @{
446+
Results = @(
447+
@{
448+
state = 'error'
449+
resultText = "Failed to delete mapping: $($_.Exception.Message)"
450+
}
451+
)
452+
}
453+
}
454+
}
455+
'GetMapping' {
456+
try {
457+
$MappingId = $Request.Query.id
458+
if (!$MappingId) {
459+
throw 'Mapping ID is missing in the request query.'
460+
}
461+
462+
# Retrieve the mapping entity
463+
$MappingEntity = Get-CIPPAzDataTableEntity @CustomDataMappingsTable -Filter "PartitionKey eq 'Mapping' and RowKey eq '$MappingId'"
464+
if (!$MappingEntity) {
465+
throw "Mapping with ID '$MappingId' not found."
466+
}
467+
468+
$Mapping = $MappingEntity.JSON | ConvertFrom-Json
469+
$Body = @{
470+
Results = $Mapping
471+
}
472+
} catch {
473+
$Body = @{
474+
Results = @(
475+
@{
476+
state = 'error'
477+
resultText = "Failed to retrieve mapping: $($_.Exception.Message)"
478+
}
479+
)
480+
}
481+
}
482+
}
416483

417484
default {
418485
$Body = @{

Modules/CIPPCore/Public/New-CIPPAlertTemplate.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ function New-CIPPAlertTemplate {
3131
$DataHTML = foreach ($object in $data) {
3232
"<p>For the standard $($object.standardName) in template {{Template Name }} we've detected the following:</p> <li>$($object.message)</li>"
3333
if ($object.object) {
34-
$object.object = $object.object | ConvertFrom-Json
35-
$object.object = $object.object | Select-Object * -ExcludeProperty Etag, PartitionKey, TimeStamp
36-
if ($object.object.compare) {
34+
$StandardObject = $object.object | ConvertFrom-Json
35+
$StandardObject = $newobject | Select-Object * -ExcludeProperty Etag, PartitionKey, TimeStamp
36+
if ($StandardObject.compare) {
3737
'<p>The following differences have been detected:</p>'
38-
($object.object.compare | ConvertTo-Html -Fragment | Out-String).Replace('<table>', ' <table class="table-modern">')
38+
($StandardObject.compare | ConvertTo-Html -Fragment | Out-String).Replace('<table>', ' <table class="table-modern">')
3939
} else {
4040
'<p>This is a table representation of the current settings:</p>'
41-
($object.object | ConvertTo-Html -Fragment -As List | Out-String).Replace('<table>', ' <table class="table-modern">')
41+
($StandardObject | ConvertTo-Html -Fragment -As List | Out-String).Replace('<table>', ' <table class="table-modern">')
4242
}
4343
}
4444

Modules/CIPPCore/Public/New-CippUser.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function New-CIPPUser {
3737
'password' = $password
3838
}
3939
}
40-
if ($userobj.businessPhone) { $bodytoShip | Add-Member -NotePropertyName businessPhones -NotePropertyValue @($UserObj.businessPhone) }
40+
if ($userobj.businessPhones) { $bodytoShip | Add-Member -NotePropertyName businessPhones -NotePropertyValue @($UserObj.businessPhones) }
4141
if ($UserObj.defaultAttributes) {
4242
$UserObj.defaultAttributes | Get-Member -MemberType NoteProperty | ForEach-Object {
4343
Write-Host "Editing user and adding $($_.Name) with value $($UserObj.defaultAttributes.$($_.Name).value)"

0 commit comments

Comments
 (0)