🔍 Code Extractor

function get_user_pending_reviews_v1

Maturity: 51

Retrieves pending review assignments for a specific user, with an option to include completed reviews.

File:
/tf/active/vicechatdev/CDocs single class/controllers/review_controller.py
Lines:
1870 - 1882
Complexity:
simple

Purpose

This function fetches review assignments for a given user from the document review system. It queries the underlying controller to get assignments filtered by status (PENDING, IN_PROGRESS, and optionally COMPLETED/REJECTED). The function is decorated with logging to track controller actions and is designed to support document review workflows where users need to see their assigned reviews.

Source Code

def get_user_pending_reviews(user: DocUser, include_completed: bool = False) -> Dict[str, Any]:
    """Get pending reviews for a user."""
    status_filter = ["PENDING", "IN_PROGRESS"]
    if include_completed:
        status_filter.extend(["COMPLETED", "REJECTED"])
        
    assignments, total = _controller.get_assignments_for_user(
        user_uid=user.uid if user else None,
        status_filter=status_filter,
        limit=100,
        offset=0
    )
    return {"success": True, "reviews": assignments, "total": total}

Parameters

Name Type Default Kind
user DocUser - positional_or_keyword
include_completed bool False positional_or_keyword

Parameter Details

user: A DocUser object representing the user whose pending reviews should be retrieved. The function extracts the user's UID to query assignments. If None is passed, the function will still execute but may return no results or all assignments depending on the controller implementation.

include_completed: Boolean flag (default: False) that determines whether to include completed and rejected reviews in the results. When False, only PENDING and IN_PROGRESS reviews are returned. When True, COMPLETED and REJECTED statuses are also included in the filter.

Return Value

Type: Dict[str, Any]

Returns a dictionary with three keys: 'success' (bool, always True in this implementation), 'reviews' (list of ReviewerAssignment objects matching the filter criteria), and 'total' (int, the total count of matching assignments). The dictionary structure follows a standard API response pattern.

Dependencies

  • CDocs
  • typing
  • datetime
  • logging

Required Imports

from typing import Dict, Any
from CDocs.models.user_extensions import DocUser
from CDocs.controllers import log_controller_action

Usage Example

from CDocs.models.user_extensions import DocUser
from your_module import get_user_pending_reviews

# Get a user object (typically from authentication/session)
user = DocUser.query.filter_by(email='user@example.com').first()

# Get only pending and in-progress reviews
result = get_user_pending_reviews(user)
print(f"Found {result['total']} pending reviews")
for review in result['reviews']:
    print(f"Review ID: {review.id}, Status: {review.status}")

# Get all reviews including completed ones
all_reviews = get_user_pending_reviews(user, include_completed=True)
print(f"Total reviews (including completed): {all_reviews['total']}")

Best Practices

  • Always ensure the user parameter is a valid DocUser object with a uid attribute before calling this function
  • The function has a hardcoded limit of 100 assignments - consider pagination for users with many reviews
  • The function always returns success=True even if no reviews are found; check the 'total' field to determine if results exist
  • This function is decorated with log_controller_action, so all calls will be logged for audit purposes
  • Consider error handling in the calling code as this function does not catch exceptions from the underlying controller
  • The offset is hardcoded to 0, so only the first 100 results are returned; implement pagination if more results are needed

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_user_assigned_reviews_v1 89.2% similar

    Retrieves all review assignments for a specific user, with optional filtering by status and inclusion of completed reviews.

    From: /tf/active/vicechatdev/CDocs single class/controllers/review_controller.py
  • function get_user_pending_reviews 85.1% similar

    Retrieves all pending (and optionally completed) document reviews assigned to a specific user, with support for date filtering and pagination.

    From: /tf/active/vicechatdev/CDocs/controllers/review_controller.py
  • function get_user_pending_approvals_v2 83.5% similar

    Retrieves pending approval assignments for a specific user, with an option to include completed and rejected approvals.

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

    Retrieves all review assignments for a specific user with optional filtering by status, including associated review cycle, document, and version details.

    From: /tf/active/vicechatdev/CDocs/controllers/review_controller.py
  • function get_user_assigned_approvals_v2 75.9% similar

    Retrieves all approval assignments for a specific user, with optional filtering by status and inclusion of completed approvals.

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