Skip to content

Commit 98d4f07

Browse files
authored
Merge pull request #476 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 4eea87a + b3b7b24 commit 98d4f07

File tree

4 files changed

+91
-4
lines changed

4 files changed

+91
-4
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
function Invoke-ListCustomDataMappings {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
.ROLE
6+
CIPP.Core.Read
7+
#>
8+
[CmdletBinding()]
9+
param($Request, $TriggerMetadata)
10+
11+
$CustomDataMappingsTable = Get-CippTable -TableName 'CustomDataMappings'
12+
$TenantFilter = $Request.Query.tenantFilter
13+
$SourceTypeFilter = $Request.Query.sourceType
14+
$DirectoryObjectFilter = $Request.Query.directoryObject
15+
16+
Write-Information "Listing custom data mappings with filters - sourceType: $SourceTypeFilter, directoryObject: $DirectoryObjectFilter, tenant: $TenantFilter"
17+
18+
try {
19+
$Mappings = Get-CIPPAzDataTableEntity @CustomDataMappingsTable | ForEach-Object {
20+
$Mapping = $_.JSON | ConvertFrom-Json -AsHashtable
21+
22+
# Filter by tenant
23+
$TenantList = Expand-CIPPTenantGroups -TenantFilter $Mapping.tenantFilter
24+
if ($TenantFilter -and ($TenantList -contains $TenantFilter -or $TenantList -eq 'AllTenants')) {
25+
return
26+
}
27+
28+
$MappingObject = [PSCustomObject]@{
29+
id = $_.RowKey
30+
tenant = $Mapping.tenantFilter.label
31+
dataset = $Mapping.extensionSyncDataset.label
32+
sourceType = $Mapping.sourceType.label
33+
directoryObject = $Mapping.directoryObjectType.label
34+
syncProperty = $Mapping.extensionSyncProperty.label ?? @($Mapping.extensionSyncDataset.addedFields.select -split ',')
35+
customDataAttribute = $Mapping.customDataAttribute
36+
manualEntryFieldLabel = $Mapping.manualEntryFieldLabel
37+
}
38+
39+
# Apply safe filtering
40+
$Include = $true
41+
if ($SourceTypeFilter -and $MappingObject.sourceType -ne $SourceTypeFilter) {
42+
$Include = $false
43+
}
44+
if ($DirectoryObjectFilter -and $MappingObject.directoryObject -ne $DirectoryObjectFilter) {
45+
$Include = $false
46+
}
47+
48+
if ($Include) {
49+
return $MappingObject
50+
}
51+
} | Where-Object { $_ -ne $null }
52+
53+
$Body = @{
54+
Results = @($Mappings)
55+
}
56+
} catch {
57+
$Body = @{
58+
Results = @(
59+
@{
60+
state = 'error'
61+
resultText = "Failed to retrieve mappings: $($_.Exception.Message)"
62+
}
63+
)
64+
}
65+
}
66+
67+
return ([HttpResponseContext]@{
68+
StatusCode = [HttpStatusCode]::OK
69+
Body = $Body
70+
})
71+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,10 @@ function Invoke-ExecCustomData {
365365
[PSCustomObject]@{
366366
id = $_.RowKey
367367
tenant = $Mapping.tenantFilter.label
368-
dataset = $Mapping.extensionSyncDataset.label
368+
dataset = $Mapping.extensionSyncDataset.label ?? 'N/A'
369369
sourceType = $Mapping.sourceType.label
370370
directoryObject = $Mapping.directoryObjectType.label
371-
syncProperty = $Mapping.extensionSyncProperty.label ?? @($Mapping.extensionSyncDataset.addedFields.select -split ',')
371+
syncProperty = $Mapping.extensionSyncProperty.label ?? ($Mapping.extensionSyncDataset ? @($Mapping.extensionSyncDataset.addedFields.select -split ',') : 'N/A')
372372
customDataAttribute = $Mapping.customDataAttribute.label
373373
}
374374
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-EditUser.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,20 @@ function Invoke-EditUser {
6161
}
6262
if ($UserObj.defaultAttributes) {
6363
$UserObj.defaultAttributes | Get-Member -MemberType NoteProperty | ForEach-Object {
64-
Write-Host "Editing user and adding $($_.Name) with value $($UserObj.defaultAttributes.$($_.Name).value)"
6564
if (-not [string]::IsNullOrWhiteSpace($UserObj.defaultAttributes.$($_.Name).value)) {
66-
Write-Host 'adding body to ship'
65+
Write-Host "Editing user and adding $($_.Name) with value $($UserObj.defaultAttributes.$($_.Name).value)"
6766
$BodyToShip | Add-Member -NotePropertyName $_.Name -NotePropertyValue $UserObj.defaultAttributes.$($_.Name).value -Force
6867
}
6968
}
7069
}
70+
if ($UserObj.customData) {
71+
$UserObj.customData | Get-Member -MemberType NoteProperty | ForEach-Object {
72+
if (-not [string]::IsNullOrWhiteSpace($UserObj.customData.$($_.Name))) {
73+
Write-Host "Editing user and adding custom data $($_.Name) with value $($UserObj.customData.$($_.Name))"
74+
$BodyToShip | Add-Member -NotePropertyName $_.Name -NotePropertyValue $UserObj.customData.$($_.Name) -Force
75+
}
76+
}
77+
}
7178
$bodyToShip = ConvertTo-Json -Depth 10 -InputObject $BodyToship -Compress
7279
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$($UserObj.id)" -tenantid $UserObj.tenantFilter -type PATCH -body $BodyToship -verbose
7380
$Results.Add( 'Success. The user has been edited.' )

Modules/CIPPCore/Public/New-CippUser.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ function New-CIPPUser {
4949
}
5050
}
5151
}
52+
if ($UserObj.customData) {
53+
$UserObj.customData | Get-Member -MemberType NoteProperty | ForEach-Object {
54+
Write-Host "Editing user and adding custom data $($_.Name) with value $($UserObj.customData.$($_.Name))"
55+
if (-not [string]::IsNullOrWhiteSpace($UserObj.customData.$($_.Name))) {
56+
Write-Host 'adding custom data to body'
57+
$BodyToShip | Add-Member -NotePropertyName $_.Name -NotePropertyValue $UserObj.customData.$($_.Name) -Force
58+
}
59+
}
60+
}
5261
$bodyToShip = ConvertTo-Json -Depth 10 -InputObject $BodyToship -Compress
5362
Write-Host "Shipping: $bodyToShip"
5463
$GraphRequest = New-GraphPostRequest -uri 'https://graph.microsoft.com/beta/users' -tenantId $UserObj.tenantFilter -type POST -body $BodyToship -verbose

0 commit comments

Comments
 (0)