function get_document_permissions
Retrieves permission information for a specific document by its unique identifier, returning structured data about who can access the document and their permission levels.
/tf/active/vicechatdev/CDocs/controllers/api_handler.py
90 - 131
moderate
Purpose
This function serves as an API endpoint to fetch comprehensive permission details for a controlled document. It validates the document ID, retrieves the document object, and delegates to a permission management function to gather all access control information. The function includes error handling and logging for debugging and monitoring purposes. It's designed to be used in document management systems where access control and permission auditing are required.
Source Code
def get_document_permissions(doc_id: str) -> Dict[str, Any]:
"""
API endpoint to get document permissions information.
Args:
doc_id: Document UID
Returns:
Dict: Document permissions information
"""
try:
logger.debug(f"Getting permissions info for document {doc_id}")
if not doc_id:
return {
'success': False,
'message': 'Missing document ID'
}
# Get document
document = ControlledDocument(uid=doc_id)
if not document:
return {
'success': False,
'message': 'Document not found'
}
# Get current permissions info
permission_info = manage_document_permissions(document)
# Return the full permissions information
return permission_info
except Exception as e:
logger.error(f"Error getting document permissions: {e}")
import traceback
logger.error(traceback.format_exc())
return {
'success': False,
'message': f'Error: {str(e)}'
}
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
doc_id |
str | - | positional_or_keyword |
Parameter Details
doc_id: A string representing the unique identifier (UID) of the document whose permissions are being queried. Must be a non-empty string. If empty or None, the function returns an error response.
Return Value
Type: Dict[str, Any]
Returns a dictionary (Dict[str, Any]) containing permission information. On success, returns the output from manage_document_permissions() which includes permission details. On failure, returns a dictionary with 'success': False and 'message' key containing error details. The structure always includes at least 'success' (bool) and 'message' (str) keys, with additional permission data on successful retrieval.
Dependencies
loggingtypingpaneltracebackCDocs.models.documentCDocs.models.user_extensionsCDocs.controllers.share_controller
Required Imports
import logging
from typing import Dict, Any
from CDocs.models.document import ControlledDocument
from CDocs.controllers.share_controller import manage_document_permissions
Conditional/Optional Imports
These imports are only needed under specific conditions:
import traceback
Condition: only when an exception occurs during execution for detailed error logging
OptionalUsage Example
import logging
from typing import Dict, Any
from CDocs.models.document import ControlledDocument
from CDocs.controllers.share_controller import manage_document_permissions
# Setup logger
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
# Get permissions for a document
doc_id = "doc-12345-abcde"
result = get_document_permissions(doc_id)
if result['success']:
print(f"Permissions retrieved successfully")
# Access permission details from result
# Structure depends on manage_document_permissions return value
else:
print(f"Error: {result['message']}")
# Handle missing document ID
result = get_document_permissions("")
print(result) # {'success': False, 'message': 'Missing document ID'}
Best Practices
- Always validate the doc_id parameter before calling this function to avoid unnecessary API calls
- Handle both success and failure cases in the returned dictionary by checking the 'success' key
- Ensure proper logging configuration is in place before using this function for debugging purposes
- The function catches all exceptions broadly - consider implementing more specific exception handling for production use
- Ensure the calling context has appropriate permissions to query document permissions
- The function depends on manage_document_permissions() - understand its return structure for proper result handling
- Consider implementing rate limiting or caching if this endpoint is called frequently for the same documents
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_document_access 85.1% similar
-
function get_document 68.9% similar
-
function get_document_v1 68.5% similar
-
function manage_document_permissions 67.7% similar
-
function set_document_permissions_in_filecloud 66.9% similar