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

Support document library owner to make change of the file version trim mode #2869

Merged
merged 17 commits into from
Mar 30, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `-Identity` option to `Get-PnPPowerPlatformEnvironment` which allows retrieval of one specific environment by its displayname or id. [#2794](https://github.com/pnp/powershell/pull/2794)
- Added `Get-PnPPowerApp` which allows PowerApps to be retrieved [#2794](https://github.com/pnp/powershell/pull/2794)
- Added `-DisableCommenting` to `Set-PnPList` which allows enabling or disabling commenting on a list. [#2939](https://github.com/pnp/powershell/pull/2939)
- Added `-EnableAutoExpirationVersionTrim` and `-ExpireVersionsAfterDays` to `Set-PnPList` which allows enabling or disabling auto expiration of versions on a list or library based on the days passed. [#2869](https://github.com/pnp/powershell/pull/2869)

### Changed

Expand Down Expand Up @@ -108,6 +109,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed `Add-PnPFieldFromXml` cmdlet. It will now return the correct typed field if the added field was of type `Taxonomy`. [#2926](https://github.com/pnp/powershell/pull/2926)

### Contributors

- [msjennywu]
- [enthusol]
- Ganesh Sanap [ganesh-sanap]
- Chris R. [ChrisRo89]
Expand Down
60 changes: 57 additions & 3 deletions documentation/Set-PnPList.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ 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>] [-DisableCommenting <Boolean>] [-DefaultSensitivityLabelForLibrary <SensitivityLabelPipeBind>]
[-Path <String>] [-OpenDocumentsMode <DocumentLibraryOpenDocumentsInMode>] [-Connection <PnPConnection>]
[-NoCrawl] [-ExemptFromBlockDownloadOfNonViewableFiles <Boolean>] [-DisableGridEditing <Boolean>] [-DisableCommenting <Boolean>]
[-EnableAutoExpirationVersionTrim <Boolean>] [-ExpireVersionsAfterDays <UInt32>]
[-DefaultSensitivityLabelForLibrary <SensitivityLabelPipeBind>] [-Path <String>] [-OpenDocumentsMode <DocumentLibraryOpenDocumentsInMode>] [-Connection <PnPConnection>]
```

## DESCRIPTION
Expand Down Expand Up @@ -81,6 +82,27 @@ Rename a list, including its' URL.

### EXAMPLE 8
```powershell
Set-PnPList -Identity "Demo List" -EnableAutoExpirationVersionTrim $true
```

Enable AutoExpiration file version trim mode on a doccument library.

### EXAMPLE 9
```powershell
Set-PnPList -Identity "Demo List" -EnableAutoExpirationVersionTrim $false -ExpireVersionsAfterDays 30 -MajorVerions 500
```

Enable ExpireAfter file version trim mode on a doccument library. MinorVersions is also needed when minor version is enabled.

### EXAMPLE 10
```powershell
Set-PnPList -Identity "Demo List" -EnableAutoExpirationVersionTrim $false -ExpireVersionsAfterDays 0 -MajorVerions 500
```

Enable NoExpiration file version trim mode on a doccument library. MinorVersions is also needed when minor version is enabled.

### EXAMPLE 11
```powershell
Set-PnPList -Identity "Demo List" -DefaultSensitivityLabelForLibrary "Confidential"
```

Expand Down Expand Up @@ -496,6 +518,38 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -EnableAutoExpirationVersionTrim
Enable or disable AutoExpiration version trim for the document library. Set to $true to enable, $false to disable.

Parameter ExpireVersionsAfterDays is required when EnableAutoExpirationVersionTrim is false. Set ExpireVersionsAfterDays to 0 for NoExpiration, set it to greater or equal 30 for ExpireAfter.

Parameter MajorVersions is required when EnableAutoExpirationVersionTrim is false.
Parameter MinorVersions is required when EnableAutoExpirationVersionTrim is false and minor version is enabled.

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

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

### -ExpireVersionsAfterDays
Work with parameter EnableAutoExpirationVersionTrim. Please see description in EnableAutoExpirationVersionTrim.

```yaml
Type: UInt32
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)
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
66 changes: 65 additions & 1 deletion src/Commands/Lists/SetList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ public class SetList : PnPWebCmdlet
public string Path;

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

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

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

[Parameter(Mandatory = false)]
public DocumentLibraryOpenDocumentsInMode OpenDocumentsMode;
Expand Down Expand Up @@ -255,14 +261,72 @@ protected override void ExecuteCmdlet()
// Is this for a list or a document library
if (list.BaseType == BaseType.DocumentLibrary)
{
list.EnsureProperties(l => l.VersionPolicies);

if (ParameterSpecified(nameof(EnableAutoExpirationVersionTrim)))
{
if (EnableAutoExpirationVersionTrim)
{
list.VersionPolicies.DefaultTrimMode = VersionPolicyTrimMode.AutoExpiration;
}
else
{
if (!ParameterSpecified(nameof(MajorVersions)) || !ParameterSpecified(nameof(ExpireVersionsAfterDays)))
{
throw new PSArgumentException($"You must specify a value for {nameof(ExpireVersionsAfterDays)} and {nameof(MajorVersions)}", nameof(ExpireVersionsAfterDays));
}

if (!ParameterSpecified(nameof(MinorVersions)) && list.EnableMinorVersions)
{
throw new PSArgumentException($"You must specify a value for {nameof(MinorVersions)} if it is enabled.", nameof(MinorVersions));
}

if (ExpireVersionsAfterDays == 0)
{
list.VersionPolicies.DefaultTrimMode = VersionPolicyTrimMode.NoExpiration;
}
else if (ExpireVersionsAfterDays >= 30)
{
list.VersionPolicies.DefaultTrimMode = VersionPolicyTrimMode.ExpireAfter;
}
else
{
throw new PSArgumentException($"You must specify {nameof(ExpireVersionsAfterDays)} to be 0 for NoExpiration or greater equal 30 for ExpireAfter.", nameof(ExpireVersionsAfterDays));
}
}

updateRequired = true;
}

if (ParameterSpecified(nameof(ExpireVersionsAfterDays)) && (int)ExpireVersionsAfterDays >= 30)
{
if (list.VersionPolicies.DefaultTrimMode == VersionPolicyTrimMode.AutoExpiration)
{
throw new PSArgumentException($"The parameter {nameof(ExpireVersionsAfterDays)} can't be set when AutoExpiration is enabled");
}

list.VersionPolicies.DefaultExpireAfterDays = (int)ExpireVersionsAfterDays;
updateRequired = true;
}

if (ParameterSpecified(nameof(MajorVersions)))
{
if (list.VersionPolicies.DefaultTrimMode == VersionPolicyTrimMode.AutoExpiration)
{
throw new PSArgumentException($"The parameter {nameof(MajorVersions)} can't be set when AutoExpiration is enabled", nameof(MajorVersions));
}

list.MajorVersionLimit = (int)MajorVersions;
updateRequired = true;
}

if (ParameterSpecified(nameof(MinorVersions)) && list.EnableMinorVersions)
{
if (list.VersionPolicies.DefaultTrimMode == VersionPolicyTrimMode.AutoExpiration)
{
throw new PSArgumentException($"The parameter {nameof(MinorVersions)} can't be set when AutoExpiration is enabled", nameof(MinorVersions));
}

list.MajorWithMinorVersionsLimit = (int)MinorVersions;
updateRequired = true;
}
Expand Down