Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1827 from SharePoint/dev
Browse files Browse the repository at this point in the history
January 2019 Release
  • Loading branch information
erwinvanhunen committed Jan 14, 2019
2 parents 4f339e6 + 256c87d commit 271dc09
Show file tree
Hide file tree
Showing 41 changed files with 4,911 additions and 102 deletions.
Binary file modified Binaries/SharePointPnP.Modernization.Framework.dll
Binary file not shown.
2,297 changes: 2,297 additions & 0 deletions Binaries/SharePointPnP.Modernization.Framework.xml

Large diffs are not rendered by default.

Binary file modified Binaries/release/SharePointPnP.Modernization.Framework.dll
Binary file not shown.
2,297 changes: 2,297 additions & 0 deletions Binaries/release/SharePointPnP.Modernization.Framework.xml

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [3.5.1901.0]

### Added
- Added Reset-PnPFileVersion cmdlet

### Changed

- Add-PnPClientSidePageSection: Added support for section the section background of a client side page
- Updated file and folder cmdlets to support special characters

### Deprecated

### Contributors
- Eric Skaggs (skaggej)
- Gautam Sheth (gautamdsheth)

## [3.4.1812.0]

### Added
Expand Down Expand Up @@ -455,7 +471,7 @@ jensotto
**2015-09-21**

* Added -Parameters parameter to Apply-SPOProvisioningTemplate. See help for the cmdlet for more info.
* Renamed PageUrl parameter of Webpart cmdlets to ServerRelativePageUrl. Set PageUrl as parameter alias to not break existing scripts.
* Renamed PageUrl parameter of web part cmdlets to ServerRelativePageUrl. Set PageUrl as parameter alias to not break existing scripts.

**2015-09-17**

Expand Down Expand Up @@ -484,7 +500,7 @@ jensotto

**2015-08-10**

* Added Get-SPOWebPartXml cmdlet to export webpart XML from a page.
* Added Get-SPOWebPartXml cmdlet to export web part XML from a page.

**2015-08-07**

Expand Down Expand Up @@ -595,7 +611,7 @@ still works as before.

**2015-01-07**

* Introduced new Cmdlet: Get-SPOWebPartProperty to return webpart properties
* Introduced new Cmdlet: Get-SPOWebPartProperty to return web part properties
* Updated Set-SPOWebPartProperty cmdlet to support int values

**2015-01-02**
Expand Down
26 changes: 18 additions & 8 deletions Commands/Base/ConnectOnline.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
using SharePointPnP.PowerShell.CmdletHelpAttributes;
using Microsoft.Identity.Client;
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;
using SharePointPnP.PowerShell.CmdletHelpAttributes;
using SharePointPnP.PowerShell.Commands.Base.PipeBinds;
using SharePointPnP.PowerShell.Commands.Provider;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Net;
using System.Reflection;
using System.Security;
using System.Linq;
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;
using SharePointPnP.PowerShell.Commands.Provider;
using File = System.IO.File;
using System.Net;
using Microsoft.Identity.Client;
#if NETSTANDARD2_0
using System.IdentityModel.Tokens.Jwt;
#endif
#if !ONPREMISES
using Microsoft.SharePoint.Client.CompliancePolicy;
#endif

namespace SharePointPnP.PowerShell.Commands.Base
Expand Down Expand Up @@ -141,6 +142,8 @@ public class ConnectOnline : PSCmdlet
private static readonly Uri GraphAADLogin = new Uri("https://login.microsoftonline.com/");
private static readonly string[] GraphDefaultScope = { "https://graph.microsoft.com/.default" };
#endif


#if ONPREMISES
private const string ParameterSet_HIGHTRUST_CERT = "High Trust using a X509Certificate2 object.";
private const string ParameterSet_HIGHTRUST_PFX = "High Trust using a certificate from a PFX file.";
Expand Down Expand Up @@ -469,6 +472,12 @@ public class ConnectOnline : PSCmdlet

