class GroupSiteManager
GroupSiteManager is a client object class that manages SharePoint group sites and Microsoft Teams operations, providing methods to create, delete, and query group sites and teams.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/portal/groups/site_manager.py
16 - 208
complex
Purpose
This class serves as a manager for SharePoint group sites and Microsoft Teams integration. It provides comprehensive functionality for creating modern SharePoint sites (group-connected sites), managing teams, querying team channels, checking user permissions, and retrieving team membership information. It acts as a service layer that communicates with SharePoint's REST API through service operation queries.
Source Code
class GroupSiteManager(ClientObject):
def __init__(self, context, resource_path=None):
if resource_path is None:
resource_path = ResourcePath("GroupSiteManager")
super(GroupSiteManager, self).__init__(context, resource_path)
def can_user_create_group(self):
return_type = ClientResult(self.context, bool())
qry = ServiceOperationQuery(
self, "CanUserCreateGroup", None, None, None, return_type
)
self.context.add_query(qry)
return return_type
def create_group_for_site(
self, display_name, alias, is_public=None, optional_params=None
):
"""
Create a modern site
:param str display_name:
:param str alias:
:param bool or None is_public:
:param office365.sharepoint.portal.group_creation_params.GroupCreationParams or None optional_params:
"""
payload = {
"displayName": display_name,
"alias": alias,
"isPublic": is_public,
"optionalParams": optional_params,
}
return_type = ClientResult(self.context, GroupSiteInfo())
qry = ServiceOperationQuery(
self, "CreateGroupForSite", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def create_group_ex(self, display_name, alias, is_public, optional_params=None):
"""
Creates a modern site
:param str display_name:
:param str alias:
:param bool is_public:
:param office365.sharepoint.portal.group_creation_params.GroupCreationParams or None optional_params:
"""
payload = GroupCreationInformation(
display_name, alias, is_public, optional_params
)
return_type = ClientResult(self.context, GroupSiteInfo())
qry = ServiceOperationQuery(
self, "CreateGroupEx", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def delete(self, site_url):
"""
Deletes a SharePoint Team site
:type site_url: str
"""
payload = {"siteUrl": site_url}
qry = ServiceOperationQuery(self, "Delete", None, payload)
self.context.add_query(qry)
return self
def ensure_team_for_group(self):
return_type = ClientResult(self.context)
qry = ServiceOperationQuery(
self, "EnsureTeamForGroup", None, None, None, return_type
)
self.context.add_query(qry)
return return_type
def get_group_creation_context(self):
return_type = ClientResult(self.context, GroupCreationContext())
qry = ServiceOperationQuery(
self, "GetGroupCreationContext", None, None, None, return_type
)
self.context.add_query(qry)
return return_type
def get_status(self, group_id):
"""Get the status of a SharePoint site
:type group_id: str
"""
return_type = ClientResult(self.context, GroupSiteInfo())
qry = ServiceOperationQuery(
self, "GetSiteStatus", None, {"groupId": group_id}, None, return_type
)
self.context.add_query(qry)
def _construct_status_request(request):
request.method = HttpMethod.Get
request.url += "?groupId='{0}'".format(group_id)
self.context.before_execute(_construct_status_request)
return return_type
def get_current_user_joined_teams(
self, get_logo_data=False, force_cache_update=False
):
"""
Get the teams in Microsoft Teams that the current user is a direct member of.
:type get_logo_data: bool
:type force_cache_update: bool
"""
result = ClientResult(self.context, str())
payload = {"getLogoData": get_logo_data, "forceCacheUpdate": force_cache_update}
qry = ServiceOperationQuery(
self, "GetCurrentUserJoinedTeams", None, payload, None, result
)
self.context.add_query(qry)
return result
def get_current_user_shared_channel_member_groups(self):
return_type = ClientResult(self.context)
qry = ServiceOperationQuery(
self,
"GetCurrentUserSharedChannelMemberGroups",
None,
None,
None,
return_type,
)
self.context.add_query(qry)
return return_type
def get_team_channels(self, team_id, use_staging_endpoint=False):
"""
:param str team_id:
:param bool use_staging_endpoint:
"""
return_type = ClientResult(self.context)
payload = {"teamId": team_id, "useStagingEndpoint": use_staging_endpoint}
qry = ServiceOperationQuery(
self, "GetTeamChannels", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def get_team_channels_direct(self, team_id):
"""
:param str team_id:
"""
return_type = ClientResult(self.context, str())
payload = {
"teamId": team_id,
}
qry = ServiceOperationQuery(
self, "GetTeamChannelsDirect", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
def notebook(self, group_id):
"""
:param str group_id:
"""
return_type = ClientResult(self.context, str())
payload = {"groupId": group_id}
qry = ServiceOperationQuery(self, "Notebook", None, payload, None, return_type)
self.context.add_query(qry)
return return_type
def recent_and_joined_teams(
self,
include_recent=None,
include_teams=None,
include_pinned=None,
existing_joined_teams_data=None,
):
"""
:param bool include_recent:
:param bool include_teams:
:param bool include_pinned:
:param str existing_joined_teams_data:
"""
return_type = ClientResult(self.context, RecentAndJoinedTeamsResponse())
payload = {
"includeRecent": include_recent,
"includeTeams": include_teams,
"includePinned": include_pinned,
"existingJoinedTeamsData": existing_joined_teams_data,
}
qry = ServiceOperationQuery(
self, "RecentAndJoinedTeams", None, payload, None, return_type
)
self.context.add_query(qry)
return return_type
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
ClientObject | - |
Parameter Details
context: The client context object that manages the connection to SharePoint and handles query execution. This is required for all API operations and maintains authentication state.
resource_path: Optional ResourcePath object specifying the API endpoint path. If not provided, defaults to 'GroupSiteManager'. This determines the base URL for all service operations.
Return Value
The constructor returns a GroupSiteManager instance. Most methods return ClientResult objects that will contain the result data after query execution (e.g., GroupSiteInfo, bool, str). Some methods return self for method chaining. Results are populated asynchronously when context.execute_query() is called.
Class Interface
Methods
__init__(self, context, resource_path=None)
Purpose: Initializes the GroupSiteManager with a client context and optional resource path
Parameters:
context: Client context for SharePoint operationsresource_path: Optional ResourcePath object, defaults to 'GroupSiteManager'
Returns: GroupSiteManager instance
can_user_create_group(self) -> ClientResult[bool]
Purpose: Checks if the current user has permission to create group sites
Returns: ClientResult containing a boolean indicating if user can create groups
create_group_for_site(self, display_name: str, alias: str, is_public: bool = None, optional_params: GroupCreationParams = None) -> ClientResult[GroupSiteInfo]
Purpose: Creates a modern SharePoint group site with specified parameters
Parameters:
display_name: Display name for the new group sitealias: URL-friendly alias for the siteis_public: Optional boolean indicating if the group is public or privateoptional_params: Optional GroupCreationParams object with additional configuration
Returns: ClientResult containing GroupSiteInfo with details about the created site
create_group_ex(self, display_name: str, alias: str, is_public: bool, optional_params: GroupCreationParams = None) -> ClientResult[GroupSiteInfo]
Purpose: Creates a modern SharePoint site using GroupCreationInformation object for more structured parameters
Parameters:
display_name: Display name for the new group sitealias: URL-friendly alias for the siteis_public: Boolean indicating if the group is public or private (required)optional_params: Optional GroupCreationParams object with additional configuration
Returns: ClientResult containing GroupSiteInfo with details about the created site
delete(self, site_url: str) -> GroupSiteManager
Purpose: Deletes a SharePoint Team site at the specified URL
Parameters:
site_url: Full URL of the SharePoint site to delete
Returns: Self (GroupSiteManager instance) for method chaining
ensure_team_for_group(self) -> ClientResult
Purpose: Ensures a Microsoft Teams team exists for the group, creating one if necessary
Returns: ClientResult with operation result
get_group_creation_context(self) -> ClientResult[GroupCreationContext]
Purpose: Retrieves the context information needed for group creation, including available options and settings
Returns: ClientResult containing GroupCreationContext with creation settings and options
get_status(self, group_id: str) -> ClientResult[GroupSiteInfo]
Purpose: Gets the current status of a SharePoint site by its group ID
Parameters:
group_id: The unique identifier of the group/site
Returns: ClientResult containing GroupSiteInfo with site status information
get_current_user_joined_teams(self, get_logo_data: bool = False, force_cache_update: bool = False) -> ClientResult[str]
Purpose: Retrieves the Microsoft Teams that the current user is a direct member of
Parameters:
get_logo_data: Boolean indicating whether to include team logo data in the responseforce_cache_update: Boolean to force refresh of cached team data
Returns: ClientResult containing string with JSON data of joined teams
get_current_user_shared_channel_member_groups(self) -> ClientResult
Purpose: Gets the groups where the current user is a member through shared channels
Returns: ClientResult with shared channel member group information
get_team_channels(self, team_id: str, use_staging_endpoint: bool = False) -> ClientResult
Purpose: Retrieves all channels for a specified Microsoft Teams team
Parameters:
team_id: The unique identifier of the teamuse_staging_endpoint: Boolean to use staging endpoint instead of production
Returns: ClientResult with team channel information
get_team_channels_direct(self, team_id: str) -> ClientResult[str]
Purpose: Retrieves team channels directly without additional processing
Parameters:
team_id: The unique identifier of the team
Returns: ClientResult containing string with channel data
notebook(self, group_id: str) -> ClientResult[str]
Purpose: Retrieves the OneNote notebook information for a group
Parameters:
group_id: The unique identifier of the group
Returns: ClientResult containing string with notebook information
recent_and_joined_teams(self, include_recent: bool = None, include_teams: bool = None, include_pinned: bool = None, existing_joined_teams_data: str = None) -> ClientResult[RecentAndJoinedTeamsResponse]
Purpose: Retrieves recent and joined teams for the current user with various filtering options
Parameters:
include_recent: Optional boolean to include recently accessed teamsinclude_teams: Optional boolean to include joined teamsinclude_pinned: Optional boolean to include pinned teamsexisting_joined_teams_data: Optional string with existing team data for delta queries
Returns: ClientResult containing RecentAndJoinedTeamsResponse with team information
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | The client context inherited from ClientObject that manages API communication and authentication | instance |
resource_path |
ResourcePath | The resource path inherited from ClientObject that defines the API endpoint for this manager | instance |
Dependencies
office365
Required Imports
from office365.runtime.client_object import ClientObject
from office365.runtime.client_result import ClientResult
from office365.runtime.http.http_method import HttpMethod
from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.portal.groups.creation_context import GroupCreationContext
from office365.sharepoint.portal.groups.creation_information import GroupCreationInformation
from office365.sharepoint.portal.groups.site_info import GroupSiteInfo
from office365.sharepoint.portal.teams.recent_and_joined_response import RecentAndJoinedTeamsResponse
Usage Example
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.portal.group_site_manager import GroupSiteManager
# Initialize context with credentials
ctx = ClientContext('https://tenant.sharepoint.com')
ctx = ctx.with_credentials(user_credentials)
# Create manager instance
manager = GroupSiteManager(ctx)
# Check if user can create groups
can_create = manager.can_user_create_group()
ctx.execute_query()
print(f'Can create group: {can_create.value}')
# Create a new group site
result = manager.create_group_for_site(
display_name='My Team Site',
alias='myteamsite',
is_public=False
)
ctx.execute_query()
print(f'Site URL: {result.value.SiteUrl}')
# Get site status
status = manager.get_status('group-id-here')
ctx.execute_query()
print(f'Status: {status.value.Status}')
# Get current user's teams
teams = manager.get_current_user_joined_teams(get_logo_data=True)
ctx.execute_query()
print(f'Teams: {teams.value}')
Best Practices
- Always call context.execute_query() after invoking methods to actually execute the queued operations and populate return values
- Check user permissions with can_user_create_group() before attempting to create sites
- Use create_group_ex() for more control over group creation with optional parameters
- Handle the asynchronous nature of operations - results are only available after execute_query()
- The delete() method returns self, allowing for method chaining with other operations
- When using get_status(), the method modifies the request before execution to use GET with query parameters
- Store ClientResult objects before calling execute_query() to access results afterward
- Ensure proper authentication context is established before creating the manager instance
- Use appropriate error handling as operations may fail due to permissions or network issues
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class SPSiteManager 71.5% similar
-
class GroupSiteInfo 68.4% similar
-
class SiteCollectionManagementService 66.0% similar
-
class TeamSiteData 65.8% similar
-
class PointPublishingSiteManager 65.0% similar