fixed trustee access
This commit is contained in:
parent
95dbbb8360
commit
013de9e220
5 changed files with 734 additions and 129 deletions
|
|
@ -53,7 +53,9 @@ def getOptions(optionsName: str, services, currentUser: Optional[User] = None) -
|
|||
Raises:
|
||||
ValueError: If optionsName is not recognized
|
||||
"""
|
||||
logger.debug(f"getOptions called with optionsName='{optionsName}' (repr: {repr(optionsName)})")
|
||||
optionsNameLower = optionsName.lower()
|
||||
logger.debug(f"optionsNameLower='{optionsNameLower}'")
|
||||
|
||||
if optionsNameLower == "user.role":
|
||||
# Fetch roles from database
|
||||
|
|
@ -118,7 +120,100 @@ def getOptions(optionsName: str, services, currentUser: Optional[User] = None) -
|
|||
logger.error(f"Error fetching user connections for options: {e}")
|
||||
return []
|
||||
|
||||
elif optionsNameLower in ("user", "users"):
|
||||
# Dynamic options: Get all users for the current mandate
|
||||
if not currentUser:
|
||||
return []
|
||||
|
||||
try:
|
||||
users = services.interfaceDbApp.getUsersByMandate(currentUser.mandateId)
|
||||
|
||||
# Handle both list and PaginatedResult
|
||||
if hasattr(users, 'items'):
|
||||
userList = users.items
|
||||
else:
|
||||
userList = users
|
||||
|
||||
return [
|
||||
{
|
||||
"value": user.id,
|
||||
"label": user.fullName or user.username or user.email or user.id
|
||||
}
|
||||
for user in userList
|
||||
]
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching users for options: {e}")
|
||||
return []
|
||||
|
||||
elif optionsNameLower in ("trusteeorganisation", "trustee.organisation"):
|
||||
# Dynamic options: Get all trustee organisations
|
||||
if not currentUser:
|
||||
return []
|
||||
|
||||
try:
|
||||
result = services.interfaceDbTrustee.getAllOrganisations()
|
||||
|
||||
# Handle PaginatedResult
|
||||
items = result.items if hasattr(result, 'items') else result
|
||||
|
||||
return [
|
||||
{
|
||||
"value": org.get("id") if isinstance(org, dict) else org.id,
|
||||
"label": org.get("label") if isinstance(org, dict) else org.label
|
||||
}
|
||||
for org in items
|
||||
]
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching trustee organisations for options: {e}")
|
||||
return []
|
||||
|
||||
elif optionsNameLower in ("trusteerole", "trustee.role"):
|
||||
# Dynamic options: Get all trustee roles
|
||||
if not currentUser:
|
||||
return []
|
||||
|
||||
try:
|
||||
result = services.interfaceDbTrustee.getAllRoles()
|
||||
|
||||
# Handle PaginatedResult
|
||||
items = result.items if hasattr(result, 'items') else result
|
||||
|
||||
return [
|
||||
{
|
||||
"value": role.get("id") if isinstance(role, dict) else role.id,
|
||||
# TrusteeRole uses 'desc' field, not 'label'
|
||||
"label": role.get("desc", role.get("id")) if isinstance(role, dict) else getattr(role, "desc", role.id)
|
||||
}
|
||||
for role in items
|
||||
]
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching trustee roles for options: {e}")
|
||||
return []
|
||||
|
||||
elif optionsNameLower in ("trusteecontract", "trustee.contract"):
|
||||
# Dynamic options: Get all trustee contracts
|
||||
if not currentUser:
|
||||
return []
|
||||
|
||||
try:
|
||||
result = services.interfaceDbTrustee.getAllContracts()
|
||||
|
||||
# Handle PaginatedResult
|
||||
items = result.items if hasattr(result, 'items') else result
|
||||
|
||||
return [
|
||||
{
|
||||
"value": contract.get("id") if isinstance(contract, dict) else contract.id,
|
||||
"label": contract.get("label") if isinstance(contract, dict) else (contract.get("name") if isinstance(contract, dict) else getattr(contract, "label", getattr(contract, "name", contract.id)))
|
||||
}
|
||||
for contract in items
|
||||
]
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching trustee contracts for options: {e}")
|
||||
return []
|
||||
|
||||
else:
|
||||
logger.error(f"Unknown options name: '{optionsName}' (lower: '{optionsNameLower}')")
|
||||
raise ValueError(f"Unknown options name: {optionsName}")
|
||||
|
||||
|
||||
|
|
@ -134,5 +229,9 @@ def getAvailableOptionsNames() -> List[str]:
|
|||
"auth.authority",
|
||||
"connection.status",
|
||||
"user.connection",
|
||||
"User",
|
||||
"TrusteeOrganisation",
|
||||
"TrusteeRole",
|
||||
"TrusteeContract",
|
||||
]
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -70,9 +70,12 @@ async def getOrganisations(
|
|||
currentUser: User = Depends(getCurrentUser)
|
||||
) -> PaginatedResponse[TrusteeOrganisation]:
|
||||
"""Get all organisations with optional pagination."""
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.debug(f"getOrganisations called for user {currentUser.id}, roles: {currentUser.roleLabels}")
|
||||
paginationParams = _parsePagination(pagination)
|
||||
interface = getInterface(currentUser)
|
||||
result = interface.getAllOrganisations(paginationParams)
|
||||
logger.debug(f"getOrganisations returned {len(result.items)} items")
|
||||
|
||||
if paginationParams:
|
||||
return PaginatedResponse(
|
||||
|
|
|
|||
|
|
@ -47,10 +47,13 @@ async def getOptionsEndpoint(
|
|||
- GET /api/options/connection.status
|
||||
"""
|
||||
try:
|
||||
logger.debug(f"Options request: {optionsName} for user {currentUser.id}")
|
||||
services = getServices(currentUser, None)
|
||||
options = getOptions(optionsName, services, currentUser)
|
||||
logger.debug(f"Options response: {optionsName} returned {len(options)} items")
|
||||
return options
|
||||
except ValueError as e:
|
||||
logger.error(f"ValueError for options {optionsName}: {str(e)}")
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=str(e)
|
||||
|
|
|
|||
|
|
@ -57,6 +57,9 @@ class Services:
|
|||
from modules.interfaces.interfaceDbComponentObjects import getInterface as getComponentInterface
|
||||
self.interfaceDbComponent = getComponentInterface(user)
|
||||
|
||||
from modules.interfaces.interfaceDbTrusteeObjects import getInterface as getTrusteeInterface
|
||||
self.interfaceDbTrustee = getTrusteeInterface(user)
|
||||
|
||||
# Expose RBAC directly on services for convenience
|
||||
self.rbac = self.interfaceDbApp.rbac if self.interfaceDbApp else None
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue