Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #2408 - Added support for audience targeting in lists #3153

Merged
merged 3 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `Move-PnPTerm` and `Move-PnPTermSet` cmdlets to allow moving the terms and termsets. [#2989](https://github.com/pnp/powershell/pull/2989)
- Added `-VerticalZoneEmphasis` parameter to `Add-PnPPageSection` cmdlet to allow setting the emphasis value for vertical columns. [#3129](https://github.com/pnp/powershell/pull/3129)
- Added `-AllowDeletion` parameter to `Set-PnPList` cmdlet to allow or prevent deletion of list from the SharePoint UI. [#3142](https://github.com/pnp/powershell/pull/3142)
- Added `EnableClassicAudienceTargeting` and `EnableModernAudienceTargeting` parameters to `Set-PnPList` cmdlet to enable audience targeting in lists. [#3153](https://github.com/pnp/powershell/pull/3153)
- Added `-Attachments` parameter to `Send-PnPMail` cmdlet to allow sending attachments via Microsoft Graph API. [#3157](https://github.com/pnp/powershell/pull/3157)

### Fixed
Expand Down
28 changes: 28 additions & 0 deletions documentation/Set-PnPList.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,34 @@ Work with parameter EnableAutoExpirationVersionTrim. Please see description in E
Type: UInt32
Parameter Sets: (All)

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

### -EnableClassicAudienceTargeting
Enable classic audience targeting in a SharePoint list.

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

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

### -EnableModernAudienceTargeting
Enable modern audience targeting in a SharePoint list.

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

Required: False
Position: Named
Default value: None
Expand Down
34 changes: 25 additions & 9 deletions src/Commands/Lists/SetList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class SetList : PnPWebCmdlet

[Parameter(Mandatory = false)]
public bool DisableGridEditing;

[Parameter(Mandatory = false)]
public bool DisableCommenting;

Expand All @@ -97,13 +97,19 @@ public class SetList : PnPWebCmdlet

[Parameter(Mandatory = false)]
public int ExpireVersionsAfterDays;

[Parameter(Mandatory = false)]
public SensitivityLabelPipeBind DefaultSensitivityLabelForLibrary;
public SensitivityLabelPipeBind DefaultSensitivityLabelForLibrary;

[Parameter(Mandatory = false)]
public DocumentLibraryOpenDocumentsInMode OpenDocumentsMode;

[Parameter(Mandatory = false)]
public bool EnableClassicAudienceTargeting;

[Parameter(Mandatory = false)]
public bool EnableModernAudienceTargeting;

protected override void ExecuteCmdlet()
{
var list = Identity.GetList(CurrentWeb);
Expand Down Expand Up @@ -256,13 +262,23 @@ protected override void ExecuteCmdlet()
list.DisableCommenting = DisableCommenting;
updateRequired = true;
}

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

if (ParameterSpecified(nameof(EnableClassicAudienceTargeting)))
{
list.EnableClassicAudienceTargeting();
}

if (ParameterSpecified(nameof(EnableModernAudienceTargeting)))
{
list.EnableModernAudienceTargeting();
}

updateRequired = false;

if (list.EnableVersioning)
Expand Down Expand Up @@ -350,9 +366,9 @@ protected override void ExecuteCmdlet()
}
}

if(ParameterSpecified(nameof(DefaultSensitivityLabelForLibrary)))
if (ParameterSpecified(nameof(DefaultSensitivityLabelForLibrary)))
{
if(DefaultSensitivityLabelForLibrary == null)
if (DefaultSensitivityLabelForLibrary == null)
{
WriteVerbose("Removing sensitivity label from library");
list.DefaultSensitivityLabelForLibrary = null;
Expand Down Expand Up @@ -392,14 +408,14 @@ protected override void ExecuteCmdlet()
}
}

if(ParameterSpecified(nameof(OpenDocumentsMode)))
if (ParameterSpecified(nameof(OpenDocumentsMode)))
{
// Is this for a list or a document library
if (list.BaseType == BaseType.DocumentLibrary)
{
WriteVerbose($"Configuring document library to use default open mode to be '{OpenDocumentsMode}'");

switch(OpenDocumentsMode)
switch (OpenDocumentsMode)
{
case DocumentLibraryOpenDocumentsInMode.Browser:
list.DefaultItemOpenInBrowser = true;
Expand All @@ -416,7 +432,7 @@ protected override void ExecuteCmdlet()
WriteWarning($"{nameof(OpenDocumentsMode)} is only supported for document libraries");
}

switch(OpenDocumentsMode)
switch (OpenDocumentsMode)
{
case DocumentLibraryOpenDocumentsInMode.Browser:
list.DefaultItemOpenInBrowser = true;
Expand Down