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

Refactor to handle AllowWebPropertyBagUpdateWhenDenyAddAndCustomizePagesIsEnabled #4680

Merged
merged 3 commits into from
Jan 22, 2025
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Loading