feat: implement user authentication and permission-based data filtering

Add user login system with role-based access control:
- Admin users see all data and can filter by any manager
- Regular users only see records where ManagerName matches their username

New components:
- BIPUsersDAO: user authentication and management
- SessionManager: singleton session state management
- LoginDialog: modal login UI for app startup
- init_users.sql: initial user setup script

Permission enforcement:
- Material validation tab: hide manager filter for non-admin, force filter by current user
- Material type management: hide filter UI for non-admin, filter at database level
- Window title and status bar display current user info

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-02-09 18:17:31 +08:00
parent 57c23f4608
commit 04b99292ad
10 changed files with 607 additions and 22 deletions

View File

@@ -18,18 +18,21 @@ from gui.settings_tab import SettingsTab
class MainWindow:
"""主窗口类"""
def __init__(self, root: tk.Tk):
def __init__(self, root: tk.Tk, session_manager):
"""
初始化主窗口
Args:
root: Tk 根窗口
session_manager: SessionManager 实例,用于用户认证和权限管理
"""
self.root = root
self.config = ConfigManager()
self.session_manager = session_manager
# 设置窗口属性
self.root.title("ERP 自动化工具 v1.0")
# 设置窗口属性(包含用户信息)
user_type_display = "管理员" if session_manager.is_admin() else "用户"
self.root.title(f"ERP 自动化工具 v1.0 - {session_manager.get_username()} ({user_type_display})")
self.root.geometry("1000x700")
# 设置最小窗口大小
@@ -72,8 +75,8 @@ class MainWindow:
self.extraction_tab = DataExtractionTab(self.notebook, self.config)
self.notebook.add(self.extraction_tab, text="数据提取")
# 物料校验标签页
self.validation_tab = MaterialValidationTab(self.notebook, self.config)
# 物料校验标签页(传入 session_manager
self.validation_tab = MaterialValidationTab(self.notebook, self.config, self.session_manager)
self.notebook.add(self.validation_tab, text="物料校验")
# 数据查询标签页
@@ -97,6 +100,15 @@ class MainWindow:
)
status_label.pack(side=tk.LEFT, padx=5)
# 用户信息显示
user_type_display = "管理员" if self.session_manager.is_admin() else "用户"
self.user_info_var = tk.StringVar()
self.user_info_var.set(f"当前用户: {self.session_manager.get_username()} ({user_type_display})")
user_label = ttk.Label(
self.status_bar, textvariable=self.user_info_var, anchor=tk.E
)
user_label.pack(side=tk.RIGHT, padx=5)
# 配置状态指示
self.config_status = tk.StringVar()
self.config_status.set("配置已加载")