🔍 Code Extractor

class GroupCollection_v1

Maturity: 32

Represents a collection of Group resources.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/principal/groups/collection.py
Lines:
14 - 83
Complexity:
moderate

Purpose

Represents a collection of Group resources.

Source Code

class GroupCollection(EntityCollection[Group]):
    """Represents a collection of Group resources."""

    def __init__(self, context, resource_path=None):
        super(GroupCollection, self).__init__(context, Group, resource_path)

    def expand_to_principals(self, max_count):
        """
        Expands groups to a collection of principals.

        :param int max_count: Specifies the maximum number of principals to be returned.
        """
        return_type = ClientResult(self.context, ClientValueCollection(PrincipalInfo))
        for cur_grp in self:
            return_type = cur_grp.expand_to_principals(max_count)
        return return_type

    def add(self, title, description=None):
        """
        Adds a group to the collection. A reference to the SP.Group that was added is returned.

        :param str title: A string that specifies the name of the cross-site group to be created.
            It MUST NOT be NULL. Its length MUST be equal to or less than 255. It MUST NOT be empty.
        :param str description: A string that contains the description of the cross-site group to be created.
            Its length MUST be equal to or less than 512.
        """
        return_type = Group(self.context)
        self.add_child(return_type)
        params = GroupCreationInformation(title, description)
        qry = CreateEntityQuery(self, params, return_type)
        self.context.add_query(qry)
        return return_type

    def get_by_id(self, group_id):
        """Returns the list item with the specified list item identifier.

        :param str group_id: Specifies the member identifier.
        """
        return Group(
            self.context,
            ServiceOperationPath("GetById", [group_id], self.resource_path),
        )

    def get_by_name(self, group_name):
        """Returns a cross-site group from the collection based on the name of the group.

        :param str group_name: A string that contains the name of the group.
        """
        return Group(
            self.context,
            ServiceOperationPath("GetByName", [group_name], self.resource_path),
        )

    def remove_by_id(self, group_id):
        """Removes the group with the specified member ID from the collection.

        :param int group_id: Specifies the member identifier.
        """
        qry = ServiceOperationQuery(self, "RemoveById", [group_id])
        self.context.add_query(qry)
        return self

    def remove_by_login_name(self, group_name):
        """Removes the cross-site group with the specified name from the collection.

        :param str group_name:  A string that contains the name of the group.
        """
        qry = ServiceOperationQuery(self, "RemoveByLoginName", [group_name])
        self.context.add_query(qry)
        return self

Parameters

Name Type Default Kind
bases EntityCollection[Group] -

Parameter Details

bases: Parameter of type EntityCollection[Group]

Return Value

Returns unspecified type

Class Interface

Methods

__init__(self, context, resource_path)

Purpose: Internal method: init

Parameters:

  • context: Parameter
  • resource_path: Parameter

Returns: None

expand_to_principals(self, max_count)

Purpose: Expands groups to a collection of principals. :param int max_count: Specifies the maximum number of principals to be returned.

Parameters:

  • max_count: Parameter

Returns: See docstring for return details

add(self, title, description)

Purpose: Adds a group to the collection. A reference to the SP.Group that was added is returned. :param str title: A string that specifies the name of the cross-site group to be created. It MUST NOT be NULL. Its length MUST be equal to or less than 255. It MUST NOT be empty. :param str description: A string that contains the description of the cross-site group to be created. Its length MUST be equal to or less than 512.

Parameters:

  • title: Parameter
  • description: Parameter

Returns: See docstring for return details

get_by_id(self, group_id)

Purpose: Returns the list item with the specified list item identifier. :param str group_id: Specifies the member identifier.

Parameters:

  • group_id: Parameter

Returns: See docstring for return details

get_by_name(self, group_name)

Purpose: Returns a cross-site group from the collection based on the name of the group. :param str group_name: A string that contains the name of the group.

Parameters:

  • group_name: Parameter

Returns: See docstring for return details

remove_by_id(self, group_id)

Purpose: Removes the group with the specified member ID from the collection. :param int group_id: Specifies the member identifier.

Parameters:

  • group_id: Parameter

Returns: None

remove_by_login_name(self, group_name)

Purpose: Removes the cross-site group with the specified name from the collection. :param str group_name: A string that contains the name of the group.

Parameters:

  • group_name: Parameter

Returns: None

Required Imports

from office365.runtime.client_result import ClientResult
from office365.runtime.client_value_collection import ClientValueCollection
from office365.runtime.paths.service_operation import ServiceOperationPath
from office365.runtime.queries.create_entity import CreateEntityQuery
from office365.runtime.queries.service_operation import ServiceOperationQuery

Usage Example

# Example usage:
# result = GroupCollection(bases)

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class AttachmentCollection_v1 72.4% similar

    Represents a collection of Attachment resources.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/attachments/collection.py
  • class GroupCollection 71.8% similar

    A collection class for managing Microsoft Graph API Group resources, providing methods to create, retrieve, and manage groups including Microsoft 365 groups and Security groups.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/groups/collection.py
  • class FolderCollection 69.0% similar

    Represents a collection of Folder resources.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/folders/collection.py
  • class Group_v2 67.2% similar

    Represents a collection of members in a SharePoint site. A group is a type of SP.Principal.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/principal/groups/group.py
  • class RoleAssignmentCollection 63.6% similar

    Represents a collection of RoleAssignment resources.

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