1.9 KiB
1.9 KiB
Department Permission And Admin Refactor Plan
For this round, continue based on the existing implementation and do not rebuild from scratch.
Goal
Refactor the admin and permission model so that:
- the
adminaccount is the onlysuper_admin - permissions are centered on departments instead of direct user-to-knowledge-base bindings
- knowledge bases belong to departments
- workspace visibility is filtered by department
- the admin page becomes a focused permission management console
- Dify health moves into a user-menu dialog
Scope
Backend
- Add
DepartmentandUserDepartmentAccessmodels - Add
primary_department_idtousers - Add
department_idtogroups - Backfill existing users and knowledge bases into a default department
- Enforce
adminas the onlysuper_admin - Replace group visibility calculation from
UserGroupAccessto department-based access - Add department CRUD and user permission management endpoints
Frontend
- Replace admin page with permission management
- Move Dify health to a modal entry under the user menu
- Rename user menu setting entry to
Dify设置 - Change inline user editing to dialog-driven create/edit flows
- Add department selector to workspace sidebar and group creation flow
- Keep UI feedback lightweight with toast-style transient notices
Validation
- Update backend tests for new department-based access model
- Run full backend pytest
- Run frontend build
- Deploy
api + worker + frontend - Verify role enforcement, department visibility, and Dify dialogs on server
Implementation Order
- Introduce department data model and migration with safe backfill.
- Update permission helpers, group/file APIs, and admin APIs to use departments.
- Rebuild the admin page into permission management and move Dify health into a dialog.
- Update workspace department filter and knowledge-base ownership UX.
- Run full validation and deploy.