Skip to content

Add app.role property for role determination based on authorized actions #175

@coderabbitai

Description

@coderabbitai

Summary

Add a built-in property app.role to automatically determine user roles based on authorized actions, eliminating the need for manual role parsing.

Current Implementation

Currently, developers need to manually implement role determination logic like this:

def get_identify_role(authorized_actions: list[str], method: str) -> IdentifyRole:
    if f'user_role.{method}' in authorized_actions:
        return IdentifyRole.user
    else:
        return IdentifyRole.support

Proposed Solution

Provide a clean API through app.role that automatically determines the role based on the authorization context, similar to how app.current_user_id works.

Benefits

  • Reduces boilerplate code across applications
  • Centralizes role determination logic
  • Provides consistent role handling across the platform
  • Improves code maintainability

References

Requested by: @felipao-mx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions