🔍 Code Extractor

function create_approval_workflow

Maturity: 47

Creates a new approval workflow template for a specified document type with configurable workflow type, returning the created template in a success response dictionary.

File:
/tf/active/vicechatdev/CDocs single class/controllers/approval_controller.py
Lines:
2045 - 2048
Complexity:
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

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_approval_workflow_templates 82.8% similar

    Retrieves approval workflow templates, optionally filtered by document type, and returns them in a standardized response format with success status and count.

    From: /tf/active/vicechatdev/CDocs single class/controllers/approval_controller.py
  • function create_approval_cycle_v1 78.3% similar

    Creates a new approval cycle for a controlled document, managing approver assignments, permissions, notifications, and audit logging.

    From: /tf/active/vicechatdev/CDocs/controllers/approval_controller.py
  • function create_approval_cycle_v2 77.6% similar

    Creates an approval cycle for a specific document version, assigning approvers and configuring approval workflow parameters.

    From: /tf/active/vicechatdev/CDocs single class/controllers/approval_controller.py
  • function create_approval_cycle 70.4% similar

    Creates a new approval cycle for a document, assigning approvers with configurable workflow options (sequential/parallel), instructions, and due dates.

    From: /tf/active/vicechatdev/CDocs/controllers/approval_controller_bis.py
  • class ApprovalControllerBase 67.3% similar

    Abstract base controller class for managing approval workflow processes, providing a template for approval cycle operations and workflow template management.

    From: /tf/active/vicechatdev/CDocs single class/controllers/workflow_controller_base.py
← Back to Browse