teccas ekart
09/15/2025, 1:26 PMfinance:view) directly to a user instead of just assigning roles? For example, if a user already has the agent role but also needs the finance:view permission, how can I handle this?Or Weis
09/15/2025, 1:28 PMAsk Inkeep
09/15/2025, 1:28 PMAsk Inkeep
09/15/2025, 1:29 PMfinance:view permission and assign it to the user alongside their existing agent role (2) .
Resource-Level Roles
For more granular control, you can use resource-specific roles (formatted as Resource#Role) (3) (4) . For example, you could create a Finance#Viewer role that grants view permissions only on finance-related resources (5) .
Dynamic Role Assignment
Here's how you can programmatically assign additional roles to users:
from permit import Permit
from dotenv import load_dotenv
from django.http import JsonResponse
from django.views import View
load_dotenv()
permit = Permit(
pdp= os.getenv("permit_pdp_url") ,
token= os.getenv("permit_sdk_key")
)
class AssignRoleView(View) :
def post(self, request) :
user = request.user
role = request.POST.get('role')
tenant = request.POST.get('tenant')
# Assuming you have a function to assign roles
ra = await permit.api.users.assign_role(user, role, tenant)
return JsonResponse({"message": "Role assigned successfully"}, status=200)
(6)
Multiple Role Assignment
Users can have multiple roles simultaneously in Permit.io (2) . A user can be both an agent and have a finance_viewer role (or any other role containing the finance:view permission) within the same tenant .
The recommended approach is to create focused roles for specific permissions and assign multiple roles to users as needed, rather than trying to assign individual permissions directly.Ask Inkeep
09/15/2025, 1:29 PMOr Weis
09/15/2025, 1:35 PMteccas ekart
09/15/2025, 1:42 PMOr Weis
09/15/2025, 1:44 PM