Skip to content

Commit a58ce09

Browse files
refactor(sharepoint): streamline tenant selection and deployment process
- Updated backend to require a single tenant for template deployment, enhancing clarity and reducing complexity. - Adjusted frontend to reflect the change from multiple tenant selection to a single tenant context, ensuring the Site/Team Owner picker is appropriately scoped. - Improved logging and messaging to accurately represent the deployment status for the selected tenant. Synced from CyberDrain/CIPP@0aa759a
1 parent 4429b09 commit a58ce09

1 file changed

Lines changed: 19 additions & 26 deletions

File tree

Modules/CIPPHTTP/Public/Entrypoints/HTTP Functions/Teams-Sharepoint/Invoke-ExecSharePointTemplate.ps1

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -136,45 +136,38 @@ function Invoke-ExecSharePointTemplate {
136136
$TemplateData = $Template.JSON | ConvertFrom-Json
137137
if (-not $SiteOwner) { throw 'A site/team owner is required to deploy this template.' }
138138

139-
# Expand AllTenants when selected in the drawer.
140-
$Tenants = foreach ($Tenant in $Request.Body.selectedTenants) {
141-
if ($Tenant.defaultDomainName -eq 'AllTenants') {
142-
(Get-Tenants).defaultDomainName
143-
} else {
144-
$Tenant.defaultDomainName
145-
}
139+
$TenantFilter = $Request.Body.tenantFilter
140+
if ([string]::IsNullOrWhiteSpace($TenantFilter)) {
141+
throw 'A tenant is required to deploy this template.'
146142
}
147-
$Tenants = @($Tenants | Sort-Object -Unique)
148143

149-
# Pre-create a status row per tenant so the frontend can poll live progress
150-
# (GDAP-onboarding style) from the moment the deployment is queued.
151-
$JobId = New-CIPPAsyncDeployment -Names $Tenants -StepTitles @(@($TemplateData.siteTemplates) | ForEach-Object { $_.displayName }) -Source 'SharePointTemplate'
144+
# Pre-create a status row so the frontend can poll live progress from queue time.
145+
$JobId = New-CIPPAsyncDeployment -Names @($TenantFilter) -StepTitles @(@($TemplateData.siteTemplates) | ForEach-Object { $_.displayName }) -Source 'SharePointTemplate'
152146

153147
# Site and Team provisioning is slow (Teams sites can take a minute each), so the
154-
# actual work runs per tenant on the durable queue instead of in this request.
155-
$Queue = New-CippQueueEntry -Name "SharePoint Template - $($TemplateData.templateName)" -TotalTasks $Tenants.Count
156-
$Batch = foreach ($TenantFilter in $Tenants) {
157-
[pscustomobject]@{
158-
FunctionName = 'ExecSharePointTemplateDeploy'
159-
Tenant = $TenantFilter
160-
TemplateId = $TemplateId
161-
SiteOwner = $SiteOwner
162-
DeploymentId = $JobId
163-
QueueId = $Queue.RowKey
164-
}
165-
}
148+
# actual work runs on the durable queue instead of in this request.
149+
$Queue = New-CippQueueEntry -Name "SharePoint Template - $($TemplateData.templateName)" -TotalTasks 1
166150
$InputObject = @{
167151
OrchestratorName = 'SharePointTemplateOrchestrator'
168-
Batch = @($Batch)
152+
Batch = @(
153+
[pscustomobject]@{
154+
FunctionName = 'ExecSharePointTemplateDeploy'
155+
Tenant = $TenantFilter
156+
TemplateId = $TemplateId
157+
SiteOwner = $SiteOwner
158+
DeploymentId = $JobId
159+
QueueId = $Queue.RowKey
160+
}
161+
)
169162
SkipLog = $true
170163
}
171164
$null = Start-CIPPOrchestrator -InputObject $InputObject
172165

173166
$Body = @{
174-
Results = "Deployment of template '$($TemplateData.templateName)' queued for $($Tenants.Count) tenant(s)."
167+
Results = "Deployment of template '$($TemplateData.templateName)' queued for $TenantFilter."
175168
DeploymentId = $JobId
176169
}
177-
Write-LogMessage -headers $Headers -API $APIName -message "Queued SharePoint template deployment '$($TemplateData.templateName)' for $($Tenants.Count) tenant(s)" -Sev 'Info'
170+
Write-LogMessage -headers $Headers -API $APIName -message "Queued SharePoint template deployment '$($TemplateData.templateName)' for $TenantFilter" -Sev 'Info'
178171
} catch {
179172
$Body = @{ Results = "Failed to queue template deployment: $($_.Exception.Message)" }
180173
$StatusCode = [HttpStatusCode]::BadRequest

0 commit comments

Comments
 (0)