From b3f23d99f3ced889ba2e82cbeb89cec2d0893560 Mon Sep 17 00:00:00 2001 From: reshmee011 Date: Sun, 12 Jan 2025 07:31:16 +0000 Subject: [PATCH 1/2] Refactor to handle AllowWebPropertyBagUpdateWhenDenyAddAndCustomizePagesIsEnabled --- src/Commands/Web/SetPropertyBagValue.cs | 37 +++++++++++++++---------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/Commands/Web/SetPropertyBagValue.cs b/src/Commands/Web/SetPropertyBagValue.cs index afeba8efd..702bfbd2a 100644 --- a/src/Commands/Web/SetPropertyBagValue.cs +++ b/src/Commands/Web/SetPropertyBagValue.cs @@ -36,25 +36,34 @@ protected override void ExecuteCmdlet() bool isScriptSettingUpdated = false; try { - WriteVerbose("Checking if the site is a no-script site"); + WriteVerbose("Checking if AllowWebPropertyBagUpdateWhenDenyAddAndCustomizePagesIsEnabled is set to true at the tenant level"); + var tenant = new Tenant(AdminContext); + AdminContext.Load(tenant); + AdminContext.Load(tenant, t => t.AllowWebPropertyBagUpdateWhenDenyAddAndCustomizePagesIsEnabled); + AdminContext.ExecuteQueryRetry(); + var web = ClientContext.Web; - web.EnsureProperties(w => w.Url, w => w.ServerRelativeUrl); - if (web.IsNoScriptSite()) + if (!tenant.AllowWebPropertyBagUpdateWhenDenyAddAndCustomizePagesIsEnabled) { - if (Force || ShouldContinue("The current site is a no-script site. Do you want to temporarily enable scripting on it to allow setting property bag value?", Properties.Resources.Confirm)) - { - WriteVerbose("Temporarily enabling scripting on the site"); - var tenant = new Tenant(AdminContext); - tenant.SetSiteProperties(web.Url, noScriptSite: false); - isScriptSettingUpdated = true; - } - else + WriteVerbose("Checking if the site is a no-script site"); + + web.EnsureProperties(w => w.Url, w => w.ServerRelativeUrl); + + if (web.IsNoScriptSite()) { - ThrowTerminatingError(new ErrorRecord(new Exception($"Site has NoScript enabled, this prevents setting some property bag values."), "NoScriptEnabled", ErrorCategory.InvalidOperation, this)); - return; + if (Force || ShouldContinue("The current site is a no-script site. Do you want to temporarily enable scripting on it to allow setting property bag value?", Properties.Resources.Confirm)) + { + WriteVerbose("Temporarily enabling scripting on the site"); + tenant.SetSiteProperties(web.Url, noScriptSite: false); + isScriptSettingUpdated = true; + } + else + { + ThrowTerminatingError(new ErrorRecord(new Exception($"Site has NoScript enabled, this prevents setting some property bag values."), "NoScriptEnabled", ErrorCategory.InvalidOperation, this)); + return; + } } } - if (!ParameterSpecified(nameof(Folder))) { if (!Indexed) From 10e2bc4c64f70c224af9b43519716aef9a801594 Mon Sep 17 00:00:00 2001 From: KoenZomers Date: Wed, 22 Jan 2025 19:08:14 +0100 Subject: [PATCH 2/2] Added changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21af96e3e..38c472d1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,7 +80,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - `Add-PnPApp` , `Publish-PnPApp` , `Remove-PnPApp` and `Unpublish-PnPApp` now support disabling script settings if tenant app catalog is a no-script site. - `Send-PnPMail` now throws a warning about the retirement of the SharePoint SendEmail API. - `Get-PnPCustomAction` now supports a completer for `-Identity` and uses the PnP Core SDK to return custom actions. -- `Set-PnPPropertyBagValue` and `Remove-PnPPropertyBagValue` now toggle the NoScript status of the site to allow setting/removing property bag values. +- `Set-PnPPropertyBagValue` and `Remove-PnPPropertyBagValue` now toggle the NoScript status of the site to allow setting/removing property bag values, but only if the tenant wide `AllowWebPropertyBagUpdateWhenDenyAddAndCustomizePagesIsEnabled` is not enabled [#4680](https://github.com/pnp/powershell/pull/4680) ### Fixed