🔍 Code Extractor

class SPSocialSwitch

Maturity: 45

A SharePoint utility class that provides methods to check whether social features (like following content) are enabled or disabled in a SharePoint environment.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/switch.py
Lines:
6 - 31
Complexity:
moderate

Purpose

SPSocialSwitch is a utility class that inherits from Entity and provides static methods to query SharePoint's social feature configuration. Its primary responsibility is to determine if social features like the 'Following' feature are enabled at both the tenant level and web level within a given SharePoint context. This class is used to conditionally enable or disable social functionality in SharePoint applications based on the current configuration.

Source Code

class SPSocialSwitch(Entity):
    """Provides methods to determine whether certain social features are enabled or disabled."""

    @staticmethod
    def is_following_feature_enabled(context):
        """
        Returns true if the SPSocial follow feature is enabled, taking into account the current context
        as appropriate. Specifically, if there is a SP.Web within the SP.RequestContext, this method will take into
        account whether the FollowingContent feature is activated within the SP.Web as well.
        Regardless of whether there is an SP.Web within the context, it will take into account if SPSocial
        is enabled at the tenant level.

        :type context: office365.sharepoint.client_context.ClientContext
        """
        binding_type = SPSocialSwitch(context)
        return_type = ClientResult(context)
        qry = ServiceOperationQuery(
            binding_type, "IsFollowingFeatureEnabled", None, None, None, return_type
        )
        qry.static = True
        context.add_query(qry)
        return return_type

    @property
    def entity_type_name(self):
        return "SP.Utilities.SPSocialSwitch"

Parameters

Name Type Default Kind
bases Entity -

Parameter Details

context: An instance of office365.sharepoint.client_context.ClientContext that represents the current SharePoint context. This context is used to execute queries against SharePoint and contains information about the current web, site, and tenant. The context parameter is required for the class to function and is used to determine feature availability at various levels (web and tenant).

Return Value

The class constructor returns an instance of SPSocialSwitch. The is_following_feature_enabled static method returns a ClientResult object that will contain a boolean value indicating whether the SPSocial follow feature is enabled. The ClientResult is a deferred result that gets populated after the query is executed through the context.

Class Interface

Methods

is_following_feature_enabled(context) -> ClientResult static

Purpose: Determines whether the SPSocial follow feature is enabled in the given SharePoint context, checking both tenant-level and web-level feature activation

Parameters:

  • context: office365.sharepoint.client_context.ClientContext instance representing the current SharePoint context

Returns: ClientResult object that will contain a boolean value indicating whether the following feature is enabled. The value is populated after calling context.execute_query()

entity_type_name -> str property

Purpose: Returns the SharePoint entity type name for this class, used internally by the Office365 SDK for type identification

Returns: String 'SP.Utilities.SPSocialSwitch' representing the SharePoint entity type

Attributes

Name Type Description Scope
entity_type_name str Property that returns the SharePoint entity type identifier 'SP.Utilities.SPSocialSwitch' 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

Usage Example

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.utilities.sp_social_switch import SPSocialSwitch

# Create SharePoint context with authentication
ctx = ClientContext('https://yourtenant.sharepoint.com/sites/yoursite')
ctx = ctx.with_credentials(UserCredential('username', 'password'))

# Check if following feature is enabled
result = SPSocialSwitch.is_following_feature_enabled(ctx)
ctx.execute_query()

if result.value:
    print('Following feature is enabled')
else:
    print('Following feature is disabled')

Best Practices

  • Always call ctx.execute_query() after calling is_following_feature_enabled to populate the ClientResult with the actual value
  • The is_following_feature_enabled method is static, so it can be called without instantiating the class
  • Ensure the ClientContext has proper authentication and permissions before querying feature status
  • The method checks both tenant-level and web-level feature activation, so results may vary depending on the context's web
  • Handle cases where the query might fail due to insufficient permissions or network issues
  • The ClientResult object's value property should only be accessed after execute_query() completes successfully

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class SocialFollowingManager 63.9% similar

    SocialFollowingManager manages a user's social following relationships in SharePoint, including followers, followed actors (users, documents, sites, tags), and follow suggestions.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/following/manager.py
  • class SPHelper 59.9% 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
  • class SocialRestFollowingManager 59.1% similar

    A SharePoint Social REST API manager class that provides methods for managing a user's list of followed actors, including users, documents, sites, and tags, as well as retrieving followers.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/following/rest_manager.py
  • class Utility_v1 58.3% similar

    A SharePoint utility class that extends Entity to provide access to SharePoint utility operations and services.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/permissions/utility.py
  • class SharingAbilityStatus 57.4% similar

    A data class representing the status of a specific sharing capability for the current user in SharePoint, including whether it's enabled and the reason if disabled.

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