function notify_review
Sends review notifications to specified reviewers for a document review cycle, supporting multiple notification types (requested, reminder, overdue, completed).
/tf/active/vicechatdev/CDocs/utils/notifications.py
1236 - 1324
moderate
Purpose
This function manages the notification workflow for document review cycles. It retrieves document and version information from a review cycle, prepares notification details including document metadata and due dates, generates appropriate messages based on notification type, and sends notifications via the send_notification function. It handles error cases gracefully by logging issues and returning empty lists when document or version information is unavailable.
Source Code
def notify_review(review_cycle,
notification_type: str,
reviewer_uids: Optional[List[str]] = None) -> List[str]:
"""
Send review notifications to reviewers.
Args:
review_cycle: ReviewCycle instance
notification_type: Type of notification
reviewer_uids: Optional specific reviewers to notify (default: all)
Returns:
List of created notification UIDs
"""
try:
# Get document and version details
version = review_cycle.document_version
if not version:
logger.error(f"Could not find document version for review cycle {review_cycle.uid}")
return []
document = version.document
if not document:
logger.error(f"Could not find document for review cycle {review_cycle.uid}")
return []
# Get reviewers to notify
if reviewer_uids is None:
reviewer_uids = review_cycle.reviewer_uids
if not reviewer_uids:
logger.warning(f"No reviewers to notify for review cycle {review_cycle.uid}")
return []
# Prepare notification details
details = {
'review_uid': review_cycle.uid,
'version_uid': version.uid,
'doc_uid': document.uid,
'doc_number': document.doc_number,
'doc_type': document.doc_type,
'title': document.title,
'version_number': version.version_number,
'due_date': review_cycle.due_date.strftime('%Y-%m-%d') if review_cycle.due_date else None
}
# Create message based on notification type
message = None
if notification_type == 'REVIEW_REQUESTED':
message = f"Please review {document.doc_number} - {document.title} (v{version.version_number})"
elif notification_type == 'REVIEW_REMINDER':
message = f"Reminder: Your review of {document.doc_number} (v{version.version_number}) is due soon"
elif notification_type == 'REVIEW_OVERDUE':
message = f"Your review of {document.doc_number} (v{version.version_number}) is overdue"
elif notification_type == 'REVIEW_COMPLETED':
message = f"The review cycle for {document.doc_number} (v{version.version_number}) has been completed"
# Determine email template based on notification type
email_template = None
if notification_type == 'REVIEW_REQUESTED':
email_template = 'review_requested'
elif notification_type == 'REVIEW_REMINDER':
email_template = 'review_reminder'
elif notification_type == 'REVIEW_OVERDUE':
email_template = 'review_overdue'
elif notification_type == 'REVIEW_COMPLETED':
email_template = 'review_completed'
# Add review instructions to email data if available
email_data = {}
if review_cycle.instructions:
email_data['instructions'] = review_cycle.instructions
# Send notification
return send_notification(
notification_type=notification_type,
users=reviewer_uids,
resource_uid=review_cycle.uid,
resource_type='ReviewCycle',
message=message,
details=details,
send_email=True,
email_template=email_template,
email_data=email_data
)
except Exception as e:
logger.error(f"Error sending review notification: {e}")
return []
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
review_cycle |
- | - | positional_or_keyword |
notification_type |
str | - | positional_or_keyword |
reviewer_uids |
Optional[List[str]] | None | positional_or_keyword |
Parameter Details
review_cycle: A ReviewCycle model instance containing the review cycle information including document_version, reviewer_uids, due_date, instructions, and uid. Must have relationships to document version and document objects.
notification_type: String indicating the type of notification to send. Expected values: 'REVIEW_REQUESTED' (initial review request), 'REVIEW_REMINDER' (reminder before due date), 'REVIEW_OVERDUE' (past due date), 'REVIEW_COMPLETED' (review cycle finished). This determines the message content and email template used.
reviewer_uids: Optional list of specific reviewer user ID strings to notify. If None (default), notifications are sent to all reviewers in review_cycle.reviewer_uids. Allows targeting specific reviewers instead of the entire review group.
Return Value
Type: List[str]
Returns a list of strings containing the UIDs of successfully created notifications. Returns an empty list if there are errors (missing document/version, no reviewers, exception during processing). The UIDs can be used to track or reference the created notifications.
Dependencies
loggingtypingdatetimeCDocsmodels.review
Required Imports
import logging
from typing import List, Optional
from models.review import ReviewCycle
Usage Example
from models.review import ReviewCycle
from typing import List
# Assuming review_cycle is a ReviewCycle instance from database
review_cycle = ReviewCycle.query.get(review_cycle_uid)
# Send initial review request to all reviewers
notification_uids = notify_review(
review_cycle=review_cycle,
notification_type='REVIEW_REQUESTED'
)
print(f"Created {len(notification_uids)} notifications")
# Send reminder to specific reviewers
specific_reviewers = ['user123', 'user456']
reminder_uids = notify_review(
review_cycle=review_cycle,
notification_type='REVIEW_REMINDER',
reviewer_uids=specific_reviewers
)
# Send overdue notification
overdue_uids = notify_review(
review_cycle=review_cycle,
notification_type='REVIEW_OVERDUE'
)
# Send completion notification
completion_uids = notify_review(
review_cycle=review_cycle,
notification_type='REVIEW_COMPLETED'
)
Best Practices
- Always ensure the review_cycle object has valid relationships to document_version and document before calling this function
- Use appropriate notification_type values from the predefined set: 'REVIEW_REQUESTED', 'REVIEW_REMINDER', 'REVIEW_OVERDUE', 'REVIEW_COMPLETED'
- Check the returned list length to verify notifications were created successfully (empty list indicates failure)
- The function handles exceptions gracefully and logs errors, but callers should still check return values
- When targeting specific reviewers with reviewer_uids parameter, ensure the UIDs exist in the system
- The function requires send_notification to be available in scope - ensure proper module imports
- Email templates must be configured in the notification system for each notification type
- Consider the review_cycle.due_date may be None - the function handles this case by setting due_date to None in details
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_review_cycle 71.6% similar
-
function notify_approval 68.0% similar
-
function add_reviewer_to_active_review 67.1% similar
-
function update_reviewer_permissions 65.9% similar
-
function create_review_cycle 65.3% similar