From e64611889ddb105f0654db83f8f196cf9be896ee Mon Sep 17 00:00:00 2001 From: Arnaud Rompen Date: Wed, 22 Feb 2023 12:05:59 +0100 Subject: [PATCH 1/3] Append Undo-PnPFileCheckedOut cmdlet and documentation --- documentation/Undo-PnPFileCheckedOut.md | 65 ++++++++++++++++++++++++ src/Commands/Files/UndoFileCheckedOut.cs | 21 ++++++++ 2 files changed, 86 insertions(+) create mode 100644 documentation/Undo-PnPFileCheckedOut.md create mode 100644 src/Commands/Files/UndoFileCheckedOut.cs diff --git a/documentation/Undo-PnPFileCheckedOut.md b/documentation/Undo-PnPFileCheckedOut.md new file mode 100644 index 000000000..68f20a0d9 --- /dev/null +++ b/documentation/Undo-PnPFileCheckedOut.md @@ -0,0 +1,65 @@ +--- +Module Name: PnP.PowerShell +title: Undo-PnPFileCheckedOut +schema: 2.0.0 +applicable: SharePoint Online +external help file: PnP.PowerShell.dll-Help.xml +online version: https://pnp.github.io/powershell/cmdlets/Undo-PnPFileCheckedOut.html +--- + +# Undo-PnPFileCheckedOut + +## SYNOPSIS +Discards changes to a file. + +## SYNTAX + +```powershell +Undo-PnPFileCheckedOut [-Url] [-Connection ] +``` + +## DESCRIPTION +This cmdlet discards changes to a single file. + +## EXAMPLES + +### EXAMPLE 1 +```powershell +Undo-PnPFileCheckedOut -Url "/sites/PnP/Shared Documents/Contract.docx" +``` + +Discards changes in the file "Contract.docx" in the "Documents" library + +## PARAMETERS + +### -Connection +Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. + +```yaml +Type: PnPConnection +Parameter Sets: (All) + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Url +The server relative url of the file to discard changes. + +```yaml +Type: String +Parameter Sets: (All) + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +## RELATED LINKS + +[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) diff --git a/src/Commands/Files/UndoFileCheckedOut.cs b/src/Commands/Files/UndoFileCheckedOut.cs new file mode 100644 index 000000000..86179ad8f --- /dev/null +++ b/src/Commands/Files/UndoFileCheckedOut.cs @@ -0,0 +1,21 @@ +using System.Management.Automation; +using Microsoft.SharePoint.Client; + + +namespace PnP.PowerShell.Commands.Files +{ + [Cmdlet(VerbsCommon.Undo, "PnPFileCheckedOut")] + public class UndoFileCheckedOut : PnPWebCmdlet + { + [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)] + public string Url = string.Empty; + + protected override void ExecuteCmdlet() + { + // Remove URL decoding from the Url as that will not work. We will encode the + character specifically, because if that is part of the filename, it needs to stay and not be decoded. + Url = Utilities.UrlUtilities.UrlDecode(Url.Replace("+", "%2B")); + + CurrentWeb.UndoCheckOutFileAsync(Url); + } + } +} From 562a7ff162dd5489206af2ad7fd61091ee455ac2 Mon Sep 17 00:00:00 2001 From: Arnaud Rompen Date: Wed, 22 Feb 2023 12:06:24 +0100 Subject: [PATCH 2/3] Append URL decoding --- src/Commands/Files/SetFileCheckedIn.cs | 3 +++ src/Commands/Files/SetFileCheckedOut.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/Commands/Files/SetFileCheckedIn.cs b/src/Commands/Files/SetFileCheckedIn.cs index fc146d4b5..0be0a4f10 100644 --- a/src/Commands/Files/SetFileCheckedIn.cs +++ b/src/Commands/Files/SetFileCheckedIn.cs @@ -21,6 +21,9 @@ public class SetFileCheckedIn : PnPWebCmdlet protected override void ExecuteCmdlet() { + // Remove URL decoding from the Url as that will not work. We will encode the + character specifically, because if that is part of the filename, it needs to stay and not be decoded. + Url = Utilities.UrlUtilities.UrlDecode(Url.Replace("+", "%2B")); + CurrentWeb.CheckInFile(Url, CheckinType, Comment); if (Approve) CurrentWeb.ApproveFile(Url, Comment); diff --git a/src/Commands/Files/SetFileCheckedOut.cs b/src/Commands/Files/SetFileCheckedOut.cs index 82c54ec52..3f956440f 100644 --- a/src/Commands/Files/SetFileCheckedOut.cs +++ b/src/Commands/Files/SetFileCheckedOut.cs @@ -12,6 +12,9 @@ public class SetFileCheckedOut : PnPWebCmdlet protected override void ExecuteCmdlet() { + // Remove URL decoding from the Url as that will not work. We will encode the + character specifically, because if that is part of the filename, it needs to stay and not be decoded. + Url = Utilities.UrlUtilities.UrlDecode(Url.Replace("+", "%2B")); + CurrentWeb.CheckOutFile(Url); } } From 562304be4c84154f0170e776780fa81b9341ff78 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Wed, 22 Feb 2023 12:20:05 +0100 Subject: [PATCH 3/3] Adding changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8e125dbb..71f37e8b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `-Connection` option to `Connect-PnPOnline` which allows of reusing an authenticated connection to connect to a different site [#2821](https://github.com/pnp/powershell/pull/2821) - Added `-UserAssignedManagedIdentityAzureResourceId` and `-UserAssignedManagedIdentityClientId` as alternatives to `-UserAssignedManagedIdentityObjectId` for `Connect-PnPOnline -ManagedIdentity` to provide an user managed identity to authenticate with. [#2813](https://github.com/pnp/powershell/pull/2813) - Added clearer error message when connecting using an expired client secret and trying to execute a command.[#2828](https://github.com/pnp/powershell/pull/2828) +- Added `Undo-PnPFileCheckedOut` which allows a checked out file to discard its changes and revert to the last checked in version. [#2837](https://github.com/pnp/powershell/pull/2837) ### Changed @@ -85,6 +86,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Contributors +- Arnaud Rompen [rompenar] - [reusto] - Ronald Mavarez [ronaldmavarez] - [lilealdai]