🔍 Code Extractor

class ApprovalControllerBase

Maturity: 49

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

File:
/tf/active/vicechatdev/CDocs single class/controllers/workflow_controller_base.py
Lines:
548 - 594
Complexity:
moderate

Purpose

ApprovalControllerBase serves as an abstract base class that defines the interface for approval workflow controllers. It inherits from WorkflowControllerBase and establishes the contract for subclasses to implement approval-specific functionality including retrieving approval steps, creating approval workflows, and managing workflow templates. This class sets the workflow_type to 'APPROVAL' and requires subclasses to implement all abstract methods for concrete approval workflow operations.

Source Code

class ApprovalControllerBase(WorkflowControllerBase):
    """Base controller for the approval workflow process."""
    
    def __init__(self):
        """Initialize the approval controller."""
        super().__init__()
        self.workflow_type = 'APPROVAL'
    
    def get_approval_steps(self, cycle_uid: str) -> List[Dict[str, Any]]:
        """
        Get all approval steps for an approval cycle.
        
        Args:
            cycle_uid: UID of the approval cycle
            
        Returns:
            List of dictionaries with approval step information
        """
        # This is an abstract method that should be implemented by subclasses
        raise NotImplementedError("Subclasses must implement get_approval_steps")
    
    def create_approval_workflow(self, document_type: str, workflow_type: str = 'STANDARD') -> Optional[Dict[str, Any]]:
        """
        Create a new approval workflow template.
        
        Args:
            document_type: Type of document this workflow applies to
            workflow_type: Type of workflow
            
        Returns:
            Dictionary with created workflow information or None if failed
        """
        # This is an abstract method that should be implemented by subclasses
        raise NotImplementedError("Subclasses must implement create_approval_workflow")
    
    def get_approval_workflow_templates(self, document_type: Optional[str] = None) -> List[Dict[str, Any]]:
        """
        Get approval workflow templates.
        
        Args:
            document_type: Optional document type to filter by
            
        Returns:
            List of dictionaries with workflow template information
        """
        # This is an abstract method that should be implemented by subclasses
        raise NotImplementedError("Subclasses must implement get_approval_workflow_templates")

Parameters

Name Type Default Kind
bases WorkflowControllerBase -

Parameter Details

__init__: No parameters required. The constructor initializes the parent WorkflowControllerBase and sets the workflow_type attribute to 'APPROVAL' to identify this controller as handling approval workflows.

Return Value

Instantiation returns an ApprovalControllerBase object (or more commonly, a subclass instance). Methods return: get_approval_steps returns a list of dictionaries containing approval step information for a given cycle; create_approval_workflow returns an optional dictionary with created workflow information or None if creation fails; get_approval_workflow_templates returns a list of dictionaries containing workflow template information, optionally filtered by document type.

Class Interface

Methods

__init__(self) -> None

Purpose: Initialize the approval controller by calling parent constructor and setting workflow_type to 'APPROVAL'

Returns: None - initializes the instance

get_approval_steps(self, cycle_uid: str) -> List[Dict[str, Any]]

Purpose: Retrieve all approval steps for a specific approval cycle identified by its UID

Parameters:

  • cycle_uid: Unique identifier (UID) of the approval cycle to retrieve steps for

Returns: List of dictionaries, where each dictionary contains information about an approval step (e.g., step ID, approver, status, timestamps)

create_approval_workflow(self, document_type: str, workflow_type: str = 'STANDARD') -> Optional[Dict[str, Any]]

Purpose: Create a new approval workflow template for a specific document type

Parameters:

  • document_type: Type of document this workflow applies to (e.g., 'invoice', 'contract', 'purchase_order')
  • workflow_type: Type of workflow to create, defaults to 'STANDARD'. Can be customized for different approval patterns

Returns: Dictionary containing created workflow information (e.g., workflow ID, configuration, steps) if successful, or None if creation failed

