-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathallow_custom_script.py
More file actions
31 lines (26 loc) · 1.64 KB
/
Copy pathallow_custom_script.py
File metadata and controls
31 lines (26 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
Allow or prevent custom script
As a Global Administrator or SharePoint Administrator in Microsoft 365, you can allow custom script as a way
of letting users change the look, feel, and behavior of sites and pages to meet organizational objectives or
individual needs. If you allow custom script, all users who have "Add and Customize Pages" permission to a site
or page can add any script they want.
(By default, users who create sites are site owners and therefore have this permission.)
Demonstrates how to determine whether custom script on SharePoint site is enabled and enable it if disabled
https://learn.microsoft.com/en-us/sharepoint/allow-or-prevent-custom-script
"""
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.tenant.administration.deny_add_and_customize_pages_status import (
DenyAddAndCustomizePagesStatus,
)
from tests import test_admin_credentials, test_admin_site_url, test_team_site_url
client = ClientContext(test_admin_site_url).with_credentials(test_admin_credentials)
site_props = client.tenant.get_site_properties_by_url(test_team_site_url, True).execute_query()
if site_props.deny_add_and_customize_pages == DenyAddAndCustomizePagesStatus.Disabled:
print(f"Enabling custom script on site: {test_team_site_url}...")
site_props.deny_add_and_customize_pages = DenyAddAndCustomizePagesStatus.Enabled
site_props.update().execute_query()
print("[Ok] Updated")
elif site_props.deny_add_and_customize_pages == DenyAddAndCustomizePagesStatus.Enabled:
print(f"[Skipping] Custom script has already been allowed on site: {test_team_site_url}")
else:
print("Unknown status detected")