-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(roles): enhance role management panel with user list and inline … #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
beilunyang
merged 4 commits into
beilunyang:master
from
stevenlee87:feat/enhanced-role-management
Jul 30, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6341502
feat(roles): enhance role management panel with user list and inline …
stevenlee87 96373f3
feat(roles): add delete user functionality to role management
stevenlee87 c6e9eb0
refactor: favicon 移回 app/ + 删除用户改为 RESTful DELETE /api/users/[id]
stevenlee87 e0c66f0
feat(roles): sort user list by role rank and username
stevenlee87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { createDb } from "@/lib/db"; | ||
| import { users, userRoles, apiKeys } from "@/lib/schema"; | ||
| import { eq } from "drizzle-orm"; | ||
| import { ROLES, PERMISSIONS } from "@/lib/permissions"; | ||
| import { checkPermission } from "@/lib/auth"; | ||
| import { getUserId } from "@/lib/apiKey"; | ||
|
|
||
| export const runtime = "edge"; | ||
|
|
||
| export async function DELETE( | ||
| request: Request, | ||
| { params }: { params: Promise<{ id: string }> } | ||
| ) { | ||
| const canManage = await checkPermission(PERMISSIONS.PROMOTE_USER); | ||
| if (!canManage) { | ||
| return Response.json({ error: "权限不足" }, { status: 403 }); | ||
| } | ||
|
|
||
| try { | ||
| const { id: userId } = await params; | ||
| if (!userId) { | ||
| return Response.json({ error: "缺少必要参数" }, { status: 400 }); | ||
| } | ||
|
|
||
| const currentUserId = await getUserId(); | ||
| if (userId === currentUserId) { | ||
| return Response.json({ error: "不能删除自己" }, { status: 400 }); | ||
| } | ||
|
|
||
| const db = createDb(); | ||
|
|
||
| const targetUserRole = await db.query.userRoles.findFirst({ | ||
| where: eq(userRoles.userId, userId), | ||
| with: { | ||
| role: true, | ||
| }, | ||
| }); | ||
|
|
||
| if (targetUserRole?.role.name === ROLES.EMPEROR) { | ||
| return Response.json({ error: "不能删除皇帝" }, { status: 400 }); | ||
| } | ||
|
|
||
| // apiKeys 未配置级联删除,需先手动删除;其余(accounts / emails→messages / webhooks / userRoles)由外键级联处理 | ||
| await db.delete(apiKeys).where(eq(apiKeys.userId, userId)); | ||
| await db.delete(users).where(eq(users.id, userId)); | ||
|
|
||
| return Response.json({ success: true }); | ||
| } catch (error) { | ||
| console.error("Failed to delete user:", error); | ||
| return Response.json({ error: "操作失败" }, { status: 500 }); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 方法实现删除,请修改
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改。请查看新的提交