🔍 Code Extractor

class TenantSettings

Maturity: 46

TenantSettings is a class that manages SharePoint tenant-level configuration properties, specifically corporate catalog settings.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/tenant/settings.py
Lines:
6 - 41
Complexity:
moderate

Purpose

This class provides an interface to interact with SharePoint tenant settings, allowing administrators to configure and manage the corporate catalog URL for a tenant. It inherits from Entity and provides methods to set, clear, and retrieve the corporate catalog URL. The class follows a fluent interface pattern where methods return self for method chaining. It integrates with SharePoint's service operations through the context object to execute remote operations.

Source Code

class TenantSettings(Entity):
    """Specifies the tenant properties."""

    def clear_corporate_catalog(self):
        """"""
        qry = ServiceOperationQuery(
            self, "ClearCorporateCatalog", None, None, None, None
        )
        self.context.add_query(qry)
        return self

    def set_corporate_catalog(self, url):
        """
        :param str url:
        """
        payload = {"url": url}
        qry = ServiceOperationQuery(
            self, "SetCorporateCatalog", None, payload, None, None
        )
        self.context.add_query(qry)
        return self

    @property
    def corporate_catalog_url(self):
        """Specifies the URL of the corporate catalog site collection.
        :rtype: str or None
        """
        return self.properties.get("CorporateCatalogUrl", None)

    @staticmethod
    def current(context):
        """
        Specifies the current instance for the SP.TenantSettings.
        :type context: office365.sharepoint.client_context.ClientContext
        """
        return TenantSettings(context, ResourcePath("SP.TenantSettings.Current"))

Parameters

Name Type Default Kind
bases Entity -

Parameter Details

context: A ClientContext instance that provides the connection and authentication context for SharePoint operations. This is required for all service operations and is inherited from the Entity base class.

resource_path: A ResourcePath object that specifies the location of the tenant settings resource in SharePoint. When using the static 'current' method, this is automatically set to 'SP.TenantSettings.Current'.

Return Value

The class constructor returns a TenantSettings instance. The 'current' static method returns a TenantSettings instance configured for the current tenant. The 'clear_corporate_catalog' and 'set_corporate_catalog' methods return self to enable method chaining. The 'corporate_catalog_url' property returns a string containing the URL of the corporate catalog site collection, or None if not set.

Class Interface

Methods

clear_corporate_catalog() -> TenantSettings

Purpose: Clears the corporate catalog URL setting for the tenant

Returns: Returns self (TenantSettings instance) to enable method chaining

set_corporate_catalog(url: str) -> TenantSettings

Purpose: Sets the corporate catalog URL for the tenant to the specified URL

Parameters:

  • url: A string containing the full URL of the corporate catalog site collection (e.g., 'https://tenant.sharepoint.com/sites/catalog')

Returns: Returns self (TenantSettings instance) to enable method chaining

corporate_catalog_url -> str | None property

Purpose: Retrieves the URL of the corporate catalog site collection

Returns: A string containing the corporate catalog URL, or None if not set or not yet loaded

current(context: ClientContext) -> TenantSettings static

Purpose: Factory method that returns the current TenantSettings instance for the specified SharePoint context

Parameters:

  • context: A ClientContext instance representing the authenticated connection to a SharePoint tenant

Returns: A TenantSettings instance configured to access the current tenant's settings

Attributes

Name Type Description Scope
context ClientContext Inherited from Entity base class. Stores the SharePoint client context used for executing queries and operations instance
properties dict Inherited from Entity base class. Dictionary containing the loaded property values from SharePoint, including CorporateCatalogUrl instance

Dependencies

  • office365.runtime.paths.resource_path
  • office365.runtime.queries.service_operation
  • office365.sharepoint.entity

Required Imports

from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity import Entity

Usage Example

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.tenant.administration.tenant_settings import TenantSettings

# Initialize SharePoint context
ctx = ClientContext('https://tenant.sharepoint.com').with_credentials(credentials)

# Get current tenant settings
tenant_settings = TenantSettings.current(ctx)

# Set corporate catalog URL
tenant_settings.set_corporate_catalog('https://tenant.sharepoint.com/sites/catalog')
ctx.execute_query()

# Retrieve the corporate catalog URL
tenant_settings = TenantSettings.current(ctx)
ctx.load(tenant_settings)
ctx.execute_query()
print(tenant_settings.corporate_catalog_url)

# Clear corporate catalog
tenant_settings.clear_corporate_catalog()
ctx.execute_query()

Best Practices

  • Always use the static 'current' method to obtain a TenantSettings instance rather than directly instantiating the class
  • Call ctx.execute_query() after setting or clearing the corporate catalog to commit changes to SharePoint
  • Use ctx.load() before accessing properties like corporate_catalog_url to ensure data is fetched from the server
  • Methods return self for fluent chaining, allowing multiple operations before executing the query
  • Ensure the authenticated user has tenant administrator permissions before attempting to modify settings
  • The context object must remain valid throughout the lifecycle of the TenantSettings instance
  • Properties are lazily loaded and may return None until explicitly loaded via ctx.load() and ctx.execute_query()

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class TenantAdminSettingsService 79.6% similar

    A service class for managing SharePoint Online tenant administration settings, providing access to tenant-level configuration and sharing status.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/tenant/administration/settings_service.py
  • class Office365Tenant 70.6% similar

    Represents a SharePoint Online tenant and provides administrative operations for managing tenant-level settings, CDN configurations, external users, themes, and user profile properties.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/tenant/management/office365_tenant.py
  • class ConnectionSettings 66.9% similar

    A SharePoint entity class representing connection settings for the Business Data Infrastructure Secure Store service.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/businessdata/infrastructure/securestore/connection_settings.py
  • class TenantAdminEndpoints 66.9% similar

    A SharePoint entity class representing tenant administration endpoints, providing access to Office 365 admin center endpoint information.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/tenant/administration/endpoints.py
  • class ServerSettings 66.2% similar

    ServerSettings is a SharePoint entity class that provides static methods for querying server-level properties and configurations such as checking if the server is SharePoint Online, retrieving blocked file extensions, and getting installed languages.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/server_settings.py
← Back to Browse