class SPSocialSwitch
A SharePoint utility class that provides methods to check whether social features (like following content) are enabled or disabled in a SharePoint environment.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/social/switch.py
6 - 31
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-runtimeoffice365-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
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class SocialFollowingManager 63.9% similar
-
class SPHelper 59.9% similar
-
class SocialRestFollowingManager 59.1% similar
-
class Utility_v1 58.3% similar
-
class SharingAbilityStatus 57.4% similar