class Tenant
Represents a SharePoint tenant.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/tenant/administration/tenant.py
69 - 667
moderate
Purpose
Represents a SharePoint tenant.
Source Code
class Tenant(Entity):
"""Represents a SharePoint tenant."""
def __init__(self, context):
static_path = ResourcePath(
"Microsoft.Online.SharePoint.TenantAdministration.Tenant"
)
super(Tenant, self).__init__(context, static_path)
def get_corporate_catalog_site(self):
"""Retrieves Corporate Catalog Site"""
settings = TenantSettings.current(self.context)
return_type = Site(self.context)
def _settings_loaded():
return_type.set_property("__siteUrl", settings.corporate_catalog_url)
settings.ensure_property("CorporateCatalogUrl", _settings_loaded)
return return_type
def get_chat_gpt_response(self):
""""""
return_type = ClientResult(self.context)
payload = {"requestOptions": ChatGptRequestOptions()}
qry = ServiceOperationQuery(
self, "GetChatGptResponse", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def delete_policy_definition(self, item_id):
"""
:param int item_id:
"""
qry = ServiceOperationQuery(
self, "DeletePolicyDefinition", None, {"itemId": item_id}
)
self.context.add_query(qry)
return self
def delete_recent_admin_action_report(self, report_id):
"""
:param int report_id:
"""
qry = ServiceOperationQuery(
self, "DeleteRecentAdminActionReport", None, {"reportId": report_id}
)
self.context.add_query(qry)
return self
def get_spo_tenant_all_web_templates(self):
return_type = SPOTenantWebTemplateCollection(self.context)
qry = ServiceOperationQuery(
self, "GetSPOTenantAllWebTemplates", None, None, None, return_type
)
self.context.add_query(qry)
return return_type
def get_onedrive_site_sharing_insights(self, query_mode):
return_type = ClientResult(self.context, OneDriveSiteSharingInsights())
payload = {"queryMode": query_mode}
qry = ServiceOperationQuery(
self, "GetOneDriveSiteSharingInsights", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def get_collaboration_insights_data(self):
""""""
return_type = ClientResult[CollaborationInsightsData](
self.context, CollaborationInsightsData()
)
qry = ServiceOperationQuery(
self, "GetCollaborationInsightsData", None, None, None, return_type
)
self.context.add_query(qry)
return return_type
def get_collaboration_insights_overview(self):
""""""
return_type = ClientResult[CollaborationInsightsData](
self.context, CollaborationInsightsOverview()
)
qry = ServiceOperationQuery(
self, "GetCollaborationInsightsOverview", None, None, None, return_type
)
self.context.add_query(qry)
return return_type
def render_recent_admin_actions(self):
return_type = ClientResult(self.context)
payload = {
"parameters": RenderListDataParameters(),
"overrideParameters": RenderListDataOverrideParameters(),
}
qry = ServiceOperationQuery(
self, "RenderRecentAdminActions", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def get_top_files_sharing_insights(self, query_mode):
"""
:param int query_mode:
"""
payload = {"queryMode": query_mode}
return_type = EntityCollection(self.context, TopFilesSharingInsights)
qry = ServiceOperationQuery(
self, "GetTopFilesSharingInsights", payload, None, None, return_type
)
self.context.add_query(qry)
return return_type
def get_site_thumbnail_logo(self, site_url):
# type: (str) -> ClientResult[AnyStr]
"""
:param str site_url:
"""
payload = {"siteUrl": site_url}
return_type = ClientResult(self.context)
qry = ServiceOperationQuery(
self, "GetSiteThumbnailLogo", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def get_home_site_url(self):
# type: () -> ClientResult[str]
""" """
return_type = ClientResult(self.context)
qry = ServiceOperationQuery(
self, "GetSPHSiteUrl", None, None, None, return_type
)
self.context.add_query(qry)
return return_type
def get_home_sites(self):
# type: () -> ClientResult[ClientValueCollection[HomeSitesDetails]]
return_type = ClientResult(
self.context,
ClientValueCollection(HomeSitesDetails), # pylint: disable=E1120
)
qry = ServiceOperationQuery(self, "GetHomeSites", None, None, None, return_type)
self.context.add_query(qry)
return return_type
def get_home_sites_details(self):
return_type = ClientResult(
self.context, ClientValueCollection(HomeSitesDetails)
)
qry = ServiceOperationQuery(
self, "GetHomeSitesDetails", None, None, None, return_type
)
self.context.add_query(qry)
return return_type
def remove_home_site(self, home_site_url):
"""
Remove home site
:param str home_site_url:
"""
payload = {"homeSiteUrl": home_site_url}
qry = ServiceOperationQuery(self, "RemoveHomeSite", None, payload)
self.context.add_query(qry)
return self
def has_valid_education_license(self):
""""""
return_type = ClientResult(self.context, bool())
qry = ServiceOperationQuery(
self, "HasValidEducationLicense", None, None, None, return_type
)
self.context.add_query(qry)
return return_type
def export_to_csv(self, view_xml=None):
"""
:param str view_xml:
"""
return_type = ClientResult(self.context)
payload = {"viewXml": view_xml}
qry = ServiceOperationQuery(
self, "ExportToCSV", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def render_policy_report(self):
""""""
return_type = ClientResult(self.context, bytes())
payload = {
"parameters": RenderListDataParameters(),
"overrideParameters": RenderListDataOverrideParameters(),
}
qry = ServiceOperationQuery(
self, "RenderPolicyReport", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
@staticmethod
def from_url(admin_site_url):
"""
:type admin_site_url: str
"""
from office365.sharepoint.client_context import ClientContext
admin_client = ClientContext(admin_site_url)
return Tenant(admin_client)
def get_lock_state_by_id(self, site_id):
"""
:param str site_id:
"""
return self.sites.get_lock_state_by_id(site_id)
def hub_sites(self, site_url):
pass
def check_tenant_intune_license(self):
"""
Checks whether a tenant has the Intune license.
"""
return_type = ClientResult(self.context) # type: ClientResult[bool]
qry = ServiceOperationQuery(
self, "CheckTenantIntuneLicense", None, None, None, return_type
)
self.context.add_query(qry)
return return_type
def check_tenant_licenses(self, licenses):
"""
Checks whether a tenant has the specified licenses.
:param list[str] licenses: The list of licenses to check for.
"""
return_type = ClientResult(self.context, bool())
params = ClientValueCollection(str, licenses)
qry = ServiceOperationQuery(
self, "CheckTenantLicenses", None, params, "licenses", return_type
)
self.context.add_query(qry)
return return_type
def get_site(self, site_url):
# type: (str) -> ListItem
return self._aggregated_site_collections_list.items.single(
"SiteUrl eq '{0}'".format(site_url.rstrip("/"))
).get()
def get_sites_by_state(self, states=None):
"""
:param list[int] states:
"""
return_type = ListItemCollection(
self.context,
ResourcePath("items", self._aggregated_site_collections_list.resource_path),
)
payload = {"states": states}
qry = ServiceOperationQuery(
self, "GetSitesByState", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def _poll_site_status(self, site_url, polling_interval_secs):
states = [0, 1, 2]
time.sleep(polling_interval_secs)
def _after(items):
completed = (
len(
[
item
for item in items
if item.properties.get("SiteUrl") == site_url
]
)
> 0
)
if not completed:
self._poll_site_status(site_url, polling_interval_secs)
self.get_sites_by_state(states).after_execute(_after, execute_first=True)
def get_site_health_status(self, source_url):
"""
:type source_url: str
"""
result = ClientResult(self.context, PortalHealthStatus())
params = {"sourceUrl": source_url}
qry = ServiceOperationQuery(
self, "GetSiteHealthStatus", None, params, None, result
)
self.context.add_query(qry)
return result
def get_site_administrators(self, site_id, return_type=None):
"""
Gets site collection administrators
:type site_id: str
:type return_type: ClientResult
"""
if return_type is None:
return_type = ClientResult(
self.context, ClientValueCollection(SiteAdministratorsInfo)
)
payload = {"siteId": site_id}
qry = ServiceOperationQuery(
self, "GetSiteAdministrators", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def get_site_secondary_administrators(self, site_id):
# type: (str) -> ClientResult[ClientValueCollection[SecondaryAdministratorsInfo]]
"""
Gets site collection administrators
:param str site_id: Site object or identifier
"""
return_type = ClientResult(
self.context, ClientValueCollection(SecondaryAdministratorsInfo)
)
payload = {
"secondaryAdministratorsFieldsData": SecondaryAdministratorsFieldsData(
site_id
)
}
qry = ServiceOperationQuery(
self, "GetSiteSecondaryAdministrators", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def set_site_secondary_administrators(self, site_id, emails=None, names=None):
"""
Sets site collection administrators
:type names: list[str] or None
:type emails: list[str]
:type site_id: str
"""
payload = {
"secondaryAdministratorsFieldsData": SecondaryAdministratorsFieldsData(
site_id, emails, names
)
}
qry = ServiceOperationQuery(
self, "SetSiteSecondaryAdministrators", None, payload, None, None
)
self.context.add_query(qry)
return self
def register_hub_site(self, site_url):
# type: (str) -> HubSiteProperties
"""Registers an existing site as a hub site."""
return_type = HubSiteProperties(self.context)
params = {"siteUrl": site_url}
qry = ServiceOperationQuery(
self, "RegisterHubSite", None, params, None, return_type
)
self.context.add_query(qry)
return return_type
def unregister_hub_site(self, site_url):
# type: (str) -> Self
"""Unregisters a hub site so that it is no longer a hub site."""
payload = {"siteUrl": site_url}
qry = ServiceOperationQuery(
self, "UnregisterHubSite", None, payload, None, None
)
self.context.add_query(qry)
return self
def create_site(self, url, owner, title=None):
"""Queues a site collection for creation with the specified properties.
:param str title: Sets the new site’s title.
:param str url: Sets the new site’s URL.
:param str owner: Sets the login name of the owner of the new site.
"""
return_type = SpoOperation(self.context)
payload = {
"siteCreationProperties": SiteCreationProperties(
title=title, url=url, owner=owner
)
}
qry = ServiceOperationQuery(
self, "CreateSite", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def create_site_sync(self, url, owner, title=None):
"""Creates a site collection
:param str title: Sets the new site’s title.
:param str url: Sets the new site’s URL.
:param str owner: Sets the login name of the owner of the new site.
"""
return_type = Site(self.context)
return_type.set_property("__siteUrl", url)
def _ensure_status(op):
# type: (SpoOperation) -> None
if not op.is_complete:
self._poll_site_status(url, op.polling_interval_secs)
self.create_site(url, owner, title).after_execute(_ensure_status)
return return_type
def remove_site(self, site_url):
"""Deletes the site with the specified URL
:param str site_url: A string representing the URL of the site.
"""
return_type = SpoOperation(self.context)
params = {"siteUrl": site_url}
qry = ServiceOperationQuery(self, "removeSite", None, params, None, return_type)
self.context.add_query(qry)
return return_type
def remove_deleted_site(self, site_url):
"""Permanently removes the specified deleted site from the recycle bin.
:param str site_url: A string representing the URL of the site.
"""
result = SpoOperation(self.context)
qry = ServiceOperationQuery(
self, "RemoveDeletedSite", [site_url], None, None, result
)
self.context.add_query(qry)
return result
def reorder_home_sites(self, home_sites_site_ids):
"""
:param list[str] home_sites_site_ids:
"""
payload = {"homeSitesSiteIds": home_sites_site_ids}
return_type = ClientResult(
self.context, ClientValueCollection(HomeSitesDetails)
)
qry = ServiceOperationQuery(
self, "ReorderHomeSites", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def restore_deleted_site(self, site_url):
"""Restores deleted site with the specified URL
:param str site_url: A string representing the URL of the site.
"""
return_type = SpoOperation(self.context)
qry = ServiceOperationQuery(
self, "RestoreDeletedSite", [site_url], None, None, return_type
)
self.context.add_query(qry)
return return_type
def get_site_properties_by_url(self, url, include_detail=False):
# type: (str, bool) -> SiteProperties
"""
:param str url: A string that represents the site URL.
:param bool include_detail: A Boolean value that indicates whether to include all of the SPSite properties.
"""
return_type = SiteProperties(self.context)
return_type.set_property("Url", url, False)
self.sites.add_child(return_type)
payload = {"url": url, "includeDetail": include_detail}
qry = ServiceOperationQuery(
self, "getSitePropertiesByUrl", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def get_site_properties_from_sharepoint_by_filters(
self, _filter=None, start_index=None, include_detail=False
):
# type: (str, str, bool) -> SitePropertiesCollection
""" """
return_type = SitePropertiesCollection(self.context)
payload = {
"speFilter": SitePropertiesEnumerableFilter(
_filter, start_index, include_detail
)
}
qry = ServiceOperationQuery(
self,
"getSitePropertiesFromSharePointByFilters",
None,
payload,
None,
return_type,
)
self.context.add_query(qry)
return return_type
def connect_site_to_hub_site_by_id(self, site_url, hub_site_id):
# type: (str, str) -> Self
"""Connects Site to Hub Site"""
params = {"siteUrl": site_url, "hubSiteId": hub_site_id}
qry = ServiceOperationQuery(
self, "ConnectSiteToHubSiteById", None, params, None, None
)
self.context.add_query(qry)
return self
def send_email(self, site_url):
# type: (str) -> ClientResult[bool]
""" """
return_type = ClientResult(self.context, bool())
payload = {"siteUrl": site_url}
qry = ServiceOperationQuery(self, "SendEmail", None, payload, None, return_type)
self.context.add_query(qry)
return return_type
@property
def ai_builder_enabled(self):
# type: () -> Optional[str]
"""Gets the value if the AIBuilder settings should be shown in the tenant"""
return self.properties.get("AIBuilderEnabled", None)
@property
def ai_builder_site_info_list(self):
""""""
return self.properties.get(
"AIBuilderSiteInfoList", ClientValueCollection(SiteInfoForSitePicker)
)
@property
def _aggregated_site_collections_list(self):
return self.context.web.lists.get_by_title(
"DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS"
)
@property
def allow_comments_text_on_email_enabled(self):
# type: () -> Optional[bool]
"""
When enabled, the email notification that a user receives when is mentioned,
includes the surrounding document context
"""
return self.properties.get("AllowCommentsTextOnEmailEnabled", None)
@property
def allow_everyone_except_external_users_claim_in_private_site(self):
# type: () -> Optional[bool]
"""
Gets the value if EveryoneExceptExternalUsers claim is allowed or not in people picker in a private group site.
False value means it is blocked
"""
return self.properties.get(
"AllowEveryoneExceptExternalUsersClaimInPrivateSite", None
)
@property
def allow_editing(self):
# type: () -> Optional[bool]
"""
Prevents users from editing Office files in the browser and copying and pasting Office file contents
out of the browser window.
"""
return self.properties.get("AllowEditing", None)
@property
def default_content_center_site(self):
""""""
return self.properties.get("DefaultContentCenterSite", SiteInfoForSitePicker())
@property
def root_site_url(self):
# type: () -> Optional[str]
"""The tenant's root site url"""
return self.properties.get("RootSiteUrl", None)
@property
def sites(self):
"""Gets a collection of sites."""
return self.properties.get(
"sites",
SitePropertiesCollection(
self.context, ResourcePath("sites", self.resource_path)
),
)
@property
def syntex_billing_subscription_settings(self):
""""""
return self.properties.get(
"SyntexBillingSubscriptionSettings", SyntexBillingContext()
)
@property
def entity_type_name(self):
return "Microsoft.Online.SharePoint.TenantAdministration.Tenant"
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
bases: Parameter of type Entity
Return Value
Returns unspecified type
Class Interface
Methods
__init__(self, context)
Purpose: Internal method: init
Parameters:
context: Parameter
Returns: None
get_corporate_catalog_site(self)
Purpose: Retrieves Corporate Catalog Site
Returns: None
get_chat_gpt_response(self)
Purpose: Retrieves chat gpt response
Returns: None
delete_policy_definition(self, item_id)
Purpose: :param int item_id:
Parameters:
item_id: Parameter
Returns: None
delete_recent_admin_action_report(self, report_id)
Purpose: :param int report_id:
Parameters:
report_id: Parameter
Returns: None
get_spo_tenant_all_web_templates(self)
Purpose: Retrieves spo tenant all web templates
Returns: None
get_onedrive_site_sharing_insights(self, query_mode)
Purpose: Retrieves onedrive site sharing insights
Parameters:
query_mode: Parameter
Returns: None
get_collaboration_insights_data(self)
Purpose: Retrieves collaboration insights data
Returns: None
get_collaboration_insights_overview(self)
Purpose: Retrieves collaboration insights overview
Returns: None
render_recent_admin_actions(self)
Purpose: Performs render recent admin actions
Returns: None
get_top_files_sharing_insights(self, query_mode)
Purpose: :param int query_mode:
Parameters:
query_mode: Parameter
Returns: None
get_site_thumbnail_logo(self, site_url)
Purpose: :param str site_url:
Parameters:
site_url: Parameter
Returns: None
get_home_site_url(self)
Purpose: Retrieves home site url
Returns: None
get_home_sites(self)
Purpose: Retrieves home sites
Returns: None
get_home_sites_details(self)
Purpose: Retrieves home sites details
Returns: None
remove_home_site(self, home_site_url)
Purpose: Remove home site :param str home_site_url:
Parameters:
home_site_url: Parameter
Returns: None
has_valid_education_license(self)
Purpose: Checks if valid education license
Returns: None
export_to_csv(self, view_xml)
Purpose: :param str view_xml:
Parameters:
view_xml: Parameter
Returns: None
render_policy_report(self)
Purpose: Performs render policy report
Returns: None
from_url(admin_site_url)
static
Purpose: :type admin_site_url: str
Parameters:
admin_site_url: Parameter
Returns: None
get_lock_state_by_id(self, site_id)
Purpose: :param str site_id:
Parameters:
site_id: Parameter
Returns: None
hub_sites(self, site_url)
Purpose: Performs hub sites
Parameters:
site_url: Parameter
Returns: None
check_tenant_intune_license(self)
Purpose: Checks whether a tenant has the Intune license.
Returns: None
check_tenant_licenses(self, licenses)
Purpose: Checks whether a tenant has the specified licenses. :param list[str] licenses: The list of licenses to check for.
Parameters:
licenses: Parameter
Returns: None
get_site(self, site_url)
Purpose: Retrieves site
Parameters:
site_url: Parameter
Returns: None
get_sites_by_state(self, states)
Purpose: :param list[int] states:
Parameters:
states: Parameter
Returns: None
_poll_site_status(self, site_url, polling_interval_secs)
Purpose: Internal method: poll site status
Parameters:
site_url: Parameterpolling_interval_secs: Parameter
Returns: None
get_site_health_status(self, source_url)
Purpose: :type source_url: str
Parameters:
source_url: Parameter
Returns: None
get_site_administrators(self, site_id, return_type)
Purpose: Gets site collection administrators :type site_id: str :type return_type: ClientResult
Parameters:
site_id: Parameterreturn_type: Parameter
Returns: See docstring for return details
get_site_secondary_administrators(self, site_id)
Purpose: Gets site collection administrators :param str site_id: Site object or identifier
Parameters:
site_id: Parameter
Returns: None
set_site_secondary_administrators(self, site_id, emails, names)
Purpose: Sets site collection administrators :type names: list[str] or None :type emails: list[str] :type site_id: str
Parameters:
site_id: Parameteremails: Parameternames: Parameter
Returns: None
register_hub_site(self, site_url)
Purpose: Registers an existing site as a hub site.
Parameters:
site_url: Parameter
Returns: None
unregister_hub_site(self, site_url)
Purpose: Unregisters a hub site so that it is no longer a hub site.
Parameters:
site_url: Parameter
Returns: None
create_site(self, url, owner, title)
Purpose: Queues a site collection for creation with the specified properties. :param str title: Sets the new site’s title. :param str url: Sets the new site’s URL. :param str owner: Sets the login name of the owner of the new site.
Parameters:
url: Parameterowner: Parametertitle: Parameter
Returns: None
create_site_sync(self, url, owner, title)
Purpose: Creates a site collection :param str title: Sets the new site’s title. :param str url: Sets the new site’s URL. :param str owner: Sets the login name of the owner of the new site.
Parameters:
url: Parameterowner: Parametertitle: Parameter
Returns: None
remove_site(self, site_url)
Purpose: Deletes the site with the specified URL :param str site_url: A string representing the URL of the site.
Parameters:
site_url: Parameter
Returns: None
remove_deleted_site(self, site_url)
Purpose: Permanently removes the specified deleted site from the recycle bin. :param str site_url: A string representing the URL of the site.
Parameters:
site_url: Parameter
Returns: None
reorder_home_sites(self, home_sites_site_ids)
Purpose: :param list[str] home_sites_site_ids:
Parameters:
home_sites_site_ids: Parameter
Returns: None
restore_deleted_site(self, site_url)
Purpose: Restores deleted site with the specified URL :param str site_url: A string representing the URL of the site.
Parameters:
site_url: Parameter
Returns: None
get_site_properties_by_url(self, url, include_detail)
Purpose: :param str url: A string that represents the site URL. :param bool include_detail: A Boolean value that indicates whether to include all of the SPSite properties.
Parameters:
url: Parameterinclude_detail: Parameter
Returns: None
get_site_properties_from_sharepoint_by_filters(self, _filter, start_index, include_detail)
Purpose: Retrieves site properties from sharepoint by filters
Parameters:
_filter: Parameterstart_index: Parameterinclude_detail: Parameter
Returns: None
connect_site_to_hub_site_by_id(self, site_url, hub_site_id)
Purpose: Connects Site to Hub Site
Parameters:
site_url: Parameterhub_site_id: Parameter
Returns: None
send_email(self, site_url)
Purpose: Performs send email
Parameters:
site_url: Parameter
Returns: None
ai_builder_enabled(self)
property
Purpose: Gets the value if the AIBuilder settings should be shown in the tenant
Returns: None
ai_builder_site_info_list(self)
property
Purpose: Performs ai builder site info list
Returns: None
_aggregated_site_collections_list(self)
property
Purpose: Internal method: aggregated site collections list
Returns: None
allow_comments_text_on_email_enabled(self)
property
Purpose: When enabled, the email notification that a user receives when is mentioned, includes the surrounding document context
Returns: None
allow_everyone_except_external_users_claim_in_private_site(self)
property
Purpose: Gets the value if EveryoneExceptExternalUsers claim is allowed or not in people picker in a private group site. False value means it is blocked
Returns: None
allow_editing(self)
property
Purpose: Prevents users from editing Office files in the browser and copying and pasting Office file contents out of the browser window.
Returns: None
default_content_center_site(self)
property
Purpose: Performs default content center site
Returns: None
root_site_url(self)
property
Purpose: The tenant's root site url
Returns: None
sites(self)
property
Purpose: Gets a collection of sites.
Returns: None
syntex_billing_subscription_settings(self)
property
Purpose: Performs syntex billing subscription settings
Returns: None
entity_type_name(self)
property
Purpose: Performs entity type name
Returns: None
Required Imports
import time
from typing import AnyStr
from typing import Optional
from typing_extensions import Self
from office365.runtime.client_result import ClientResult
Usage Example
# Example usage:
# result = Tenant(bases)
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class Office365Tenant 71.5% similar
-
class TenantAppInstance 67.4% similar
-
class TenantAppUtility 66.5% similar
-
class TenantSettings 64.9% similar
-
class TenantCdnUrl 63.3% similar