class SharePermissionIndicator
A Panel-based visual indicator component that displays document sharing permissions, showing whether a user has write access or read-only access to a document with color-coded status indicators.
/tf/active/vicechatdev/CDocs/ui/components/share_manager.py
25 - 113
moderate
Purpose
This component provides real-time visual feedback about document access permissions for a specific user and document combination. It automatically refreshes at configurable intervals to reflect permission changes, displaying a boolean indicator and styled text label that shows whether the user has edit mode (write access) or read-only access. The component integrates with the CDocs document management system to query current permissions and handles error states gracefully.
Source Code
class SharePermissionIndicator(param.Parameterized):
"""
A visual indicator for document sharing permissions.
This component shows whether a document has write access or read-only access
with appropriate visual indicators.
"""
document_uid = param.String(default="")
user_uid = param.String(default="")
refresh_interval = param.Integer(default=60000, doc="Refresh interval in milliseconds")
def __init__(self, **params):
super().__init__(**params)
# Create UI components
self.access_indicator = pn.indicators.BooleanIndicator(
value=False,
label="Write Access",
width=100
)
self.access_label = pn.pane.Markdown(
"Access: Read Only",
style={'color': 'orange', 'font-weight': 'bold'}
)
# Create layout
self.layout = pn.Row(
self.access_indicator,
self.access_label
)
# Initialize
self._update_indicator()
# Set up periodic refresh
if self.refresh_interval > 0:
self.refresh_cb = pn.state.add_periodic_callback(
self._update_indicator,
period=self.refresh_interval
)
def _update_indicator(self, *args, **kwargs):
"""Update access indicator based on current permissions."""
if not self.document_uid or not self.user_uid:
self.access_indicator.value = False
self.access_label.object = "Access: Not Available"
return
try:
# Get document version
document = ControlledDocument(uid=self.document_uid)
version = document.current_version
if not version:
self.access_indicator.value = False
self.access_label.object = "Access: No Version Available"
return
# Get access URL with permission info
result = get_user_access_url(version, self.user_uid)
if result.get('success', False):
write_access = result.get('write_access', False)
self.access_indicator.value = write_access
if write_access:
self.access_label.object = "Access: Edit Mode"
self.access_label.style = {'color': 'green', 'font-weight': 'bold'}
else:
self.access_label.object = "Access: Read Only"
self.access_label.style = {'color': 'orange', 'font-weight': 'bold'}
return
# Handle error
self.access_indicator.value = False
self.access_label.object = f"Access: Error - {result.get('message', 'Unknown')}"
self.access_label.style = {'color': 'red', 'font-weight': 'bold'}
except Exception as e:
logger.error(f"Error updating access indicator: {e}")
self.access_indicator.value = False
self.access_label.object = "Access: Error"
self.access_label.style = {'color': 'red', 'font-weight': 'bold'}
def view(self):
"""Return the layout for display."""
return self.layout
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
param.Parameterized | - |
Parameter Details
document_uid: String identifier for the document whose permissions are being monitored. Must be a valid UID from the ControlledDocument system. Empty string by default, which results in 'Not Available' status.
user_uid: String identifier for the user whose access permissions are being checked. Must be a valid UID from the DocUser system. Empty string by default, which results in 'Not Available' status.
refresh_interval: Integer specifying how often (in milliseconds) the component should check for permission updates. Default is 60000 (60 seconds). Set to 0 or negative to disable automatic refresh.
Return Value
Instantiation returns a SharePermissionIndicator object. The view() method returns a Panel Row layout containing the access indicator and label components that can be displayed in a Panel dashboard. The _update_indicator() method returns None but updates the component's visual state as a side effect.
Class Interface
Methods
__init__(self, **params) -> None
Purpose: Initialize the SharePermissionIndicator with UI components, layout, and periodic refresh callback
Parameters:
params: Keyword arguments passed to parent Parameterized class, typically document_uid, user_uid, and refresh_interval
Returns: None - initializes the instance with access_indicator, access_label, layout, and refresh_cb attributes
_update_indicator(self, *args, **kwargs) -> None
Purpose: Private method that queries current document permissions and updates the visual indicator and label based on user access level
Parameters:
args: Variable positional arguments (unused, accepted for callback compatibility)kwargs: Variable keyword arguments (unused, accepted for callback compatibility)
Returns: None - updates access_indicator.value, access_label.object, and access_label.style as side effects
view(self) -> pn.Row
Purpose: Return the Panel layout containing the access indicator and label for display in a Panel application
Returns: Panel Row layout object containing the boolean indicator and markdown label components
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
document_uid |
param.String | Parameter storing the document UID being monitored, default empty string | instance |
user_uid |
param.String | Parameter storing the user UID whose permissions are being checked, default empty string | instance |
refresh_interval |
param.Integer | Parameter storing the refresh interval in milliseconds, default 60000 | instance |
access_indicator |
pn.indicators.BooleanIndicator | Panel boolean indicator widget showing True (green) for write access, False (red) for read-only or no access | instance |
access_label |
pn.pane.Markdown | Panel markdown pane displaying text description of access level with color-coded styling (green for edit, orange for read-only, red for errors) | instance |
layout |
pn.Row | Panel Row layout containing the access_indicator and access_label arranged horizontally | instance |
refresh_cb |
pn.state.PeriodicCallback | Panel periodic callback object that triggers _update_indicator at the specified refresh_interval, only created if refresh_interval > 0 | instance |
Dependencies
panelparampandasloggingdatetimepyperclip
Required Imports
import panel as pn
import param
import pandas as pd
from typing import Dict, List, Any, Optional, Callable
import logging
import datetime
from CDocs.models.document import ControlledDocument, DocumentVersion
from CDocs.models.user_extensions import DocUser
from CDocs.controllers.share_controller import get_document_share_url, get_user_access_url, manage_document_permissions
import pyperclip
Usage Example
import panel as pn
import param
from CDocs.models.document import ControlledDocument
from CDocs.controllers.share_controller import get_user_access_url
import logging
logger = logging.getLogger(__name__)
pn.extension()
# Create the indicator with document and user UIDs
indicator = SharePermissionIndicator(
document_uid='doc_12345',
user_uid='user_67890',
refresh_interval=30000 # Refresh every 30 seconds
)
# Display in a Panel app
app = pn.template.FastListTemplate(
title='Document Access Monitor',
main=[indicator.view()]
)
app.servable()
# Or use in a notebook/dashboard
indicator.view() # Returns the layout for display
# Manually trigger an update if needed
indicator._update_indicator()
Best Practices
- Always provide both document_uid and user_uid parameters during instantiation to avoid 'Not Available' status
- The component automatically sets up a periodic callback for refreshing; ensure the Panel server is running to enable this functionality
- The refresh_interval should be balanced between responsiveness and server load; default 60 seconds is reasonable for most use cases
- The component handles errors gracefully and displays error messages in the UI, but check logs for detailed error information
- The _update_indicator method is private and called automatically; manual calls are rarely needed unless forcing an immediate refresh
- The component maintains state through Panel's reactive framework; avoid directly modifying access_indicator or access_label attributes
- When embedding in a Panel application, call view() to get the displayable layout rather than accessing internal components
- The periodic callback is registered with pn.state and will persist for the session lifetime; consider cleanup if dynamically creating/destroying instances
- Ensure the CDocs backend is accessible and responsive, as the component makes synchronous calls to get_user_access_url
- The component expects get_user_access_url to return a dictionary with 'success', 'write_access', and 'message' keys
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class DocumentShareManager 75.4% similar
-
class DocumentAccessControls 66.3% similar
-
function manage_document_permissions 52.7% similar
-
class CDocsApp 52.5% similar
-
function manage_user_share_access 51.7% similar