class ReviewControllerBase
Abstract base controller class for managing review workflow processes, providing core functionality for handling review cycles, comments, and completion checks.
/tf/active/vicechatdev/CDocs single class/controllers/workflow_controller_base.py
513 - 545
moderate
Purpose
ReviewControllerBase serves as an abstract base class for implementing review workflow controllers. It inherits from WorkflowControllerBase and defines the interface for managing review cycles, including checking unresolved comments and determining if a review can be completed. Subclasses must implement the abstract methods to provide specific review workflow logic. This class is designed to be extended rather than instantiated directly.
Source Code
class ReviewControllerBase(WorkflowControllerBase):
"""Base controller for the review workflow process."""
def __init__(self):
"""Initialize the review controller."""
super().__init__()
self.workflow_type = 'REVIEW'
def get_unresolved_comments(self, cycle_uid: str) -> List[Dict[str, Any]]:
"""
Get all unresolved comments for a review cycle.
Args:
cycle_uid: UID of the review cycle
Returns:
List of dictionaries with unresolved comment information
"""
# This is an abstract method that should be implemented by subclasses
raise NotImplementedError("Subclasses must implement get_unresolved_comments")
def can_complete_review(self, cycle_uid: str) -> Tuple[bool, Optional[str]]:
"""
Check if a review cycle can be completed.
Args:
cycle_uid: UID of the review cycle
Returns:
Tuple of (can complete boolean, reason if cannot complete)
"""
# This is an abstract method that should be implemented by subclasses
raise NotImplementedError("Subclasses must implement can_complete_review")
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
WorkflowControllerBase | - |
Parameter Details
__init__: No parameters required. The constructor initializes the parent WorkflowControllerBase and sets the workflow_type to 'REVIEW' to identify this as a review workflow controller.
Return Value
Instantiation returns a ReviewControllerBase object (or more commonly, a subclass instance). The get_unresolved_comments method returns a list of dictionaries containing unresolved comment information. The can_complete_review method returns a tuple with a boolean indicating if the review can be completed and an optional string explaining why it cannot be completed if applicable.
Class Interface
Methods
__init__(self) -> None
Purpose: Initialize the review controller and set workflow type to 'REVIEW'
Returns: None - initializes the instance
get_unresolved_comments(self, cycle_uid: str) -> List[Dict[str, Any]]
Purpose: Retrieve all unresolved comments for a specific review cycle
Parameters:
cycle_uid: Unique identifier of the review cycle to query for unresolved comments
Returns: List of dictionaries containing unresolved comment information including comment details, authors, timestamps, etc.
can_complete_review(self, cycle_uid: str) -> Tuple[bool, Optional[str]]
Purpose: Determine if a review cycle meets all requirements for completion
Parameters:
cycle_uid: Unique identifier of the review cycle to check for completion eligibility
Returns: Tuple containing a boolean (True if review can be completed, False otherwise) and an optional string explaining the reason if completion is blocked
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
workflow_type |
str | Identifies the type of workflow this controller manages, set to 'REVIEW' for review workflows | instance |
Dependencies
logginguuidtypingdatetimeCDocstraceback
Required Imports
from typing import Dict, List, Any, Optional, Union, Tuple
from datetime import datetime, timedelta
import logging
import uuid
import traceback
from CDocs import db
from CDocs.config import settings
from CDocs.db.schema_manager import NodeLabels, RelTypes
from CDocs.models.user_extensions import DocUser
from CDocs.utils.notifications import send_notification
from CDocs.models.document import DocumentVersion
Usage Example
# This is an abstract base class and should not be instantiated directly
# Instead, create a subclass that implements the abstract methods:
class MyReviewController(ReviewControllerBase):
def __init__(self):
super().__init__()
# Additional initialization
def get_unresolved_comments(self, cycle_uid: str) -> List[Dict[str, Any]]:
# Implementation to fetch unresolved comments from database
comments = db.query_unresolved_comments(cycle_uid)
return comments
def can_complete_review(self, cycle_uid: str) -> Tuple[bool, Optional[str]]:
# Check if review can be completed
unresolved = self.get_unresolved_comments(cycle_uid)
if unresolved:
return (False, f"There are {len(unresolved)} unresolved comments")
return (True, None)
# Usage:
controller = MyReviewController()
can_complete, reason = controller.can_complete_review('cycle-123')
if can_complete:
print("Review can be completed")
else:
print(f"Cannot complete: {reason}")
unresolved = controller.get_unresolved_comments('cycle-123')
print(f"Found {len(unresolved)} unresolved comments")
Best Practices
- This is an abstract base class - do not instantiate directly, always create a subclass
- Subclasses MUST implement both get_unresolved_comments and can_complete_review methods
- The workflow_type attribute is automatically set to 'REVIEW' and should not be modified
- Call super().__init__() in subclass constructors to ensure proper initialization
- The can_complete_review method should return a tuple with (bool, Optional[str]) where the string explains why completion is blocked
- get_unresolved_comments should return a list of dictionaries with consistent structure across implementations
- Handle database exceptions appropriately in subclass implementations
- Consider caching unresolved comments if can_complete_review calls get_unresolved_comments to avoid duplicate queries
- Use the cycle_uid parameter consistently across methods to identify the review cycle
- Ensure proper error handling and logging in subclass implementations
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class WorkflowControllerBase 88.4% similar
-
class ReviewController 77.1% similar
-
class ApprovalControllerBase 76.9% similar
-
class WorkflowCycleBase 75.6% similar
-
class CommentBase 69.8% similar