Skip to content

feat(roles): enhance role management panel with user list and inline … - #130

Merged
beilunyang merged 4 commits into
beilunyang:masterfrom
stevenlee87:feat/enhanced-role-management
Jul 30, 2026
Merged

feat(roles): enhance role management panel with user list and inline …#130
beilunyang merged 4 commits into
beilunyang:masterfrom
stevenlee87:feat/enhanced-role-management

Conversation

@stevenlee87

@stevenlee87 stevenlee87 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

feat(roles): 增强角色管理面板 - 用户列表与内联角色编辑

增强角色管理面板

概述

将皇帝的角色管理面板从单用户搜索+分配的表单,重新设计为完整的用户管理仪表板,支持可浏览的用户列表和内联角色编辑。

改动内容

新增 API:GET /api/roles/users

  • 新增 GET 接口,返回所有注册用户的分页列表及当前角色
  • 支持 pagepageSizesearch 查询参数
  • 搜索支持匹配用户名、邮箱和昵称
  • 为 GET 和已有的 POST 方法均添加了权限校验(PROMOTE_USER)

重构 promote-panel.tsx

  • 将原来的"搜索单个用户 + 选择角色 + 提交"流程替换为完整的用户列表视图
  • 每行用户显示头像、用户名/邮箱,以及内联角色下拉框,支持即时修改角色
  • 皇帝角色只展示不可编辑(受保护)
  • 新增实时搜索,输入即过滤
  • 新增分页功能(每页 10 个用户),支持上一页/下一页导航
  • 修改角色时单行 loading 状态反馈

i18n 更新(5 种语言:en、zh-CN、zh-TW、ja、ko)

  • 新增翻译 key:totalUsersprevPagenextPagepageInfo
  • 更新 searchPlaceholder,反映扩展后的搜索范围(用户

Enhanced Role Management Panel

Summary

Redesigned the Emperor's Role Management panel from a single-user search-and-assign form into a full user management dashboard with a browsable user list and inline role editing.

Changes

New API: GET /api/roles/users

  • Added a new GET endpoint that returns a paginated list of all registered users with their current roles
  • Supports page, pageSize, and search query parameters
  • Search matches against username, email, and display name
  • Added permission guard (PROMOTE_USER) to both GET and existing POST methods

Redesigned promote-panel.tsx

  • Replaced the old "search one user + select role + submit" workflow with a full user list view
  • Each user row displays avatar, username/email, and an inline role dropdown for instant role changes
  • Emperor role is displayed but not editable (protected)
  • Added real-time search with auto-filtering
  • Added pagination (10 users per page) with previous/next navigation
  • Per-row loading state during role updates

i18n Updates (5 locales: en, zh-CN, zh-TW, ja, ko)

  • Added new translation keys: totalUsers, prevPage, nextPage, pageInfo
  • Updated searchPlaceholder to reflect expanded search scope (username, email, or name)

role_management

…editing

Redesign the Emperor's Role Management panel from a single-user
search-and-assign form into a full user management dashboard with
browsable user list and inline role editing.
Add ability for Emperor to delete users from the role management panel:
- New POST /api/roles/delete endpoint with PROMOTE_USER permission guard,
  blocks deleting self or other emperors, cascades user data cleanup
- Trash button on each non-emperor row with confirmation dialog
- Auto-navigate to previous page when deleting the last user on a page
- i18n strings added for all 5 locales
@stevenlee87

Copy link
Copy Markdown
Contributor Author

🆕 Added: Delete User in Role Management

The Emperor (site owner) can now permanently delete users directly from the Role Management panel.

  • 🗑️ Click the trash button on any non-Emperor user row, then confirm in the dialog.
  • Safety guards: Emperor-only (HTTP 403 otherwise); cannot delete yourself; cannot delete an Emperor.
  • Cascade cleanup: removes the user's API keys, accounts, webhooks, mailboxes, and all their messages.
  • Auto-steps back to the previous page when deleting the last user on a page.
  • Full i18n support (en, zh-CN, zh-TW, ja, ko).

Endpoint: POST /api/roles/delete { userId } → { success: true } / { error } (400/403/500).
Files: app/api/roles/delete/route.ts, app/components/profile/promote-panel.tsx, app/i18n/messages/*/profile.json.


🆕 新增功能:角色管理 - 删除用户

皇帝(站点所有者)现在可以直接在角色管理面板永久删除用户。

  • 🗑️ 点击任意非皇帝用户行的删除按钮,在确认框中确认即可。
  • 安全防护:仅皇帝可用(否则返回 403);不能删除自己;不能删除皇帝。
  • 级联清理:一并删除该用户的 API 密钥、账号、Webhook、邮箱
  • 删除当前页最后一个用户时自动退回上一页。
  • 完整支持多语言(en、zh-CN、zh-TW、ja、ko)。

接口:POST /api/roles/delete,请求体 { userId } → 成功 { sur }(400/403/500)。
涉及文件:app/api/roles/delete/route.ts、app/components/profile/promote-panel.tsx、app/i18n/messages/*/profile.json。


Comment thread public/favicon.ico

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么改了 favicon.ico

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改回来了。之前不小心给改了。

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除用户功能,从 restful 语意上来说,应该放到 api/users 下面, 使用 http DELETE 方法实现删除,请修改

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改。请查看新的提交

- favicon: 从 public/favicon.ico 移回 app/favicon.ico(next-on-pages 1.13.16 下生产验证 /favicon.ico 正常返回)
- 删除用户: POST /api/roles/delete 改为 DELETE /api/users/[id],符合 RESTful 语义(资源 users + 标准 DELETE 方法)
@stevenlee87

Copy link
Copy Markdown
Contributor Author
role_management3

优化 GET /api/roles/users 用户列表的排序:
- 主排序:按角色等级 皇帝 → 公爵 → 骑士 → 平民(无角色用户排最后)
- 次排序:用户名长度(短者优先)
- 末排序:用户名字母序(大小写不敏感)
- 查询由 db.query.users.findMany(relational)改为显式 select + leftJoin,
  以支持基于角色名的 CASE 排序

Sort the user list returned by GET /api/roles/users:
- Primary: by role rank Emperor -> Duke -> Knight -> Civilian (users
  without a role sort last)
- Secondary: username length (shorter first)
- Tertiary: username alphabetical order (case-insensitive)
- Switch the query from db.query.users.findMany (relational) to an explicit
  select + leftJoin to enable CASE-based ordering on role name
@stevenlee87

Copy link
Copy Markdown
Contributor Author

新增提交 e0c66f0:用户列表排序优化

在已有「用户列表 + 内联角色编辑 + 删除用户」基础上,新增对 GET /api/roles/users 返回顺序的优化:

  • 主排序:按角色等级 皇帝 → 公爵 → 骑士 → 平民(无角色用户排最后)
  • 次排序:用户名长度(短者优先)
  • 末排序:用户名字母序(大小写不敏感)
  • 实现上将查询由 relational(db.query.users.findMany)改为显式 select + leftJoin,以支持基于角色名的 CASE 排序

New commit e0c66f0: user list sorting optimization

On top of the existing user list + inline role editing + user deletion, this improves the ordering returned by GET /api/roles/users:

  • Primary: by role rank Emperor → Duke → Knight → Civilian (users without a role sort last)
  • Secondary: username length (shorter first)
  • Tertiary: username alphabetical order (case-insensitive)
  • Implementation switches the query from relational (db.query.users.findMany) to an explicit select + leftJoin to enable CASE-based ordering on role name

@beilunyang
beilunyang merged commit 6c19aef into beilunyang:master Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants