67 lines
2.9 KiB
Python
67 lines
2.9 KiB
Python
from sqlalchemy.orm import Session
|
|||
|
|
from typing import List
|
||
|
|
from app.models.auth.module_model import Module
|
||
|
|
import uuid
|
||
|
|
from app.services.auth.tenant_module_service import TenantModuleService
|
||
|
|
from app.schemas.auth.tenant_module_schema import TenantModuleCreate, TenantModuleUpdate, TenantModuleResponse
|
||
|
|
|
||
|
|
class TenantModuleController:
|
||
|
|
@staticmethod
|
||
|
|
def list_tenant_modules(db: Session, tenant_id: str) -> List[TenantModuleResponse]:
|
||
|
|
results = TenantModuleService.list_tenant_modules(db, tenant_id)
|
||
|
|
|
||
|
|
response_list = []
|
||
|
|
for tm, mod in results:
|
||
|
|
response_list.append(TenantModuleResponse(
|
||
|
|
id=str(tm.id),
|
||
|
|
tenant_id=str(tm.tenant_id),
|
||
|
|
module_id=str(tm.module_id),
|
||
|
|
module_name=mod.module_name,
|
||
|
|
module_icon_url=mod.icon_url,
|
||
|
|
assigned_environment_slug=tm.assigned_environment_slug or "prod",
|
||
|
|
is_active=tm.is_active,
|
||
|
|
module_config=tm.module_config,
|
||
|
|
created_at=tm.created_at
|
||
|
|
))
|
||
|
|
return response_list
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def assign_module(db: Session, tenant_id: str, assignment_data: TenantModuleCreate) -> TenantModuleResponse:
|
||
|
|
tm = TenantModuleService.assign_module(db, tenant_id, assignment_data)
|
||
|
|
|
||
|
|
module = db.query(Module).filter(Module.id == tm.module_id).first()
|
||
|
|
|
||
|
|
return TenantModuleResponse(
|
||
|
|
id=str(tm.id),
|
||
|
|
tenant_id=str(tm.tenant_id),
|
||
|
|
module_id=str(tm.module_id),
|
||
|
|
module_name=module.module_name if module else "Unknown",
|
||
|
|
module_icon_url=module.icon_url if module else None,
|
||
|
|
assigned_environment_slug=tm.assigned_environment_slug,
|
||
|
|
is_active=tm.is_active,
|
||
|
|
module_config=tm.module_config,
|
||
|
|
created_at=tm.created_at
|
||
|
|
)
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def update_assignment(db: Session, tenant_id: str, tenant_module_id: str, update_data: TenantModuleUpdate) -> TenantModuleResponse:
|
||
|
|
tm = TenantModuleService.update_assignment(db, tenant_id, tenant_module_id, update_data)
|
||
|
|
|
||
|
|
module = db.query(Module).filter(Module.id == tm.module_id).first()
|
||
|
|
|
||
|
|
return TenantModuleResponse(
|
||
|
|
id=str(tm.id),
|
||
|
|
tenant_id=str(tm.tenant_id),
|
||
|
|
module_id=str(tm.module_id),
|
||
|
|
module_name=module.module_name if module else "Unknown",
|
||
|
|
module_icon_url=module.icon_url if module else None,
|
||
|
|
assigned_environment_slug=tm.assigned_environment_slug,
|
||
|
|
is_active=tm.is_active,
|
||
|
|
module_config=tm.module_config,
|
||
|
|
created_at=tm.created_at
|
||
|
|
)
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def remove_assignment(db: Session, tenant_id: str, tenant_module_id: str):
|
||
|
|
TenantModuleService.remove_assignment(db, tenant_id, tenant_module_id)
|
||
|
|
return {"message": "Module removed from tenant successfully"}
|