Skip to content

Commit

Permalink
Merge pull request #4680 from reshmee011/addcheckallowpb
Browse files Browse the repository at this point in the history
Refactor to handle AllowWebPropertyBagUpdateWhenDenyAddAndCustomizePagesIsEnabled
  • Loading branch information
KoenZomers authored Jan 22, 2025
2 parents 45ff5e5 + 10e2bc4 commit d8721ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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
Expand Down
37 changes: 23 additions & 14 deletions src/Commands/Web/SetPropertyBagValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d8721ed

Please sign in to comment.