Skip to content

Commit

Permalink
Merge pull request #1233 from kris6673/more-dropdowns
Browse files Browse the repository at this point in the history
FIX: Dropdowns and modernization
  • Loading branch information
KelvinTegelaar authored Jan 17, 2025
2 parents 0f4549a + 49f1db1 commit 3224925
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ Function Invoke-ExecSetSharePointMember {
[CmdletBinding()]
param($Request, $TriggerMetadata)


$APIName = $TriggerMetadata.FunctionName
$ExecutingUser = $request.headers.'x-ms-client-principal'
Write-LogMessage -user $ExecutingUser -API $APINAME -message 'Accessed this API' -Sev 'Debug'
$TenantFilter = $Request.body.tenantFilter



if ($Request.body.SharePointType -eq 'Group') {
$GroupId = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/groups?`$filter=mail eq '$($Request.Body.GroupID)' or proxyAddresses/any(x:endsWith(x,'$($Request.Body.GroupID)'))&`$count=true" -ComplexFilter -tenantid $Request.Body.TenantFilter).id
$GroupId = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/groups?`$filter=mail eq '$($Request.Body.GroupID)' or proxyAddresses/any(x:endsWith(x,'$($Request.Body.GroupID)'))&`$count=true" -ComplexFilter -tenantid $TenantFilter).id
if ($Request.body.Add -eq $true) {
$Results = Add-CIPPGroupMember -GroupType 'Team' -GroupID $GroupID -Member $Request.Body.user.value -TenantFilter $Request.Body.TenantFilter -ExecutingUser $request.headers.'x-ms-client-principal'
$Results = Add-CIPPGroupMember -GroupType 'Team' -GroupID $GroupID -Member $Request.Body.user.value -TenantFilter $TenantFilter -ExecutingUser $ExecutingUser
} else {
$UserID = (New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/users/$($Request.Body.user.value)" -tenantid $Request.Body.TenantFilter).id
$Results = Remove-CIPPGroupMember -GroupType 'Team' -GroupID $GroupID -Member $UserID -TenantFilter $Request.Body.TenantFilter -ExecutingUser $request.headers.'x-ms-client-principal'
$UserID = (New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/users/$($Request.Body.user.value)" -tenantid $TenantFilter).id
$Results = Remove-CIPPGroupMember -GroupType 'Team' -GroupID $GroupID -Member $UserID -TenantFilter $TenantFilter -ExecutingUser $ExecutingUser
}
} else {
$Results = 'This type of SharePoint site is not supported.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,36 @@ Function Invoke-ExecSharePointPerms {
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
$tenantFilter = $Request.Body.TenantFilter
$tenantFilter = $Request.Body.tenantFilter
$ExecutingUser = $Request.Headers.'x-ms-client-principal'

Write-LogMessage -user $ExecutingUser -API $APIName -message 'Accessed this API' -Sev Debug

# The UPN or ID of the users OneDrive we are changing permissions on
$UserId = $Request.body.UPN
# The UPN of the user we are adding or removing permissions for
$OnedriveAccessUser = $Request.body.onedriveAccessUser.value

try {
$State = Set-CIPPSharePointPerms -tenantFilter $tenantFilter -userid $request.body.UPN -OnedriveAccessUser $request.body.input -ExecutingUser $ExecutingUser -APIName $APIName -RemovePermission $request.body.RemovePermission -URL $Request.Body.URL

$State = Set-CIPPSharePointPerms -tenantFilter $tenantFilter `
-UserId $UserId `
-OnedriveAccessUser $OnedriveAccessUser `
-ExecutingUser $ExecutingUser `
-APIName $APIName `
-RemovePermission $Request.body.RemovePermission `
-URL $Request.Body.URL
$Results = [pscustomobject]@{'Results' = "$State" }
$StatusCode = [HttpStatusCode]::OK
} catch {
$Results = [pscustomobject]@{'Results' = "Failed. $($_.Exception.Message)" }
$ErrorMessage = Get-CippException -Exception $_
$Results = [pscustomobject]@{'Results' = "Failed. $($ErrorMessage.NormalizedError)" }
$StatusCode = [HttpStatusCode]::BadRequest
}

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
StatusCode = $StatusCode
Body = $Results
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,30 @@ Function Invoke-ExecTeamsVoicePhoneNumberAssignment {
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
$ExecutingUser = $Request.headers.'x-ms-client-principal'
Write-LogMessage -user $ExecutingUser -API $APINAME -message 'Accessed this API' -Sev 'Debug'
$Identity = $Request.Body.input.value

$tenantFilter = $Request.Body.TenantFilter
try {
if ($Request.Body.locationOnly) {
$null = New-TeamsRequest -TenantFilter $TenantFilter -Cmdlet 'Set-CsPhoneNumberAssignment' -CmdParams @{LocationId = $Request.Body.input; PhoneNumber = $Request.Body.PhoneNumber; ErrorAction = 'stop'}
$Results = [pscustomobject]@{'Results' = "Successfully assigned emergency location to $($Request.Body.PhoneNumber)"}
$null = New-TeamsRequest -TenantFilter $TenantFilter -Cmdlet 'Set-CsPhoneNumberAssignment' -CmdParams @{LocationId = $Identity; PhoneNumber = $Request.Body.PhoneNumber; ErrorAction = 'stop' }
$Results = [pscustomobject]@{'Results' = "Successfully assigned emergency location to $($Request.Body.PhoneNumber)" }
} else {
$null = New-TeamsRequest -TenantFilter $TenantFilter -Cmdlet 'Set-CsPhoneNumberAssignment' -CmdParams @{Identity = $Request.Body.input; PhoneNumber = $Request.Body.PhoneNumber; PhoneNumberType = $Request.Body.PhoneNumberType; ErrorAction = 'stop'}
$Results = [pscustomobject]@{'Results' = "Successfully assigned $($Request.Body.PhoneNumber) to $($Request.Body.input)"}
$null = New-TeamsRequest -TenantFilter $TenantFilter -Cmdlet 'Set-CsPhoneNumberAssignment' -CmdParams @{Identity = $Identity; PhoneNumber = $Request.Body.PhoneNumber; PhoneNumberType = $Request.Body.PhoneNumberType; ErrorAction = 'stop' }
$Results = [pscustomobject]@{'Results' = "Successfully assigned $($Request.Body.PhoneNumber) to $($Identity)" }
}
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($TenantFilter) -message $($Results.Results) -Sev 'Info'
Write-LogMessage -user $ExecutingUser -API $APINAME -tenant $($TenantFilter) -message $($Results.Results) -Sev Info
$StatusCode = [HttpStatusCode]::OK
} catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
$Results = [pscustomobject]@{'Results' = $ErrorMessage}
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -tenant $($TenantFilter) -message $($Results.Results) -Sev 'Error'
$ErrorMessage = Get-CippException -Exception $_
$Results = [pscustomobject]@{'Results' = $ErrorMessage.NormalizedError }
Write-LogMessage -user $ExecutingUser -API $APINAME -tenant $($TenantFilter) -message $($Results.Results) -Sev Error -LogData $ErrorMessage
$StatusCode = [HttpStatusCode]::Forbidden
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
StatusCode = $StatusCode
Body = $Results
})
}
15 changes: 8 additions & 7 deletions Modules/CIPPCore/Public/Set-CIPPSharePointPerms.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function Set-CIPPSharePointPerms {
[CmdletBinding()]
param (
$userid,
$OnedriveAccessUser,
$UserId, # The UPN or ID of the users OneDrive we are changing permissions on
$OnedriveAccessUser, # The UPN of the user we are adding or removing permissions for
$TenantFilter,
$APIName = 'Manage SharePoint Owner',
$RemovePermission,
Expand All @@ -17,6 +17,7 @@ function Set-CIPPSharePointPerms {

try {
if (!$URL) {
Write-Information 'No URL provided, getting URL from Graph'
$URL = (New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/users/$($UserId)/Drives" -asapp $true -tenantid $TenantFilter).WebUrl
}
$tenantName = (New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/sites/root' -asApp $true -tenantid $TenantFilter).id.Split('.')[0]
Expand All @@ -39,19 +40,19 @@ function Set-CIPPSharePointPerms {
</Request>
"@
$request = New-GraphPostRequest -scope "$AdminURL/.default" -tenantid $TenantFilter -Uri "$AdminURL/_vti_bin/client.svc/ProcessQuery" -Type POST -Body $XML -ContentType 'text/xml'
Write-Host $($request)
# Write-Host $($request)
if (!$request.ErrorInfo.ErrorMessage) {
$Message = "$($OnedriveAccessUser) has been $($RemovePermission ? 'removed from' : 'given') access to $URL"
Write-LogMessage -user $ExecutingUser -API $APIName -message $Message -Sev 'Info' -tenant $TenantFilter
Write-LogMessage -user $ExecutingUser -API $APIName -message $Message -Sev Info -tenant $TenantFilter
return $Message
} else {
$message = "Failed to change access: $($request.ErrorInfo.ErrorMessage)"
Write-LogMessage -user $ExecutingUser -API $APIName -message $message -Sev 'Info' -tenant $TenantFilter
return $message
Write-LogMessage -user $ExecutingUser -API $APIName -message $message -Sev Error -tenant $TenantFilter
throw $Message
}
} catch {
$ErrorMessage = Get-CippException -Exception $_
Write-LogMessage -user $ExecutingUser -API $APIName -message "Could not add new owner to $($OnedriveAccessUser) on $URL. Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
Write-LogMessage -user $ExecutingUser -API $APIName -message "Could not add new owner to $($OnedriveAccessUser) on $URL. Error: $($ErrorMessage.NormalizedError)" -Sev Error -tenant $TenantFilter -LogData $ErrorMessage
return "Could not add owner for $($URL). Error: $($ErrorMessage.NormalizedError)"
}
}

0 comments on commit 3224925

Please sign in to comment.