protected override void ProcessRecord()
{
var latestVersion = SPOnlineConnectionHelper.GetLatestVersion();
if (!string.IsNullOrEmpty(latestVersion))
{
WriteWarning(latestVersion);
}

if (IgnoreSslErrors)
{
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
Expand Down Expand Up @@ -756,6 +765,7 @@ private SPOnlineConnection ConnectGraphDeviceLogin(string accessToken)
}
}


private void ConnectGraphAAD()
{
var appCredentials = new ClientCredential(AppSecret);
Expand Down
8 changes: 5 additions & 3 deletions Commands/Base/PipeBinds/PagePipeBind.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if !ONPREMISES
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core.Utilities;
using SharePointPnP.PowerShell.Commands.ClientSidePages;
using System;
using System.Linq;
Expand Down Expand Up @@ -45,9 +46,10 @@ public PagePipeBind(string name)
internal ListItem GetPage(Web web)
{
// Get pages library
ListCollection listCollection = web.Lists;
listCollection.EnsureProperties(coll => coll.Include(li => li.BaseTemplate));
var sitePagesLibrary = listCollection.Where(p => p.BaseTemplate == (int)ListTemplateType.WebPageLibrary).FirstOrDefault();
web.EnsureProperty(w => w.ServerRelativeUrl);
var listServerRelativeUrl = UrlUtility.Combine(web.ServerRelativeUrl, "sitepages");
var sitePagesLibrary = web.GetList(listServerRelativeUrl);

if (sitePagesLibrary != null)
{
CamlQuery query = null;
Expand Down
38 changes: 37 additions & 1 deletion Commands/Base/SPOnlineConnectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using System.Reflection;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using Newtonsoft.Json;
Expand All @@ -28,6 +27,14 @@ namespace SharePointPnP.PowerShell.Commands.Base
{
internal class SPOnlineConnectionHelper
{

#if DEBUG
private static readonly Uri VersionCheckUrl = new Uri("https://raw.githubusercontent.com/SharePoint/PnP-PowerShell/dev/version.txt");
#else
private static readonly Uri VersionCheckUrl = new Uri("https://raw.githubusercontent.com/SharePoint/PnP-PowerShell/master/version.txt");
#endif
private static bool VersionChecked;

#if !NETSTANDARD2_0
public static AuthenticationContext AuthContext { get; set; }
#endif
Expand Down Expand Up @@ -692,5 +699,34 @@ private static bool IsTenantAdminSite(ClientRuntimeContext clientContext)
return (result);
},
true);

public static string GetLatestVersion()
{
try
{
if (!VersionChecked)
{
using (var client = new WebClient())
{
SPOnlineConnectionHelper.VersionChecked = true;
var onlineVersion = client.DownloadString(VersionCheckUrl);
onlineVersion = onlineVersion.Trim(new char[] { '\t', '\r', '\n' });
var assembly = Assembly.GetExecutingAssembly();
var currentVersion = ((AssemblyFileVersionAttribute)assembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute))).Version;
if (Version.TryParse(onlineVersion, out Version availableVersion))
{
if (availableVersion > new Version(currentVersion))
{
return $"A newer version of PnP PowerShell is available: {availableVersion}. Consider upgrading.";
}
}
SPOnlineConnectionHelper.VersionChecked = true;
}
}
}
catch
{ }
return null;
}
}
}
10 changes: 9 additions & 1 deletion Commands/ClientSidePages/AddClientSidePageSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ namespace SharePointPnP.PowerShell.Commands.ClientSidePages
PS> Add-PnPClientSidePageSection -Page $page -SectionTemplate OneColumn",
Remarks = "Adds a new one column section to the Client-Side page 'MyPage'",
SortOrder = 3)]
[CmdletExample(
Code = @"PS:> $page = Add-PnPClientSidePage -Name ""MyPage""
PS> Add-PnPClientSidePageSection -Page $page -SectionTemplate OneColumn -ZoneEmphasis 2",
Remarks = "Adds a new one column section to the Client-Side page 'MyPage' and sets the background to 2 (0 is no background, 3 is highest emphasis)",
SortOrder = 4)]
public class AddClientSidePageSection : PnPWebCmdlet
{
[Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "The name of the page")]
Expand All @@ -34,14 +39,17 @@ public class AddClientSidePageSection : PnPWebCmdlet
[Parameter(Mandatory = false, HelpMessage = "Sets the order of the section. (Default = 1)")]
public int Order = 1;

