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
Summary
Add a built-in property
app.roleto 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:
Proposed Solution
Provide a clean API through
app.rolethat automatically determines the role based on the authorization context, similar to howapp.current_user_idworks.Benefits
References
Requested by: @felipao-mx