Skip to content

Commit 6008216

Browse files
committed
fix: 删除用户接口(deleteUser) 不允许删除 root 分组和 guest 分组的用户
1 parent 8006a52 commit 6008216

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

app/config/code-message.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ module.exports = {
5656
10076: '邮箱已被使用,请重新填入新的邮箱',
5757
10077: '不可将用户分配给不存在的分组',
5858
10078: '不可修改root用户的分组',
59+
10079: 'root分组和guest分组的用户不可删除',
5960
10080: '请求方法不允许',
6061
10100: '刷新令牌获取失败',
6162
10110: '{name}大小不能超过{size}字节',

app/dao/admin.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ class AdminDao {
102102
code: 10021
103103
});
104104
}
105+
const rootOrGuest = await UserGroupModel.findOne({
106+
where: {
107+
group_id: {
108+
[Op.in]: [GroupLevel.Root, GroupLevel.Guest]
109+
},
110+
user_id: id
111+
}
112+
})
113+
if (rootOrGuest) {
114+
throw new Forbidden({
115+
code: 10079
116+
})
117+
}
105118
let transaction;
106119
try {
107120
transaction = await sequelize.transaction();

0 commit comments

Comments
 (0)