get_approval_workflow_templates(self, document_type: Optional[str] = None) -> List[Dict[str, Any]]

Purpose: Retrieve approval workflow templates, optionally filtered by document type

Parameters:

  • document_type: Optional document type to filter templates by. If None, returns all templates

Returns: List of dictionaries containing workflow template information (e.g., template ID, document type, steps configuration, approval rules)

Attributes

Name Type Description Scope
workflow_type str Identifies the type of workflow this controller manages, set to 'APPROVAL' in the constructor instance

Dependencies

  • logging
  • uuid
  • typing
  • datetime
  • CDocs
  • CDocs.config
  • CDocs.db.schema_manager
  • CDocs.models.user_extensions
  • CDocs.utils.notifications
  • CDocs.models.document
  • traceback

Required Imports

from typing import Dict, List, Any, Optional
from CDocs.controllers.workflow_controller_base import WorkflowControllerBase

Usage Example

# This is an abstract base class, so you must create a concrete subclass
class MyApprovalController(ApprovalControllerBase):
    def get_approval_steps(self, cycle_uid: str) -> List[Dict[str, Any]]:
        # Implementation to retrieve approval steps from database
        return [{"step_id": "1", "approver": "user@example.com", "status": "pending"}]
    
    def create_approval_workflow(self, document_type: str, workflow_type: str = 'STANDARD') -> Optional[Dict[str, Any]]:
        # Implementation to create workflow
        return {"workflow_id": "wf_123", "document_type": document_type, "type": workflow_type}
    
    def get_approval_workflow_templates(self, document_type: Optional[str] = None) -> List[Dict[str, Any]]:
        # Implementation to retrieve templates
        return [{"template_id": "tmpl_1", "document_type": document_type or "all"}]

# Instantiate and use the concrete controller
controller = MyApprovalController()
steps = controller.get_approval_steps("cycle_uid_123")
workflow = controller.create_approval_workflow("invoice", "STANDARD")
templates = controller.get_approval_workflow_templates("invoice")

Best Practices

  • This is an abstract base class and cannot be instantiated directly - always create a concrete subclass that implements all abstract methods
  • Subclasses must implement get_approval_steps, create_approval_workflow, and get_approval_workflow_templates methods
  • The workflow_type attribute is automatically set to 'APPROVAL' and should not be modified
  • Ensure proper error handling in subclass implementations as the base methods raise NotImplementedError
  • Follow the return type contracts defined in the method signatures when implementing abstract methods
  • The class inherits from WorkflowControllerBase, so subclasses have access to parent class methods and attributes
  • Use type hints consistently when implementing methods to maintain interface compatibility
  • Consider implementing proper logging in subclass methods for debugging approval workflow operations

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class WorkflowControllerBase 84.8% similar

    Abstract base class that defines the interface for workflow controllers managing document review and approval processes.

    From: /tf/active/vicechatdev/CDocs single class/controllers/workflow_controller_base.py
  • class ApprovalController 78.4% similar

    Controller for managing document approval processes.

    From: /tf/active/vicechatdev/CDocs single class/controllers/approval_controller.py
  • class ReviewControllerBase 76.9% similar

    Abstract base controller class for managing review workflow processes, providing core functionality for handling review cycles, comments, and completion checks.

    From: /tf/active/vicechatdev/CDocs single class/controllers/workflow_controller_base.py
  • class WorkflowCycleBase 72.1% similar

    Base class for workflow cycles (ReviewCycle and ApprovalCycle) that manages workflow lifecycle, status tracking, and common properties for document review and approval processes.

    From: /tf/active/vicechatdev/CDocs single class/models/workflow_base.py
  • class AssignmentBase 67.6% similar

    Base class for managing assignment lifecycle in a document review/approval workflow system, tracking status, timestamps, user assignments, and decisions.

    From: /tf/active/vicechatdev/CDocs single class/models/workflow_base.py
← Back to Browse