🔍 Code Extractor

class Role

Maturity: 44

An enumeration class representing abstract roles for SharePoint sharing permissions on securable objects in document libraries.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sharing/role.py
Lines:
4 - 20
Complexity:
simple

Purpose

This class defines three standard SharePoint sharing roles (View, Edit, Owner) that can be assigned to users for controlling access to securable objects in document libraries. It inherits from ClientValue, making it compatible with SharePoint's client-side object model. The class provides a type-safe way to specify permission levels when sharing documents or other securable resources.

Source Code

class Role(ClientValue):
    """
    Specifies a set of abstract roles that a user can be assigned to share a securable object in a document library
    """

    View = 1
    """The user can only read a securable object."""

    Edit = 2
    """The user can edit or read a securable object, but cannot delete it."""

    Owner = 3
    """The user is an owner of a securable object and can manage permissions, and edit, read or delete the object."""

    @property
    def entity_type_name(self):
        return "SP.Sharing.Role"

Parameters

Name Type Default Kind
bases ClientValue -

Parameter Details

__init__: This class does not define a custom __init__ method. It inherits the constructor from ClientValue base class. Typically instantiated by passing one of the class constants (View=1, Edit=2, Owner=3) or used directly via the class constants.

Return Value

Instantiation returns a Role object representing a SharePoint sharing permission level. The entity_type_name property returns the string 'SP.Sharing.Role' which identifies this type in SharePoint's type system.

Class Interface

Methods

@property entity_type_name(self) -> str property

Purpose: Returns the SharePoint entity type name for this role class, used for type identification in SharePoint's client object model

Returns: String 'SP.Sharing.Role' representing the SharePoint type identifier

Attributes

Name Type Description Scope
View int Represents read-only permission level. Users with this role can only view/read a securable object but cannot modify or delete it. Value: 1 class
Edit int Represents edit permission level. Users with this role can read and edit a securable object but cannot delete it. Value: 2 class
Owner int Represents owner permission level. Users with this role have full control including managing permissions, editing, reading, and deleting the securable object. Value: 3 class

Dependencies

  • office365

Required Imports

from office365.runtime.client_value import ClientValue
from office365.sharepoint.sharing.role import Role

Usage Example

from office365.sharepoint.sharing.role import Role

# Use class constants to specify roles
view_role = Role.View  # Value: 1
edit_role = Role.Edit  # Value: 2
owner_role = Role.Owner  # Value: 3

# Typically used when sharing a document or folder
# Example: Assigning a role when sharing
if user_permission_level == 'read_only':
    assigned_role = Role.View
elif user_permission_level == 'contributor':
    assigned_role = Role.Edit
else:
    assigned_role = Role.Owner

# Get the entity type name for SharePoint API calls
role_instance = Role()
type_name = role_instance.entity_type_name  # Returns: 'SP.Sharing.Role'

Best Practices

  • Use the class constants (Role.View, Role.Edit, Role.Owner) rather than hardcoding integer values for better code readability and maintainability
  • This class is typically used as a parameter in SharePoint sharing operations rather than being instantiated directly
  • The Role class is immutable - the constants represent fixed permission levels defined by SharePoint
  • When integrating with SharePoint APIs, ensure the role values align with the target SharePoint version's permission model
  • The entity_type_name property is used internally by the Office365 library for serialization and should not typically be modified

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class RoleType 75.2% similar

    An enumeration class that defines SharePoint role types with integer constants representing different permission levels for users and groups.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sharing/role_type.py
  • class SharingPermissionInformation 69.6% similar

    A class representing sharing permission information for SharePoint entities such as groups or roles, providing access to permission metadata and default permission status.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sharing/permission_information.py
  • class SecurableObject 69.5% similar

    A class representing an object that can be assigned security permissions in SharePoint, providing methods to manage role assignments, permissions, and inheritance.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/permissions/securable_object.py
  • class UserRoleAssignment 68.2% similar

    A data class representing the assignment of a role to a user in SharePoint, inheriting from ClientValue for serialization support.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sharing/user_role_assignment.py
  • class SharingCapabilities 68.0% similar

    An enumeration-style class that defines external sharing capability levels for SharePoint site collections in Office 365.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/tenant/administration/sharing_capabilities.py
← Back to Browse