🔍 Code Extractor

function remove_user_access

Maturity: 57

Removes a user's access permissions from a specific document version share in FileCloud by delegating to the FileCloud client's remove_user_from_share method.

File:
/tf/active/vicechatdev/CDocs/controllers/share_controller.py
Lines:
844 - 862
Complexity:
simple

Purpose

This function serves as a wrapper to revoke document access for a specific user in a document management system. It retrieves the FileCloud client and calls its remove_user_from_share method to remove the specified user's access to a document version. The function includes error handling for cases where the FileCloud client cannot be obtained, returning a structured response indicating success or failure.

Source Code

def remove_user_access(document_version: DocumentVersion, user_id: str) -> Dict[str, Any]:
    """
    Remove a user's access to a document share.
    
    Args:
        document_version: The document version to remove access for
        user_id: FileCloud username of the user to remove
        
    Returns:
        Dict: Result of the operation
    """
    fc_client = get_filecloud_client()
    if not fc_client:
        return {
            'success': False,
            'message': 'Could not get FileCloud client'
        }
    
    return fc_client.remove_user_from_share(document_version, user_id)

Parameters

Name Type Default Kind
document_version DocumentVersion - positional_or_keyword
user_id str - positional_or_keyword

Parameter Details

document_version: A DocumentVersion model instance representing the specific version of a document from which user access should be removed. This object should contain all necessary metadata about the document version including its location and sharing configuration in FileCloud.

user_id: A string containing the FileCloud username of the user whose access should be revoked. This must be a valid FileCloud username that currently has access to the document share.

Return Value

Type: Dict[str, Any]

Returns a dictionary (Dict[str, Any]) containing the operation result. On success, returns the result from fc_client.remove_user_from_share() which typically includes a 'success' boolean and relevant operation details. On failure (when FileCloud client cannot be obtained), returns {'success': False, 'message': 'Could not get FileCloud client'}. The dictionary structure allows for flexible return values depending on the FileCloud client's response.

Dependencies

  • CDocs.models.document
  • CDocs.controllers.filecloud_controller
  • typing

Required Imports

from typing import Dict, Any
from CDocs.models.document import DocumentVersion
from CDocs.controllers.filecloud_controller import get_filecloud_client

Usage Example

from CDocs.models.document import DocumentVersion
from typing import Dict, Any

# Assume document_version is already retrieved from database
document_version = DocumentVersion.query.get(version_id)
user_to_remove = "john.doe@company.com"

# Remove user access
result = remove_user_access(document_version, user_to_remove)

if result['success']:
    print(f"Successfully removed access for {user_to_remove}")
else:
    print(f"Failed to remove access: {result.get('message', 'Unknown error')}")

Best Practices

  • Always check the 'success' key in the returned dictionary before assuming the operation completed successfully
  • Ensure the document_version object is valid and exists before calling this function
  • Verify that the user_id corresponds to a valid FileCloud username
  • Handle the case where get_filecloud_client() returns None by checking the returned message
  • Consider logging the operation result for audit purposes
  • Wrap calls to this function in try-except blocks to handle potential exceptions from the FileCloud client
  • Verify user has appropriate permissions to remove access from the document before calling this function

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function manage_user_share_access_v2 78.5% similar

    Manages user access permissions to a FileCloud document share, creating shares if needed and setting read-only or write access for specified users.

    From: /tf/active/vicechatdev/CDocs/controllers/permission_startup_check.py
  • function manage_user_share_access 76.4% similar

    Manages user access permissions (read-only or edit) to a specific document version share in FileCloud, creating the share if it doesn't exist.

    From: /tf/active/vicechatdev/CDocs/controllers/filecloud_helper.py
  • function manage_user_share_access_v1 74.8% similar

    Manages user access permissions to a FileCloud document share, creating the share if needed and setting read-only or write access for a specified user.

    From: /tf/active/vicechatdev/CDocs/controllers/filecloud_controller.py
  • function get_user_access_url 70.0% similar

    Retrieves a share URL for a document version and determines the appropriate access level (read/write) for a specific user based on their role (owner, author, reviewer, approver) and the document's current status.

    From: /tf/active/vicechatdev/CDocs/controllers/share_controller.py
  • function delete_document_from_filecloud 68.9% similar

    Deletes a document and its associated folder from FileCloud storage, with permission checks, audit logging, and error handling.

    From: /tf/active/vicechatdev/CDocs/controllers/filecloud_controller.py
← Back to Browse