🔍 Code Extractor

class SiteSharingReportHelper

Maturity: 38

A helper class for managing SharePoint site sharing reports, providing static methods to create, cancel, and retrieve capabilities of sharing report jobs.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sharing/site_sharing_report_helper.py
Lines:
12 - 69
Complexity:
moderate

Purpose

SiteSharingReportHelper is a utility class that interfaces with SharePoint's sharing report API. It provides static methods to manage sharing report jobs for SharePoint sites and folders, including creating new report jobs, canceling existing jobs, and querying the site's sharing report capabilities. This class extends the Entity base class and is designed to work with the office365 SharePoint client context to execute service operations.

Source Code

class SiteSharingReportHelper(Entity):
    @staticmethod
    def cancel_sharing_report_job(context):
        """
        :type context: office365.sharepoint.client_context.ClientContext
        """
        return_type = ClientResult(context, SiteSharingReportStatus())
        binding_type = SiteSharingReportHelper(context)
        qry = ServiceOperationQuery(
            binding_type, "CancelSharingReportJob", None, None, None, return_type, True
        )
        context.add_query(qry)
        return return_type

    @staticmethod
    def create_sharing_report_job(context, web_url, folder_url):
        """
        :type context: office365.sharepoint.client_context.ClientContext
        :param str web_url:
        :param str folder_url:
        """
        return_type = ClientResult(context, SiteSharingReportStatus())
        payload = {"webUrl": web_url, "folderUrl": folder_url}
        binding_type = SiteSharingReportHelper(context)
        qry = ServiceOperationQuery(
            binding_type,
            "CreateSharingReportJob",
            None,
            payload,
            None,
            return_type,
            True,
        )
        context.add_query(qry)
        return return_type

    @staticmethod
    def get_site_sharing_report_capabilities(context):
        """
        :type context: office365.sharepoint.client_context.ClientContext
        """
        return_type = ClientResult(context, SiteSharingReportCapabilities())
        binding_type = SiteSharingReportHelper(context)
        qry = ServiceOperationQuery(
            binding_type,
            "GetSiteSharingReportCapabilities",
            None,
            None,
            None,
            return_type,
            True,
        )
        context.add_query(qry)
        return return_type

    @property
    def entity_type_name(self):
        return "SP.Sharing.SiteSharingReportHelper"

Parameters

Name Type Default Kind
bases Entity -

Parameter Details

context: An instance of office365.sharepoint.client_context.ClientContext that provides the connection and authentication context for SharePoint operations. This is required for all static methods to execute queries against the SharePoint service.

Return Value

The class constructor returns an instance of SiteSharingReportHelper (inheriting from Entity). The static methods return ClientResult objects containing either SiteSharingReportStatus (for cancel_sharing_report_job and create_sharing_report_job) or SiteSharingReportCapabilities (for get_site_sharing_report_capabilities). These ClientResult objects are asynchronous result containers that will be populated when the context executes the queued queries.

Class Interface

Methods

cancel_sharing_report_job(context) -> ClientResult[SiteSharingReportStatus] static

Purpose: Cancels an existing sharing report job for the SharePoint site

Parameters:

  • context: ClientContext instance providing the SharePoint connection and authentication context

Returns: ClientResult object containing SiteSharingReportStatus that indicates the cancellation status. The actual value is available after calling context.execute_query()

create_sharing_report_job(context, web_url: str, folder_url: str) -> ClientResult[SiteSharingReportStatus] static

Purpose: Creates a new sharing report job for a specified SharePoint web and folder

Parameters:

  • context: ClientContext instance providing the SharePoint connection and authentication context
  • web_url: The full URL of the SharePoint web/site where the report should be generated
  • folder_url: The server-relative or absolute URL of the folder to generate the sharing report for

Returns: ClientResult object containing SiteSharingReportStatus that provides information about the created report job. The actual value is available after calling context.execute_query()

get_site_sharing_report_capabilities(context) -> ClientResult[SiteSharingReportCapabilities] static

Purpose: Retrieves the sharing report capabilities available for the SharePoint site

Parameters:

  • context: ClientContext instance providing the SharePoint connection and authentication context

Returns: ClientResult object containing SiteSharingReportCapabilities that describes what sharing report features are available for the site. The actual value is available after calling context.execute_query()

entity_type_name() -> str property

Purpose: Returns the SharePoint entity type name for this helper class

Returns: String 'SP.Sharing.SiteSharingReportHelper' representing the SharePoint entity type

Attributes

Name Type Description Scope
_entity_type_name str Internal storage for the SharePoint entity type name, accessed via the entity_type_name property instance

Dependencies

  • office365-runtime
  • office365-sharepoint

Required Imports

from office365.runtime.client_result import ClientResult
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity import Entity
from office365.sharepoint.sharing.reports.site_capabilities import SiteSharingReportCapabilities
from office365.sharepoint.sharing.site_sharing_report_status import SiteSharingReportStatus

Usage Example

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.sharing.site_sharing_report_helper import SiteSharingReportHelper

# Initialize SharePoint context with credentials
ctx = ClientContext('https://yourtenant.sharepoint.com/sites/yoursite').with_credentials(user_credentials)

# Check site sharing report capabilities
capabilities_result = SiteSharingReportHelper.get_site_sharing_report_capabilities(ctx)
ctx.execute_query()
print(f"Capabilities: {capabilities_result.value}")

# Create a sharing report job for a specific folder
web_url = 'https://yourtenant.sharepoint.com/sites/yoursite'
folder_url = '/sites/yoursite/Shared Documents/MyFolder'
report_status = SiteSharingReportHelper.create_sharing_report_job(ctx, web_url, folder_url)
ctx.execute_query()
print(f"Report Job Status: {report_status.value}")

# Cancel the sharing report job if needed
cancel_result = SiteSharingReportHelper.cancel_sharing_report_job(ctx)
ctx.execute_query()
print(f"Cancel Status: {cancel_result.value}")

Best Practices

  • Always call ctx.execute_query() after invoking any static method to execute the queued service operations
  • The class is designed to be used via static methods only; instantiation is handled internally by the static methods
  • Ensure the ClientContext has appropriate permissions before attempting to create or cancel sharing reports
  • The return values are ClientResult objects that contain the actual results in their 'value' property after execute_query() is called
  • Multiple operations can be queued before calling execute_query() to batch requests
  • Handle potential exceptions from execute_query() as network or permission issues may occur
  • The web_url and folder_url parameters in create_sharing_report_job must be valid SharePoint URLs
  • This class follows the SharePoint REST API pattern where operations are queued and executed in batch

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class SiteSharingReportStatus 76.3% similar

    SiteSharingReportStatus is a data transfer object class that represents the status of a site sharing report in Microsoft 365/SharePoint operations.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sharing/site_sharing_report_status.py
  • class SiteSharingReportCapabilities 75.7% similar

    SiteSharingReportCapabilities is a data transfer object class that inherits from ClientValue, representing capabilities related to site sharing reports in Office 365/SharePoint.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sharing/reports/site_capabilities.py
  • class ObjectSharingInformation 70.6% similar

    A class that provides comprehensive information about the sharing state of SharePoint securable objects (documents, list items, sites), including permissions, sharing links, and user access details.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sharing/object_sharing_information.py
  • class DocumentSharingManager 67.5% similar

    A SharePoint document sharing manager class that provides static methods for managing document permissions, sharing settings, and shared views in SharePoint.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sharing/document_manager.py
  • class SPHelper 67.4% similar

    SPHelper is a utility class for SharePoint directory operations, providing static methods to check group membership, site availability, retrieve group members/owners, and manage external members.

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