function complete_approval_v2
Completes an approval cycle by recording a decision (approve/reject) and optional comments, then returns the operation status.
/tf/active/vicechatdev/CDocs single class/controllers/approval_controller.py
1995 - 2002
simple
Purpose
This function serves as a controller action to finalize an approval workflow cycle in a document management system. It delegates to an underlying approval controller to process the decision, update the approval cycle status, and provide feedback on whether the operation succeeded. This is typically used when an approver makes a final decision on a document or workflow item requiring approval.
Source Code
def complete_approval(user: DocUser, approval_uid: str, decision: str, comments: Optional[str] = None) -> Dict[str, Any]:
"""Complete an approval cycle."""
success = _controller.complete_cycle(
cycle_uid=approval_uid,
decision=decision,
comment=comments
)
return {"success": success, "message": "Approval completed successfully" if success else "Failed to complete approval"}
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
user |
DocUser | - | positional_or_keyword |
approval_uid |
str | - | positional_or_keyword |
decision |
str | - | positional_or_keyword |
comments |
Optional[str] | None | positional_or_keyword |
Parameter Details
user: DocUser object representing the authenticated user completing the approval. This user should have appropriate permissions to complete the approval cycle and their identity is used for audit trail purposes.
approval_uid: String containing the unique identifier (UID) of the approval cycle to be completed. This references a specific ApprovalCycle instance in the system.
decision: String indicating the approval decision. Expected values are typically 'approve', 'reject', or similar workflow-specific decision values that determine the outcome of the approval cycle.
comments: Optional string parameter for providing additional context, justification, or notes about the approval decision. Can be None if no comments are needed. These comments are typically stored with the approval record for audit purposes.
Return Value
Type: Dict[str, Any]
Returns a dictionary with two keys: 'success' (boolean indicating whether the approval completion succeeded) and 'message' (string containing a human-readable status message - either 'Approval completed successfully' if success is True, or 'Failed to complete approval' if success is False). Type: Dict[str, Any]
Dependencies
CDocstypingdatetimeloggingtracebackuuid
Required Imports
from typing import Dict, Any, Optional
from CDocs.models.user_extensions import DocUser
from CDocs.controllers import log_controller_action
Usage Example
from CDocs.models.user_extensions import DocUser
from typing import Dict, Any
# Assume user is authenticated and retrieved from session
user = DocUser.get_by_id('user_123')
approval_uid = 'approval_cycle_456'
# Complete approval with decision
result = complete_approval(
user=user,
approval_uid=approval_uid,
decision='approve',
comments='All requirements met, documentation is complete.'
)
if result['success']:
print(f"Success: {result['message']}")
else:
print(f"Error: {result['message']}")
# Complete approval without comments
result = complete_approval(
user=user,
approval_uid='approval_cycle_789',
decision='reject'
)
print(result)
Best Practices
- Ensure the user parameter represents an authenticated and authorized user before calling this function
- Validate that the approval_uid exists and is in a state that allows completion before calling
- The decision parameter should match expected values defined in your workflow configuration (typically 'approve' or 'reject')
- Always check the 'success' key in the returned dictionary before proceeding with subsequent operations
- Consider providing meaningful comments for audit trail purposes, especially for rejections
- This function is decorated with @log_controller_action, so all invocations are automatically logged
- Handle the case where success is False appropriately in your application logic
- The function relies on _controller being properly initialized in the module scope
- Ensure proper error handling around this function call as it may raise PermissionError, ResourceNotFoundError, or other CDocs exceptions
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function complete_review_v1 84.4% similar
-
function complete_approval 81.1% similar
-
function complete_approval_v1 79.3% similar
-
function cancel_approval_cycle_v2 77.8% similar
-
function create_approval_cycle_v1 75.9% similar