Skip to content

Commit

Permalink
Merge pull request #889 from ykuijs/Rollup
Browse files Browse the repository at this point in the history
Bugfix rollup
  • Loading branch information
ykuijs committed Sep 25, 2018
2 parents 47263b9 + b19f9be commit f2a65c5
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 33 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,8 +2,19 @@

## Unreleased

* Changes to SharePointDsc
* Updated test helpers to force a reload of the resource every time you run a test
* SPSearchContentSource
* Fixed issue with numerical Content Sources name;
* Fixed issue with numerical Content Sources name
* SPSearchTopology
* Updated Readme.md to remove some incorrect information
* SPSite
* Added the possibility for creating the default site groups
* SPUserProfileServiceApp
* Fixed issue which was introduced in v2.5 where the service application proxy
was not created.
* Updated resource to grant the InstallAccount permissions to a newly created service
application to prevent issues in the Get method.
* SPWebAppSuiteBar
* Fixed incorrect test method that resulted in this resource to never apply changes.
* SPWebAppPropertyBag
Expand Down
Expand Up @@ -7,10 +7,7 @@ current farm. It allows the configuration to dictate the search topology roles
that the current server should be running. Any combination of roles can be
specified and the topology will be upaded to reflect the current servers new
roles. If this is the first server to apply topology to a farm, then at least
one search index must be provided. To this end, the FirstPartitionIndex,
FirstPartitionDirectory and FirstPartitionServers allow configuring where the
first index partition will belong. This will behave the same as the
SPSearchIndexPartition resource.
one search index must be provided.

You only need to run the topology resource on a single server in the farm.
It will enable the components on each server in the farm, as specified in
Expand Down
84 changes: 80 additions & 4 deletions Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1
Expand Up @@ -56,6 +56,10 @@ function Get-TargetResource
[System.String]
$Template,

[Parameter()]
[System.Boolean]
$CreateDefaultGroups = $true,

[Parameter()]
[System.Management.Automation.PSCredential]
$InstallAccount
Expand All @@ -73,7 +77,22 @@ function Get-TargetResource

if ($null -eq $site)
{
return $null
return @{
Url = $params.Url
OwnerAlias = $null
CompatibilityLevel = $null
ContentDatabase = $null
Description = $null
HostHeaderWebApplication = $null
Language = $null
Name = $null
OwnerEmail = $null
QuotaTemplate = $null
SecondaryEmail = $null
SecondaryOwnerAlias = $null
Template = $null
CreateDefaultGroups = $null
}
}
else
{
Expand Down Expand Up @@ -122,6 +141,14 @@ function Get-TargetResource
$_.QuotaID -eq $site.Quota.QuotaID
}).Name

$CreateDefaultGroups = $true
if ($null -eq $site.RootWeb.AssociatedVisitorGroup -and
$null -eq $site.RootWeb.AssociatedMemberGroup -and
$null -eq $site.RootWeb.AssociatedOwnerGroup)
{
$CreateDefaultGroups = $false
}

return @{
Url = $site.Url
OwnerAlias = $owner
Expand All @@ -136,6 +163,7 @@ function Get-TargetResource
SecondaryEmail = $site.SecondaryContact.Email
SecondaryOwnerAlias = $secondaryOwner
Template = "$($site.RootWeb.WebTemplate)#$($site.RootWeb.Configuration)"
CreateDefaultGroups = $CreateDefaultGroups
InstallAccount = $params.InstallAccount
}
}
Expand Down Expand Up @@ -200,13 +228,22 @@ function Set-TargetResource
[System.String]
$Template,

[Parameter()]
[System.Boolean]
$CreateDefaultGroups = $true,

[Parameter()]
[System.Management.Automation.PSCredential]
$InstallAccount
)

Write-Verbose -Message "Setting site collection $Url"

if ($PSBoundParameters.ContainsKey("CreateDefaultGroups") -eq $false)
{
$PSBoundParameters.CreateDefaultGroups = $true
}

$CurrentValues = Get-TargetResource @PSBoundParameters

$result = Invoke-SPDSCCommand -Credential $InstallAccount `
Expand All @@ -217,11 +254,26 @@ function Set-TargetResource

$params.Remove("InstallAccount") | Out-Null

$CreateDefaultGroups = $params.CreateDefaultGroups
$params.Remove("CreateDefaultGroups") | Out-Null

$site = Get-SPSite -Identity $params.Url -ErrorAction SilentlyContinue

if ($null -eq $site)
{
New-SPSite @params | Out-Null
$site = New-SPSite @params

if ($CreateDefaultGroups -eq $true)
{
$site.RootWeb.CreateDefaultAssociatedGroups($params.OwnerAlias,
$params.SecondaryOwnerAlias,
$null)
}
else
{
Write-Verbose -Message ("CreateDefaultGroups set to false. The default " + `
"SharePoint groups will not be created")
}
}
else
{
Expand Down Expand Up @@ -258,6 +310,22 @@ function Set-TargetResource
Write-Verbose -Message "Updating existing site collection"
Set-SPSite @newParams
}

