class UserRoleAssignment
A data class representing the assignment of a role to a user in SharePoint, inheriting from ClientValue for serialization support.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sharing/user_role_assignment.py
4 - 18
simple
Purpose
This class encapsulates the relationship between a user and their assigned role in SharePoint's sharing and permission system. It is used to represent user-role assignments when managing permissions, sharing resources, or querying user access levels. The class provides a structured way to pass user role information to SharePoint APIs and serialize/deserialize this data through the Office365 client library.
Source Code
class UserRoleAssignment(ClientValue):
"""Specifies a user and a role that is associated with the user."""
def __init__(self, role=None, user_id=None):
"""
:param int role: Specifies a Role (section 3.2.5.188) that is assigned to a user.
:param str user_id: Specifies the identifier of a user, which can be in the format of an email address or a
login identifier.
"""
self.Role = role
self.UserId = user_id
@property
def entity_type_name(self):
return "SP.Sharing.UserRoleAssignment"
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
ClientValue | - |
Parameter Details
role: An integer representing the Role (as defined in SharePoint section 3.2.5.188) assigned to the user. This typically corresponds to permission levels like Read, Contribute, or Full Control. Can be None if not yet assigned.
user_id: A string identifier for the user, which can be formatted as either an email address (e.g., 'user@example.com') or a login identifier (e.g., 'domain\username'). Can be None if not yet specified.
Return Value
Instantiation returns a UserRoleAssignment object with Role and UserId attributes set to the provided values (or None if not provided). The entity_type_name property returns the string 'SP.Sharing.UserRoleAssignment', which is used for SharePoint API serialization.
Class Interface
Methods
__init__(self, role=None, user_id=None)
Purpose: Initializes a new UserRoleAssignment instance with optional role and user_id values
Parameters:
role: Integer representing the SharePoint role to assign (default: None)user_id: String identifier for the user in email or login format (default: None)
Returns: None (constructor)
@property entity_type_name(self) -> str
property
Purpose: Returns the SharePoint entity type name used for API serialization and deserialization
Returns: The string 'SP.Sharing.UserRoleAssignment' identifying this entity type in SharePoint's object model
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
Role |
int or None | Stores the integer value representing the SharePoint role assigned to the user. Corresponds to permission levels defined in SharePoint (section 3.2.5.188) | instance |
UserId |
str or None | Stores the user identifier string, which can be formatted as an email address or login identifier. Used to identify the user in SharePoint operations | instance |
Dependencies
office365
Required Imports
from office365.runtime.client_value import ClientValue
Usage Example
from office365.runtime.client_value import ClientValue
from office365.sharepoint.sharing.user_role_assignment import UserRoleAssignment
# Create a user role assignment with a specific role and user
user_assignment = UserRoleAssignment(role=3, user_id='user@example.com')
# Access the attributes
print(f"User: {user_assignment.UserId}")
print(f"Role: {user_assignment.Role}")
print(f"Entity Type: {user_assignment.entity_type_name}")
# Create an assignment with only user_id initially
partial_assignment = UserRoleAssignment(user_id='admin@example.com')
partial_assignment.Role = 5 # Assign role later
# Typically used when setting permissions on SharePoint items
# assignments = [UserRoleAssignment(role=2, user_id='user1@example.com'),
# UserRoleAssignment(role=3, user_id='user2@example.com')]
Best Practices
- Always provide both role and user_id when creating assignments for complete permission definitions
- Use valid SharePoint role integers that correspond to defined permission levels in your SharePoint environment
- The user_id should match the format expected by your SharePoint instance (email or login identifier)
- This class is typically used as part of larger permission management operations, not in isolation
- The entity_type_name property should not be modified as it's used for SharePoint API serialization
- Instances are immutable in practice - create new instances rather than modifying existing ones for clarity
- When used in collections, ensure each user_id is unique to avoid permission conflicts
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class RoleAssignment 76.6% similar
-
class UnifiedRoleAssignment 68.8% similar
-
class RoleDefinitionCreationInformation 68.4% similar
-
class Role 68.2% similar
-
class AppRoleAssignmentCollection 63.8% similar