function remove_user_access
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.
/tf/active/vicechatdev/CDocs/controllers/share_controller.py
844 - 862
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.documentCDocs.controllers.filecloud_controllertyping
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
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function manage_user_share_access_v2 78.5% similar
-
function manage_user_share_access 76.4% similar
-
function manage_user_share_access_v1 74.8% similar
-
function get_user_access_url 70.0% similar
-
function delete_document_from_filecloud 68.9% similar