if ($CurrentValues.CreateDefaultGroups -eq $false)
{
if ($CreateDefaultGroups -eq $true)
{
$site = Get-SPSite -Identity $params.Url -ErrorAction SilentlyContinue
$site.RootWeb.CreateDefaultAssociatedGroups($params.OwnerAlias,
$params.SecondaryOwnerAlias,
$null)
}
else
{
Write-Verbose -Message ("CreateDefaultGroups set to false. The default " + `
"SharePoint groups will not be created")
}
}
}
}
}
Expand Down Expand Up @@ -320,6 +388,10 @@ function Test-TargetResource
[System.String]
$Template,

[Parameter()]
[System.Boolean]
$CreateDefaultGroups = $true,

[Parameter()]
[System.Management.Automation.PSCredential]
$InstallAccount
Expand All @@ -329,10 +401,14 @@ function Test-TargetResource

$CurrentValues = Get-TargetResource @PSBoundParameters

if ($null -eq $CurrentValues)
if ($CreateDefaultGroups -eq $true)
{
return $false
if ($CurrentValues.CreateDefaultGroups -ne $true)
{
return $false
}
}

return Test-SPDscParameterState -CurrentValues $CurrentValues `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @("Url",
Expand Down
Expand Up @@ -14,6 +14,7 @@ class MSFT_SPSite : OMI_BaseResource
[Write, Description("The secondary site collection admin email address")] string SecondaryEmail;
[Write, Description("The secondary site collection admin username")] string SecondaryOwnerAlias;
[Write, Description("The template to apply to the site collection")] string Template;
[Write, Description("Create the default site groups in the site collection")] boolean CreateDefaultGroups;
[Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount;
};

4 changes: 4 additions & 0 deletions Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md
Expand Up @@ -17,3 +17,7 @@ IIS site and prevent the site from listening for the URL of the Host Header
Site Collection.
If you want to change the IIS website binding settings, please use the xWebsite
resource in the xWebAdministration module.

NOTE2:
The CreateDefaultGroups parameter is only used for creating default site
groups. It will not remove or change the default groups if they already exist.
Expand Up @@ -286,8 +286,8 @@ function Set-TargetResource
if ($Ensure -eq "Present")
{
$farmAccount = Invoke-SPDSCCommand -Credential $InstallAccount `
-Arguments $PSBoundParameters `
-ScriptBlock {
-Arguments $PSBoundParameters `
-ScriptBlock {
return Get-SPDscFarmAccount
}

Expand All @@ -302,6 +302,7 @@ function Set-TargetResource
"Account. Make sure the specified InstallAccount isn't the Farm Account " + `
"and try again")
}
$setupAccount = $InstallAccount.UserName
}
else
{
Expand All @@ -316,6 +317,7 @@ function Set-TargetResource
"Account. Make sure the specified PSDSCRunAsCredential isn't the " + `
"Farm Account and try again")
}
$setupAccount = $localaccount
}
}
}
Expand All @@ -342,9 +344,10 @@ function Set-TargetResource
}

$null = Invoke-SPDSCCommand -Credential $FarmAccount `
-Arguments $PSBoundParameters `
-Arguments @($PSBoundParameters, $setupAccount) `
-ScriptBlock {
$params = $args[0]
$setupAccount = $args[1]

$updateEnableNetBIOS = $false
if ($params.ContainsKey("EnableNetBIOS"))
Expand Down Expand Up @@ -402,14 +405,24 @@ function Set-TargetResource
$app = $serviceApps | Select-Object -First 1
if ($null -eq $serviceApps)
{
New-SPProfileServiceApplication @params | Out-Null
$app = New-SPProfileServiceApplication @params
if ($null -ne $app)
{
New-SPProfileServiceApplicationProxy -Name $pName `
-ServiceApplication $app `
-DefaultProxyGroup
}

$claimsPrincipal = New-SPClaimsPrincipal -Identity $setupAccount `
-IdentityType WindowsSamAccountName

$serviceAppSecurity = Get-SPServiceApplicationSecurity $app
Grant-SPObjectSecurity -Identity $serviceAppSecurity `
-Principal $claimsPrincipal `
-Rights "Full Control"
Set-SPServiceApplicationSecurity -Identity $app `
-ObjectSecurity $serviceAppSecurity

$app = Get-SPServiceApplication -Name $params.Name `
-ErrorAction SilentlyContinue
}
Expand Down
Expand Up @@ -21,19 +21,19 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture {
# Initialize tests
$getTypeFullName = "Microsoft.Office.Excel.Server.MossHost.ExcelServerWebServiceApplication"

# Mocks for all contexts
Mock -CommandName Remove-SPServiceApplication -MockWith { }
Mock -CommandName New-SPExcelServiceApplication -MockWith { }
Mock -CommandName Get-SPExcelFileLocation -MockWith { }
Mock -CommandName Set-SPExcelServiceApplication -MockWith { }
Mock -CommandName New-SPExcelFileLocation -MockWith { }
Mock -CommandName Set-SPExcelFileLocation -MockWith { }
Mock -CommandName Remove-SPExcelFileLocation -MockWith { }

# Test contexts
switch ($Global:SPDscHelper.CurrentStubBuildNumber.Major)
{
15 {
# Mocks for all contexts
Mock -CommandName Remove-SPServiceApplication -MockWith { }
Mock -CommandName New-SPExcelServiceApplication -MockWith { }
Mock -CommandName Get-SPExcelFileLocation -MockWith { }
Mock -CommandName Set-SPExcelServiceApplication -MockWith { }
Mock -CommandName New-SPExcelFileLocation -MockWith { }
Mock -CommandName Set-SPExcelFileLocation -MockWith { }
Mock -CommandName Remove-SPExcelFileLocation -MockWith { }

Context -Name "When no service applications exist in the current farm" -Fixture {
$testParams = @{
Name = "Test Excel Services App"
Expand Down

0 comments on commit f2a65c5

Please sign in to comment.