[Parameter(Mandatory = false, HelpMessage = "Sets the background of the section (default = 0)")]
public int ZoneEmphasis = 0;


protected override void ExecuteCmdlet()
{
var clientSidePage = Page?.GetPage(ClientContext);

if (clientSidePage != null)
{
clientSidePage.AddSection(SectionTemplate, Order);
clientSidePage.AddSection(new CanvasSection(clientSidePage, SectionTemplate, Order) { ZoneEmphasis = ZoneEmphasis });
clientSidePage.Save();
}
else
Expand Down
18 changes: 18 additions & 0 deletions Commands/ClientSidePages/ConvertToClientSidePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SharePointPnP.Modernization.Framework.Transform;
using SharePointPnP.PowerShell.Commands.Utilities;
using System.Reflection;
using SharePointPnP.Modernization.Framework.Cache;

namespace SharePointPnP.PowerShell.Commands.ClientSidePages
{
Expand All @@ -21,6 +22,10 @@ namespace SharePointPnP.PowerShell.Commands.ClientSidePages
Code = @"PS:> ConvertTo-PnPClientSidePage -Identity ""somepage.aspx"" -Overwrite -WebPartMappingFile c:\contoso\webpartmapping.xml",
Remarks = "Converts a wiki page named 'somepage' to a client side page using a custom provided mapping file",
SortOrder = 2)]
[CmdletExample(
Code = @"PS:> ConvertTo-PnPClientSidePage -Identity ""somepage.aspx"" -Overwrite -AddPageAcceptBanner",
Remarks = "Converts a wiki page named 'somepage' to a client side page and adds the page accept banner web part on top of the page. This requires that the SPFX solution holding the web part (https://github.com/SharePoint/sp-dev-modernization/blob/master/Solutions/PageTransformationUI/assets/sharepointpnp-pagetransformation-client.sppkg?raw=true) has been installed to the tenant app catalog.",
SortOrder = 3)]
public class ConvertToClientSidePage : PnPWebCmdlet
{
private Assembly modernizationAssembly;
Expand All @@ -45,6 +50,12 @@ public class ConvertToClientSidePage : PnPWebCmdlet
[Parameter(Mandatory = false, HelpMessage = "Adds the page accept banner web part. The actual web part is specified in webpartmapping.xml file")]
public SwitchParameter AddPageAcceptBanner = false;

[Parameter(Mandatory = false, HelpMessage = "By default the item level permissions on a page are copied to the created client side page. Use this switch to prevent the copy.")]
public SwitchParameter SkipItemLevelPermissionCopyToClientSidePage = false;

[Parameter(Mandatory = false, HelpMessage = "Clears the page component cache. Can be needed if you've installed a new web part to the site and want to use that in a custom webpartmapping file. Restarting your PS session has the same effect.")]
public SwitchParameter ClearPageComponentCache = false;

protected override void ExecuteCmdlet()
{
string tempPath = null;
Expand Down Expand Up @@ -93,12 +104,19 @@ protected override void ExecuteCmdlet()
Overwrite = this.Overwrite,
TargetPageTakesSourcePageName = this.TakeSourcePageName,
ReplaceHomePageWithDefaultHomePage = this.ReplaceHomePageWithDefault,
KeepPageSpecificPermissions = !this.SkipItemLevelPermissionCopyToClientSidePage,
ModernizationCenterInformation = new ModernizationCenterInformation()
{
AddPageAcceptBanner = this.AddPageAcceptBanner
},
};

// Clear the client side component cache
if (this.ClearPageComponentCache)
{
CacheManager.Instance.ClearClientSideComponents();
}

string serverRelativeClientPageUrl = pageTransformator.Transform(pti);

ClientSidePagePipeBind cpb = new ClientSidePagePipeBind(System.IO.Path.GetFileName(serverRelativeClientPageUrl));
Expand Down
16 changes: 8 additions & 8 deletions Commands/ClientSidePages/MoveClientSideComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ public class MoveClientSideWebPart : PnPWebCmdlet
[Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The instance id of the control. Use Get-PnPClientSideControl retrieve the instance ids.")]
public GuidPipeBind InstanceId;

[Parameter(Mandatory = true, ValueFromPipeline = false, ParameterSetName = ParameterSet_SECTION, HelpMessage = "The section to move the webpart to")]
[Parameter(Mandatory = true, ValueFromPipeline = false, ParameterSetName = ParameterSet_SECTIONCOLUMN, HelpMessage = "The section to move the webpart to")]
[Parameter(Mandatory = true, ValueFromPipeline = false, ParameterSetName = ParameterSet_SECTION, HelpMessage = "The section to move the web part to")]
[Parameter(Mandatory = true, ValueFromPipeline = false, ParameterSetName = ParameterSet_SECTIONCOLUMN, HelpMessage = "The section to move the web part to")]
public int Section;

[Parameter(Mandatory = true, ValueFromPipeline = false, ParameterSetName = ParameterSet_COLUMN, HelpMessage = "The column to move the webpart to")]
[Parameter(Mandatory = true, ValueFromPipeline = false, ParameterSetName = ParameterSet_SECTIONCOLUMN, HelpMessage = "The column to move the webpart to")]
[Parameter(Mandatory = true, ValueFromPipeline = false, ParameterSetName = ParameterSet_COLUMN, HelpMessage = "The column to move the web part to")]
[Parameter(Mandatory = true, ValueFromPipeline = false, ParameterSetName = ParameterSet_SECTIONCOLUMN, HelpMessage = "The column to move the web part to")]
public int Column;

[Parameter(Mandatory = false, ValueFromPipeline = false, ParameterSetName = ParameterSet_COLUMN, HelpMessage = "Change to order of the webpart in the column")]
[Parameter(Mandatory = false, ValueFromPipeline = false, ParameterSetName = ParameterSet_SECTION, HelpMessage = "Change to order of the webpart in the column")]
[Parameter(Mandatory = false, ValueFromPipeline = false, ParameterSetName = ParameterSet_SECTIONCOLUMN, HelpMessage = "Change to order of the webpart in the column")]
[Parameter(Mandatory = true, ValueFromPipeline = false, ParameterSetName = ParameterSet_POSITION, HelpMessage = "Change to order of the webpart in the column")]
[Parameter(Mandatory = false, ValueFromPipeline = false, ParameterSetName = ParameterSet_COLUMN, HelpMessage = "Change to order of the web part in the column")]
[Parameter(Mandatory = false, ValueFromPipeline = false, ParameterSetName = ParameterSet_SECTION, HelpMessage = "Change to order of the web part in the column")]
[Parameter(Mandatory = false, ValueFromPipeline = false, ParameterSetName = ParameterSet_SECTIONCOLUMN, HelpMessage = "Change to order of the web part in the column")]
[Parameter(Mandatory = true, ValueFromPipeline = false, ParameterSetName = ParameterSet_POSITION, HelpMessage = "Change to order of the web part in the column")]
public int Position;

protected override void ExecuteCmdlet()
Expand Down
10 changes: 5 additions & 5 deletions Commands/ClientSidePages/SetClientSideWebPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ namespace SharePointPnP.PowerShell.Commands.ClientSidePages
[Cmdlet(VerbsCommon.Set, "PnPClientSideWebPart")]
[CmdletHelp("Set Client-Side Web Part properties",
SupportedPlatform = CmdletSupportedPlatform.Online,
DetailedDescription = "Sets specific client side webpart properties. Notice that the title parameter will only set the -internal- title of webpart. The title which is shown in the UI will, if possible, have to be set using the PropertiesJson parameter. Use Get-PnPClientSideComponent to retrieve the instance id and properties of a webpart.",
DetailedDescription = "Sets specific client side web part properties. Notice that the title parameter will only set the -internal- title of web part. The title which is shown in the UI will, if possible, have to be set using the PropertiesJson parameter. Use Get-PnPClientSideComponent to retrieve the instance id and properties of a web part.",
Category = CmdletHelpCategory.WebParts)]
[CmdletExample(
Code = @"PS:> Set-PnPClientSideWebPart -Page Home -Identity a2875399-d6ff-43a0-96da-be6ae5875f82 -PropertiesJson $myproperties",
Remarks = @"Sets the properties of the client side webpart given in the $myproperties variable.", SortOrder = 1)]
Remarks = @"Sets the properties of the client side web part given in the $myproperties variable.", SortOrder = 1)]
public class SetClientSideWebPart : PnPWebCmdlet
{
[Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "The name of the page")]
public ClientSidePagePipeBind Page;

[Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The identity of the webpart. This can be the webpart instance id or the title of a webpart")]
[Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The identity of the web part. This can be the web part instance id or the title of a web part")]
public ClientSideWebPartPipeBind Identity;

[Parameter(Mandatory = false, ValueFromPipeline = true, HelpMessage = "Sets the internal title of the webpart. Notice that this will NOT set a visible title.")]
[Parameter(Mandatory = false, ValueFromPipeline = true, HelpMessage = "Sets the internal title of the web part. Notice that this will NOT set a visible title.")]
public string Title;

[Parameter(Mandatory = false, ValueFromPipeline = true, HelpMessage = "Sets the properties as a JSON string.")]
Expand Down Expand Up @@ -66,7 +66,7 @@ protected override void ExecuteCmdlet()
}
else
{
throw new Exception($"WebPart does not exist");
throw new Exception($"Web part does not exist");
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions Commands/Files/AddFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ protected override void ExecuteCmdlet()
{
try
{
#if ONPREMISES
var existingFile = SelectedWeb.GetFileByServerRelativeUrl(fileUrl);
#else
var existingFile = SelectedWeb.GetFileByServerRelativePath(ResourcePath.FromDecodedUrl(fileUrl));
#endif
existingFile.EnsureProperty(f => f.Exists);
if (existingFile.Exists)
{
Expand Down
9 changes: 8 additions & 1 deletion Commands/Files/GetFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ protected override void ExecuteCmdlet()
});
break;
case URLASFILEOBJECT:
#if ONPREMISES
file = SelectedWeb.GetFileByServerRelativeUrl(serverRelativeUrl);

#else
file = SelectedWeb.GetFileByServerRelativePath(ResourcePath.FromDecodedUrl(serverRelativeUrl));
#endif
ClientContext.Load(file, f => f.Author, f => f.Length,
f => f.ModifiedBy, f => f.Name, f => f.TimeCreated,
f => f.TimeLastModified, f => f.Title);
Expand All @@ -122,7 +125,11 @@ protected override void ExecuteCmdlet()
WriteObject(file);
break;
case URLASLISTITEM:
#if ONPREMISES
file = SelectedWeb.GetFileByServerRelativeUrl(serverRelativeUrl);
#else
file = SelectedWeb.GetFileByServerRelativePath(ResourcePath.FromDecodedUrl(serverRelativeUrl));
#endif

ClientContext.Load(file, f => f.Exists, f => f.ListItemAllFields);

Expand Down
5 changes: 4 additions & 1 deletion Commands/Files/GetFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ protected override void ExecuteCmdlet()
{
Url = UrlUtility.Combine(webServerRelativeUrl, Url);
}
#if ONPREMISES
var folder = SelectedWeb.GetFolderByServerRelativeUrl(Url);

#else
var folder = SelectedWeb.GetFolderByServerRelativePath(ResourcePath.FromDecodedUrl(Url));
#endif
folder.EnsureProperties(RetrievalExpressions);

WriteObject(folder);
Expand Down
Loading

0 comments on commit 271dc09

Please sign in to comment.