Spaces:
Configuration error
Configuration error
File size: 1,695 Bytes
2567e7e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | from typing import Optional, List
from pydantic import BaseModel, Field
class UserContext(BaseModel):
user_id: str = "USR-001"
account_id: Optional[str] = "ACCT-001" # Target customer account ID if customer
is_internal: bool = False # False = Customer Facing, True = Internal Staff
role: str = "customer" # "customer", "support_agent", "operations_lead", "admin"
user_name: str = "Northstar User"
def can_access_account(self, target_account_id: Optional[str]) -> bool:
"""
Data-layer security check.
Internal users can access any account data.
Customer users can ONLY access data belonging to their own account_id.
"""
if self.is_internal:
return True
if not target_account_id:
return True # Public general documents
return self.account_id == target_account_id
def can_access_document(self, doc_filename: str, doc_account_id: Optional[str]) -> bool:
"""
Document-layer security check.
Customer agreements are restricted to that account only.
"""
if self.is_internal:
return True
if doc_account_id:
return self.account_id == doc_account_id
return True
def can_perform_action(self, action_name: str) -> bool:
"""
Action authorization check.
"""
if not self.is_internal and action_name in ["escalate_ticket", "update_ticket", "create_followup_task", "approve_service_credit"]:
# Customers can request escalation for their own tickets, but internal actions are role-checked
return True
return True
|