class CalendarPermissionCollection
A collection class for managing CalendarPermission entities, providing methods to add and manage permissions for calendar sharing and delegation in Microsoft 365/Outlook.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/calendar/permissions/collection.py
6 - 22
moderate
Purpose
This class extends EntityCollection to specifically handle CalendarPermission objects. It provides functionality to create and manage calendar permissions, allowing users to share calendars with others by specifying email addresses and permission roles. The class acts as a container and factory for CalendarPermission entities, handling the creation of permission resources with proper validation and formatting.
Source Code
class CalendarPermissionCollection(EntityCollection[CalendarPermission]):
def __init__(self, context, resource_path=None):
super(CalendarPermissionCollection, self).__init__(
context, CalendarPermission, resource_path
)
def add(self, email_address, role):
"""
Create a calendarPermission resource to specify the identity and role of the user with whom the specified
calendar is being shared or delegated.
:param str or EmailAddress email_address: Represents a sharee or delegate who has access to the calendar.
:param str role: Permission level of the calendar sharee or delegate
"""
if not isinstance(email_address, EmailAddress):
email_address = EmailAddress(email_address)
props = {"emailAddress": email_address, "role": str(role)}
return super(CalendarPermissionCollection, self).add(**props)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
EntityCollection[CalendarPermission] | - |
Parameter Details
context: The execution context object required for API operations, typically containing authentication credentials and connection information for Microsoft Graph API or Office 365 services
resource_path: Optional string representing the API endpoint path for this collection resource. If None, it will be derived from the parent context or default collection path
Return Value
Instantiation returns a CalendarPermissionCollection object that manages CalendarPermission entities. The add() method returns a CalendarPermission object representing the newly created permission resource with the specified email address and role.
Class Interface
Methods
__init__(self, context, resource_path=None)
Purpose: Initializes a new CalendarPermissionCollection instance with the provided context and optional resource path
Parameters:
context: The execution context for API operationsresource_path: Optional API endpoint path for this collection
Returns: None (constructor)
add(self, email_address, role)
Purpose: Creates a new CalendarPermission resource to specify the identity and role of a user with whom the calendar is being shared or delegated
Parameters:
email_address: String email address or EmailAddress object representing the sharee or delegate who will have access to the calendarrole: String specifying the permission level (e.g., 'read', 'write', 'owner') for the calendar sharee or delegate
Returns: CalendarPermission object representing the newly created permission resource
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientRequestContext | Inherited from EntityCollection - stores the execution context for API operations | instance |
resource_path |
str or None | Inherited from EntityCollection - stores the API endpoint path for this collection | instance |
Dependencies
office365
Required Imports
from office365.entity_collection import EntityCollection
from office365.outlook.calendar.email_address import EmailAddress
from office365.outlook.calendar.permissions.permission import CalendarPermission
Usage Example
from office365.outlook.calendar.permissions.collection import CalendarPermissionCollection
from office365.runtime.client_request_context import ClientRequestContext
# Assume context is already configured with authentication
context = ClientRequestContext()
calendar_permissions = CalendarPermissionCollection(context, '/calendars/calendar_id/permissions')
# Add a new permission for a user with read access
permission = calendar_permissions.add('user@example.com', 'read')
# Add permission with EmailAddress object
from office365.outlook.calendar.email_address import EmailAddress
email = EmailAddress('delegate@example.com')
permission = calendar_permissions.add(email, 'write')
# Execute the request to persist changes
context.execute_query()
Best Practices
- Always ensure the context object is properly authenticated before creating a CalendarPermissionCollection instance
- The add() method accepts either a string email address or an EmailAddress object - it will automatically convert strings to EmailAddress objects
- Call context.execute_query() after adding permissions to persist changes to the server
- Valid role values typically include 'read', 'write', 'freeBusyRead', 'limitedRead', 'owner' - check Microsoft Graph API documentation for current supported roles
- The collection inherits from EntityCollection, so standard collection operations (iteration, filtering, etc.) are available
- Handle exceptions that may occur during API calls, especially authentication and permission-related errors
- The resource_path parameter should point to the specific calendar's permissions endpoint
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class CalendarPermission 81.0% similar
-
class Calendar 73.3% similar
-
class EventCollection 71.6% similar
-
class CalendarGroup 68.9% similar
-
class PermissionCollection 64.0% similar