Skip to content

Commit

Permalink
Merge pull request #2381 from fowl2/SetList-Path
Browse files Browse the repository at this point in the history
SetList: add "-Path" parameter for updating list URLs
  • Loading branch information
KoenZomers committed Sep 29, 2022
2 parents 50cb96a + b51e539 commit c624e55
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 137 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `ScriptSafeDomainName` option to `Set-PnPSite` to allow contributors to insert iframe from specified domains only. [#2363](https://github.com/pnp/powershell/pull/2363)
- Added `AlertTemplateName` paramter to `Add-PnPAlert` to allow configuring the Alert Template type name in the email. [#2362](https://github.com/pnp/powershell/pull/2362)
- Added `Get-PnPAzureADActivityReportDirectoryAudit` to retrieve the audit logs generated by Azure AD. [#2095](https://github.com/pnp/powershell/pull/2095)
- Added `-Path` option to `Set-PnPList` which allows the url of a list to be changed within the same site [#2381](https://github.com/pnp/powershell/pull/2381)
- Added `-Force` option to `Set-PnPListem` to force it to update a list item even without changing something. Can be useful in i.e. triggering a webhook. [#2396](https://github.com/pnp/powershell/pull/2396)
- Added `ImageUrl`, `PageImageAlignment`, `ImageHeight` and `ImageWidth` parameters to `Add-PnPPageTextPart` cmdlet so that users can add an inline image into a text webpart. [#2401](https://github.com/pnp/powershell/pull/2401)

Expand Down
24 changes: 23 additions & 1 deletion documentation/Set-PnPList.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Set-PnPList -Identity <ListPipeBind> [-EnableContentTypes <Boolean>] [-BreakRole
[-EnableAttachments <Boolean>] [-EnableFolderCreation <Boolean>] [-EnableVersioning <Boolean>]
[-EnableMinorVersions <Boolean>] [-MajorVersions <UInt32>] [-MinorVersions <UInt32>]
[-EnableModeration <Boolean>] [-DraftVersionVisibility <DraftVisibilityType>] [-ReadSecurity <ListReadSecurity>] [-WriteSecurity <ListWriteSecurity>]
[-NoCrawl] [-ExemptFromBlockDownloadOfNonViewableFiles <Boolean>] [-DisableGridEditing <Boolean>] [-Connection <PnPConnection>] [<CommonParameters>]
[-NoCrawl] [-ExemptFromBlockDownloadOfNonViewableFiles <Boolean>] [-DisableGridEditing <Boolean>]
[-Path <String>] [-Connection <PnPConnection>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -71,6 +72,13 @@ Set-PnPList -Identity "Demo List" -EnableAttachments $true

Turns on attachments on a list

### EXAMPLE 7
```powershell
Set-PnPList -Identity "Demo List" -Title "Demo List 2" -Path "Lists/DemoList2"
```

Rename a list, including its' URL.

## PARAMETERS

### -BreakRoleInheritance
Expand Down Expand Up @@ -424,6 +432,20 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Path
The new URL path of the list. The parent folder must exist and be in the same site/web. I.e. lists\newname.

```yaml
Type: String
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
289 changes: 153 additions & 136 deletions src/Commands/Lists/SetList.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.SharePoint.Client;

using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Enums;

using System.Management.Automation;

namespace PnP.PowerShell.Commands.Lists
Expand Down Expand Up @@ -81,177 +83,192 @@ public class SetList : PnPWebCmdlet
[Parameter(Mandatory = false)]
public bool DisableGridEditing;

[Parameter(Mandatory = false)]
public string Path;

protected override void ExecuteCmdlet()
{
var list = Identity.GetList(CurrentWeb);

if (list != null)
if (list is null)
{
list.EnsureProperties(l => l.EnableAttachments, l => l.EnableVersioning, l => l.EnableMinorVersions, l => l.Hidden, l => l.EnableModeration, l => l.BaseType, l => l.HasUniqueRoleAssignments, l => l.ContentTypesEnabled, l => l.ExemptFromBlockDownloadOfNonViewableFiles, l => l.DisableGridEditing);
WriteWarning($"List {Identity} not found");
return;
}

var enableVersioning = list.EnableVersioning;
var enableMinorVersions = list.EnableMinorVersions;
var enableAttachments = list.EnableAttachments;
var updateRequired = false;
if (BreakRoleInheritance)
{
list.BreakRoleInheritance(CopyRoleAssignments, ClearSubscopes);
updateRequired = true;
}
if (ParameterSpecified(nameof(Path)))
{
// Move the list to its newly requested location within the same site
list.RootFolder.MoveTo(Path);
ClientContext.ExecuteQueryRetry();

if (list.HasUniqueRoleAssignments && ResetRoleInheritance)
{
list.ResetRoleInheritance();
updateRequired = true;
}
// Fetch the list again so it will have its updated location and can be used for property updates
var newIdentity = new ListPipeBind(list.Id);
list = newIdentity.GetList(CurrentWeb);
}

if (!string.IsNullOrEmpty(Title))
{
list.Title = Title;
updateRequired = true;
}
list.EnsureProperties(l => l.EnableAttachments, l => l.EnableVersioning, l => l.EnableMinorVersions, l => l.Hidden, l => l.EnableModeration, l => l.BaseType, l => l.HasUniqueRoleAssignments, l => l.ContentTypesEnabled, l => l.ExemptFromBlockDownloadOfNonViewableFiles, l => l.DisableGridEditing);

if (ParameterSpecified(nameof(Hidden)) && Hidden != list.Hidden)
{
list.Hidden = Hidden;
updateRequired = true;
}
var enableVersioning = list.EnableVersioning;
var enableMinorVersions = list.EnableMinorVersions;
var enableAttachments = list.EnableAttachments;
var updateRequired = false;
if (BreakRoleInheritance)
{
list.BreakRoleInheritance(CopyRoleAssignments, ClearSubscopes);
updateRequired = true;
}

if (ParameterSpecified(nameof(EnableContentTypes)) && list.ContentTypesEnabled != EnableContentTypes)
{
list.ContentTypesEnabled = EnableContentTypes;
updateRequired = true;
}
if (list.HasUniqueRoleAssignments && ResetRoleInheritance)
{
list.ResetRoleInheritance();
updateRequired = true;
}

if (ParameterSpecified(nameof(EnableVersioning)) && EnableVersioning != enableVersioning)
{
list.EnableVersioning = EnableVersioning;
updateRequired = true;
}
if (!string.IsNullOrEmpty(Title))
{
list.Title = Title;
updateRequired = true;
}

if (ParameterSpecified(nameof(EnableMinorVersions)) && EnableMinorVersions != enableMinorVersions)
{
list.EnableMinorVersions = EnableMinorVersions;
updateRequired = true;
}
if (ParameterSpecified(nameof(Hidden)) && Hidden != list.Hidden)
{
list.Hidden = Hidden;
updateRequired = true;
}

if (ParameterSpecified(nameof(EnableModeration)) && list.EnableModeration != EnableModeration)
{
list.EnableModeration = EnableModeration;
updateRequired = true;
}
if (ParameterSpecified(nameof(EnableContentTypes)) && list.ContentTypesEnabled != EnableContentTypes)
{
list.ContentTypesEnabled = EnableContentTypes;
updateRequired = true;
}

if (ParameterSpecified(nameof(DraftVersionVisibility)))
{
list.DraftVersionVisibility = DraftVersionVisibility;
updateRequired = true;
}
if (ParameterSpecified(nameof(EnableVersioning)) && EnableVersioning != enableVersioning)
{
list.EnableVersioning = EnableVersioning;
updateRequired = true;
}

if (ParameterSpecified(nameof(EnableAttachments)) && EnableAttachments != enableAttachments)
{
list.EnableAttachments = EnableAttachments;
updateRequired = true;
}
if (ParameterSpecified(nameof(EnableMinorVersions)) && EnableMinorVersions != enableMinorVersions)
{
list.EnableMinorVersions = EnableMinorVersions;
updateRequired = true;
}

if (ParameterSpecified(nameof(Description)))
{
list.Description = Description;
updateRequired = true;
}
if (ParameterSpecified(nameof(EnableModeration)) && list.EnableModeration != EnableModeration)
{
list.EnableModeration = EnableModeration;
updateRequired = true;
}

if (ParameterSpecified(nameof(EnableFolderCreation)))
{
list.EnableFolderCreation = EnableFolderCreation;
updateRequired = true;
}
if (ParameterSpecified(nameof(DraftVersionVisibility)))
{
list.DraftVersionVisibility = DraftVersionVisibility;
updateRequired = true;
}

if (ParameterSpecified(nameof(ForceCheckout)))
{
list.ForceCheckout = ForceCheckout;
updateRequired = true;
}
if (ParameterSpecified(nameof(EnableAttachments)) && EnableAttachments != enableAttachments)
{
list.EnableAttachments = EnableAttachments;
updateRequired = true;
}

if (ParameterSpecified(nameof(ListExperience)))
{
list.ListExperienceOptions = ListExperience;
updateRequired = true;
}
if (ParameterSpecified(nameof(Description)))
{
list.Description = Description;
updateRequired = true;
}

if (ParameterSpecified(nameof(ReadSecurity)))
{
list.ReadSecurity = (int)ReadSecurity;
updateRequired = true;
}
if (ParameterSpecified(nameof(EnableFolderCreation)))
{
list.EnableFolderCreation = EnableFolderCreation;
updateRequired = true;
}

if (ParameterSpecified(nameof(WriteSecurity)))
{
list.WriteSecurity = (int)WriteSecurity;
updateRequired = true;
}
if (ParameterSpecified(nameof(ForceCheckout)))
{
list.ForceCheckout = ForceCheckout;
updateRequired = true;
}

if (ParameterSpecified(nameof(NoCrawl)))
{
list.NoCrawl = NoCrawl;
updateRequired = true;
}
if (ParameterSpecified(nameof(ListExperience)))
{
list.ListExperienceOptions = ListExperience;
updateRequired = true;
}

if (ParameterSpecified(nameof(ExemptFromBlockDownloadOfNonViewableFiles)))
{
list.SetExemptFromBlockDownloadOfNonViewableFiles(ExemptFromBlockDownloadOfNonViewableFiles);
updateRequired = true;
}
if (ParameterSpecified(nameof(ReadSecurity)))
{
list.ReadSecurity = (int)ReadSecurity;
updateRequired = true;
}

if (ParameterSpecified(nameof(DisableGridEditing)))
{
list.DisableGridEditing = DisableGridEditing;
updateRequired = true;
}
if (ParameterSpecified(nameof(WriteSecurity)))
{
list.WriteSecurity = (int)WriteSecurity;
updateRequired = true;
}

if (updateRequired)
{
list.Update();
ClientContext.ExecuteQueryRetry();
}
updateRequired = false;
if (ParameterSpecified(nameof(NoCrawl)))
{
list.NoCrawl = NoCrawl;
updateRequired = true;
}

if (list.EnableVersioning)
{
// list or doclib?
if (ParameterSpecified(nameof(ExemptFromBlockDownloadOfNonViewableFiles)))
{
list.SetExemptFromBlockDownloadOfNonViewableFiles(ExemptFromBlockDownloadOfNonViewableFiles);
updateRequired = true;
}

if (list.BaseType == BaseType.DocumentLibrary)
{
if (ParameterSpecified(nameof(DisableGridEditing)))
{
list.DisableGridEditing = DisableGridEditing;
updateRequired = true;
}

if (ParameterSpecified(nameof(MajorVersions)))
{
list.MajorVersionLimit = (int)MajorVersions;
updateRequired = true;
}

if (ParameterSpecified(nameof(MinorVersions)) && list.EnableMinorVersions)
{
list.MajorWithMinorVersionsLimit = (int)MinorVersions;
updateRequired = true;
}
}
else
if (updateRequired)
{
list.Update();
ClientContext.ExecuteQueryRetry();
}

updateRequired = false;

if (list.EnableVersioning)
{
// list or doclib?
if (list.BaseType == BaseType.DocumentLibrary)
{
if (ParameterSpecified(nameof(MajorVersions)))
{
if (ParameterSpecified(nameof(MajorVersions)))
{
list.MajorVersionLimit = (int)MajorVersions;
updateRequired = true;
}
list.MajorVersionLimit = (int)MajorVersions;
updateRequired = true;
}


if (ParameterSpecified(nameof(MinorVersions)) && list.EnableMinorVersions)
{
list.MajorWithMinorVersionsLimit = (int)MinorVersions;
updateRequired = true;
}
}
if (updateRequired)
else
{
list.Update();
ClientContext.ExecuteQueryRetry();
if (ParameterSpecified(nameof(MajorVersions)))
{
list.MajorVersionLimit = (int)MajorVersions;
updateRequired = true;
}
}
}

WriteObject(list);
if (updateRequired)
{
list.Update();
ClientContext.ExecuteQueryRetry();
}

WriteObject(list);
}
}
}
}

0 comments on commit c624e55

Please sign in to comment.