feat: add Admin user selection dialog (管理员用户选择对话框)
When an Admin user logs in, display a centered dialog allowing them to
select which user identity to use for the session. The Admin adopts the
selected user's permissions and operates as that user throughout the session.
Changes:
- Add UserSelectionDialog class in gui/user_selection_dialog.py
- Add SessionManager.switch_user() method to switch user identity
- Add SessionManager.get_original_admin() method to retrieve original admin
- Update MainWindow status bar to show when Admin operates as another user
- Display format: "当前用户: {username} ({type}) - 以 {admin_username} 身份登录"
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
Session Manager - Singleton pattern for managing authenticated user session
|
||||
"""
|
||||
from typing import Optional
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
|
||||
class SessionManager:
|
||||
@@ -150,3 +150,38 @@ class SessionManager:
|
||||
Dict with username and user_type if authenticated, None otherwise
|
||||
"""
|
||||
return self._current_user
|
||||
|
||||
def switch_user(self, user_info: Dict[str, Any]) -> bool:
|
||||
"""
|
||||
Switch to a different user (Admin only feature)
|
||||
|
||||
This allows an Admin user to operate as a different user
|
||||
with that user's permissions.
|
||||
|
||||
Args:
|
||||
user_info: Dict with {id, username, user_type}
|
||||
|
||||
Returns:
|
||||
True if switch successful
|
||||
"""
|
||||
if not self._current_user:
|
||||
return False
|
||||
|
||||
# Store original admin user for reference
|
||||
if not hasattr(self, '_original_admin_user'):
|
||||
self._original_admin_user = self._current_user.copy()
|
||||
|
||||
self._current_user = {
|
||||
'username': user_info['username'],
|
||||
'user_type': user_info['user_type']
|
||||
}
|
||||
return True
|
||||
|
||||
def get_original_admin(self) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Get the original Admin user before any user switch
|
||||
|
||||
Returns:
|
||||
Original admin user dict if a switch occurred, None otherwise
|
||||
"""
|
||||
return getattr(self, '_original_admin_user', None)
|
||||
|
||||
Reference in New Issue
Block a user