function create_approval_workflow
Creates a new approval workflow template for a specified document type with configurable workflow type, returning the created template in a success response dictionary.
/tf/active/vicechatdev/CDocs single class/controllers/approval_controller.py
2045 - 2048
moderate
Purpose
This function serves as a controller endpoint for creating approval workflow templates in a document management system. It enables administrators to define standardized approval processes for different document types (e.g., policies, procedures, forms). The function enforces permission checks and logs the action before delegating to the underlying controller to create the workflow template. This is typically used during system configuration to establish approval routing rules and requirements for controlled documents.
Source Code
def create_approval_workflow(user: DocUser, document_type: str, workflow_type: str = 'STANDARD') -> Dict[str, Any]:
"""Create a new approval workflow template."""
template = _controller.create_approval_workflow(document_type, workflow_type)
return {"success": True, "template": template}
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
user |
DocUser | - | positional_or_keyword |
document_type |
str | - | positional_or_keyword |
workflow_type |
str | 'STANDARD' | positional_or_keyword |
Parameter Details
user: DocUser object representing the authenticated user performing the action. Must have MANAGE_SETTINGS or MANAGE_APPROVALS permissions (enforced by decorator). Used for audit logging and permission validation.
document_type: String identifier specifying the type of document this workflow applies to (e.g., 'SOP', 'POLICY', 'FORM'). This categorizes documents and determines which approval workflow template should be applied when documents of this type are submitted for approval.
workflow_type: String specifying the workflow pattern to use. Defaults to 'STANDARD'. Expected values likely include 'STANDARD', 'EXPEDITED', 'PARALLEL', or other workflow patterns defined in the system. Determines the approval routing logic and requirements.
Return Value
Type: Dict[str, Any]
Returns a dictionary with two keys: 'success' (boolean, always True on successful execution) and 'template' (the created approval workflow template object/dictionary containing workflow configuration details such as approval stages, required approvers, routing rules, and other workflow metadata). On error, decorators or underlying controller may raise exceptions instead of returning.
Dependencies
CDocs
Required Imports
from typing import Dict, Any
from CDocs.models.user_extensions import DocUser
from CDocs.controllers import require_permission, log_controller_action
Usage Example
from CDocs.models.user_extensions import DocUser
from your_module import create_approval_workflow
# Assume user is authenticated and has required permissions
admin_user = DocUser.get_by_id('user_123')
# Create a standard approval workflow for SOPs
result = create_approval_workflow(
user=admin_user,
document_type='SOP',
workflow_type='STANDARD'
)
if result['success']:
template = result['template']
print(f"Created workflow template: {template}")
# Create an expedited workflow for forms
expedited_result = create_approval_workflow(
user=admin_user,
document_type='FORM',
workflow_type='EXPEDITED'
)
print(f"Template ID: {expedited_result['template'].get('id')}")
Best Practices
- Ensure the user object passed has been properly authenticated and has active MANAGE_SETTINGS or MANAGE_APPROVALS permissions before calling
- Use consistent document_type identifiers across the system to avoid creating duplicate or conflicting workflow templates
- Handle potential exceptions (PermissionError, ValidationError, BusinessRuleError) that may be raised by decorators or the underlying controller
- The function relies on a module-level _controller instance (ApprovalControllerBase) which must be properly initialized before use
- Consider validating document_type and workflow_type values against allowed enumerations before calling to provide better error messages
- This function is decorated with log_controller_action, so all invocations are automatically logged for audit purposes
- The function always returns success=True on completion; errors are communicated via exceptions rather than return values
- Workflow templates created are typically reusable across multiple documents of the same type
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_approval_workflow_templates 82.8% similar
-
function create_approval_cycle_v1 78.3% similar
-
function create_approval_cycle_v2 77.6% similar
-
function create_approval_cycle 70.4% similar
-
class ApprovalControllerBase 67.3% similar