Skip to content

Commit

Permalink
Merge pull request #76 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
[pull] dev from KelvinTegelaar:dev
  • Loading branch information
pull[bot] authored Feb 12, 2025
2 parents d57c0db + bc714f4 commit 384b28d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,29 @@ function Invoke-ExecCommunityRepo {

$Action = $Request.Body.Action
$Id = $Request.Body.Id
if ($Request.Body.Id) {
$Filter = "PartitionKey eq 'CommunityRepos' and RowKey eq '$($Id)'"
} elseif ($Request.Body.FullName) {
$Filter = "PartitionKey eq 'CommunityRepos' and FullName eq '$($Request.Body.FullName)'"
} else {
$Results = @(
@{
resultText = 'Id or FullName required'
state = 'error'
}
)
$Body = @{
Results = $Results
}

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $Body
})
return
}

$Table = Get-CIPPTable -TableName CommunityRepos
$Filter = "PartitionKey eq 'CommunityRepos' and RowKey eq '$($Id)'"
$RepoEntity = Get-CIPPAzDataTableEntity @Table -Filter $Filter

switch ($Action) {
Expand Down Expand Up @@ -88,12 +108,21 @@ function Invoke-ExecCommunityRepo {
$GUID = $Request.Body.GUID
$TemplateTable = Get-CIPPTable -TableName templates
$TemplateEntity = Get-CIPPAzDataTableEntity @TemplateTable -Filter "RowKey eq '$($GUID)'"
$Branch = $RepoEntity.UploadBranch ?? $RepoEntity.DefaultBranch
if ($TemplateEntity) {
$Template = $TemplateEntity.JSON | ConvertFrom-Json
$DisplayName = $Template.Displayname ?? $Template.templateName ?? $Template.name
if ($Template.tenantFilter) {
$Template.tenantFilter = @(@{ label = 'Template Tenant'; value = 'Template Tenant' })
}
if ($Template.excludedTenants) {
$Template.excludedTenants = @()
}
$TemplateEntity.JSON = $Template | ConvertTo-Json -Compress -Depth 100

$Basename = $DisplayName -replace '\s', '_' -replace '[^\w\d_]', ''
$Path = '{0}/{1}.json' -f $TemplateEntity.PartitionKey, $Basename
$Results = Push-GitHubContent -FullName $Request.Body.FullName -Path $Path -Content ($TemplateEntity | ConvertTo-Json -Compress) -Message $Request.Body.Message
$Results = Push-GitHubContent -FullName $Request.Body.FullName -Path $Path -Content ($TemplateEntity | ConvertTo-Json -Compress) -Message $Request.Body.Message -Branch $Branch

$Results = @{
resultText = "Template '$($DisplayName)' uploaded"
Expand All @@ -106,6 +135,27 @@ function Invoke-ExecCommunityRepo {
}
}
}
'SetBranch' {
if (!$RepoEntity) {
$Results = @{
resultText = "Repository $($Id) not found"
state = 'error'
}
} else {
$Branch = $Request.Body.Branch
if (!$RepoEntity.UploadBranch) {
$RepoEntity | Add-Member -NotePropertyName 'UploadBranch' -NotePropertyValue $Branch
} else {
$RepoEntity.UploadBranch = $Branch
}
$null = Add-CIPPAzDataTableEntity @Table -Entity $RepoEntity -Force

$Results = @{
resultText = "Branch set to $Branch"
state = 'success'
}
}
}
'ImportTemplate' {
$Path = $Request.Body.Path
$FullName = $Request.Body.FullName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function Invoke-ListCommunityRepos {
Visibility = $Repo.Visibility
WriteAccess = $Repo.WriteAccess
DefaultBranch = $Repo.DefaultBranch
UploadBranch = $Repo.DefaultBranch
Permissions = [string]($Repo.RepoPermissions | ConvertTo-Json)
}
Add-CIPPAzDataTableEntity @Table -Entity $Entity
Expand All @@ -63,6 +64,7 @@ function Invoke-ListCommunityRepos {
Visibility = $_.Visibility
WriteAccess = $_.WriteAccess
DefaultBranch = $_.DefaultBranch
UploadBranch = $_.UploadBranch ?? $_.DefaultBranch
RepoPermissions = $_.Permissions | ConvertFrom-Json
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Function Invoke-ListGraphExplorerPresets {

$APIName = $Request.Params.CIPPEndpoint
Write-LogMessage -headers $Request.Headers -API $APINAME -message 'Accessed this API' -Sev 'Debug'
$Username = ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Request.Headers)) | ConvertFrom-Json).userDetails
$Username = $Request.Headers['x-ms-client-principal-name']

try {
$Table = Get-CIPPTable -TableName 'GraphPresets'
Expand Down

0 comments on commit 384b28d

Please sign in to comment.