class DirectoryRoleTemplate
A class representing a directory role template in Microsoft Graph API, which specifies property values for directory roles.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/rolemanagement/template.py
6 - 23
simple
Purpose
DirectoryRoleTemplate is a data model class that inherits from DirectoryObject and represents a template for directory roles in Azure Active Directory/Microsoft 365. It provides read-only access to role template properties like display name and description through property decorators. This class is used to retrieve and represent predefined role templates that can be used to create directory roles with specific permissions and characteristics.
Source Code
class DirectoryRoleTemplate(DirectoryObject):
"""Represents a directory role template. A directory role template specifies the property values of a directory
role (directoryRole)."""
def __repr__(self):
return self.display_name
@property
def display_name(self):
# type: () -> Optional[str]
"""The display name to set for the directory role"""
return self.properties.get("displayName", None)
@property
def description(self):
# type: () -> Optional[str]
"""The display name to set for the directory role"""
return self.properties.get("description", None)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
DirectoryObject | - |
Parameter Details
DirectoryObject_init_params: This class inherits from DirectoryObject, so it accepts whatever parameters the parent DirectoryObject.__init__ method requires. Typically this includes context and resource_path parameters for API communication, though the exact parameters are not visible in this code snippet.
Return Value
Instantiating this class returns a DirectoryRoleTemplate object that provides access to role template properties. The __repr__ method returns the display_name string for string representation. The display_name and description properties return Optional[str] values retrieved from the internal properties dictionary, or None if not present.
Class Interface
Methods
__repr__(self) -> str
Purpose: Returns a string representation of the DirectoryRoleTemplate object
Returns: The display_name property value as a string representation of the object
@property display_name(self) -> Optional[str]
property
Purpose: Gets the display name of the directory role template
Returns: The display name string if present in properties, otherwise None
@property description(self) -> Optional[str]
property
Purpose: Gets the description of the directory role template
Returns: The description string if present in properties, otherwise None
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
properties |
dict | Inherited from DirectoryObject, stores the raw property data retrieved from the Microsoft Graph API including displayName and description | instance |
Dependencies
typingoffice365.directory.object
Required Imports
from typing import Optional
from office365.directory.object import DirectoryObject
Usage Example
# Assuming you have a context object configured for Microsoft Graph API
from office365.directory.role_template import DirectoryRoleTemplate
from office365.graph_client import GraphClient
# Initialize Graph client with credentials
client = GraphClient.with_credentials(tenant_id, client_id, client_secret)
# Get a directory role template
role_template = client.directory_role_templates.get_by_id('template_id').get().execute_query()
# Access properties
print(role_template.display_name) # e.g., 'Global Administrator'
print(role_template.description) # e.g., 'Can manage all aspects of Azure AD'
print(role_template) # Uses __repr__, prints display_name
# List all role templates
role_templates = client.directory_role_templates.get().execute_query()
for template in role_templates:
print(f'{template.display_name}: {template.description}')
Best Practices
- This is a read-only data model class - properties are retrieved from the internal properties dictionary and should not be modified directly
- The class relies on the parent DirectoryObject class for API communication and data storage in the properties dictionary
- Always ensure the object is properly loaded from the API (using execute_query()) before accessing properties to avoid None values
- Use the properties (display_name, description) rather than accessing the properties dictionary directly for type safety
- The __repr__ method returns display_name, so string conversion may return None if the property is not loaded
- This class represents immutable templates - to create actual directory roles, use the template as a reference but instantiate DirectoryRole objects
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class DirectoryRole 82.4% similar
-
class GroupSettingTemplate 68.5% similar
-
class DirectoryObject 65.2% similar
-
class UnifiedRoleDefinition 64.4% similar
-
class UnifiedRoleAssignment 63.8% similar