🔍 Code Extractor

class DirectoryRoleTemplate

Maturity: 46

A class representing a directory role template in Microsoft Graph API, which specifies property values for directory roles.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/rolemanagement/template.py
Lines:
6 - 23
Complexity:
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

  • typing
  • office365.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

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class DirectoryRole 82.4% similar

    Represents an Azure AD directory role (also known as administrator roles) with properties like description, display name, and members.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/rolemanagement/role.py
  • class GroupSettingTemplate 68.5% similar

    GroupSettingTemplate represents system-defined settings templates available to a tenant in Microsoft Graph API, allowing creation of group settings with customizable values.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/groups/setting_template.py
  • class DirectoryObject 65.2% similar

    Represents an Azure Active Directory object, serving as the base type for directory entities like users, groups, service principals, and organizational contacts.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/object.py
  • class UnifiedRoleDefinition 64.4% similar

    Represents an Azure Active Directory (Azure AD) role definition, which is a collection of permissions listing operations that can be performed and resources against which they can be performed.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/rolemanagement/unified_role_definition.py
  • class UnifiedRoleAssignment 63.8% similar

    Represents a role assignment in Microsoft Graph API that grants access to resources by associating a role definition with a principal (user or group) at a specific scope.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/rolemanagement/unified_role_assignment.py
← Back to Browse