Add System and Firm Admin task controls
This commit is contained in:
@@ -602,6 +602,8 @@ def catalogue_detail(request: Request, catalogue_id: int):
|
||||
catalogue=row,
|
||||
can_edit=can_edit,
|
||||
can_manage_firm_services=_can_manage_firm_services(db, user),
|
||||
can_manage_firm_tasks=_can_manage_firm_tasks(db, user),
|
||||
is_system_admin=_is_system_admin(db, user),
|
||||
branches=branches,
|
||||
current_selection=get_firm_selection(db, tenant_id=tenant_id, catalogue_id=row.id),
|
||||
current_templates=get_firm_task_templates(db, tenant_id=tenant_id, catalogue_id=row.id),
|
||||
@@ -1548,6 +1550,58 @@ def firm_task_document_template_download(request: Request, template_id: int):
|
||||
db.close()
|
||||
|
||||
|
||||
@router.post('/templates/{catalogue_id}/tasks/{task_id}/toggle-active')
|
||||
def firm_task_template_toggle_active(
|
||||
request: Request,
|
||||
catalogue_id: int,
|
||||
task_id: int,
|
||||
csrf_token: str = Form(...),
|
||||
):
|
||||
"""Enable/disable a firm task template without changing the system default.
|
||||
|
||||
Existing engagement task instances are snapshots and are intentionally not
|
||||
modified. This affects task generation for future engagements only.
|
||||
"""
|
||||
validate_csrf(request, csrf_token)
|
||||
db = CommonSessionLocal()
|
||||
try:
|
||||
user = get_current_user(request, db=db)
|
||||
if not user:
|
||||
return RedirectResponse(url='/login', status_code=303)
|
||||
|
||||
if not _can_manage_firm_tasks(db, user):
|
||||
return _redirect_denied()
|
||||
|
||||
tenant_id = _active_tenant_id(request, user)
|
||||
selection = get_firm_selection(db, tenant_id=tenant_id, catalogue_id=catalogue_id)
|
||||
if not selection or not selection.is_enabled:
|
||||
return RedirectResponse(url='/services', status_code=303)
|
||||
|
||||
task = get_firm_task_template(
|
||||
db,
|
||||
tenant_id=tenant_id,
|
||||
catalogue_id=catalogue_id,
|
||||
task_id=task_id,
|
||||
)
|
||||
if not task:
|
||||
return RedirectResponse(
|
||||
url=f'/services/templates/{catalogue_id}?error=task_missing',
|
||||
status_code=303,
|
||||
)
|
||||
|
||||
task.is_active = not bool(task.is_active)
|
||||
task.updated_by_user_id = user.id
|
||||
db.commit()
|
||||
|
||||
state = 'enabled' if task.is_active else 'disabled'
|
||||
return RedirectResponse(
|
||||
url=f'/services/templates/{catalogue_id}?task_{state}=1',
|
||||
status_code=303,
|
||||
)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@router.get('/templates/{catalogue_id}/tasks/{task_id}/edit')
|
||||
def firm_task_template_edit_page(request: Request, catalogue_id: int, task_id: int):
|
||||
db = CommonSessionLocal()
|
||||
|
||||
Reference in New Issue
Block a user