Skip to content

Commit 9d326cb

Browse files
committed
Merge branch 'feat/development' into develop
2 parents 0cc3f83 + 6a0bf47 commit 9d326cb

File tree

5 files changed

+67
-24
lines changed

5 files changed

+67
-24
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ QQ 群号:643205479
6161

6262
## 版本日志
6363

64-
最新版本 `0.3.1`
64+
最新版本 `0.3.2`
65+
66+
### 0.3.2
67+
68+
1. `F` 更改文件上传返回字段
69+
2. `F` `GET admin/users``GET admin/group/all` 接口过滤 `root` 用户
70+
3. `F` `PUT /admin/user/{id}` 接口不允许修改 `root` 用户的分组
6571

6672
### 0.3.1
6773

app/dao/admin.js

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class AdminDao {
3232
async getUsers (groupId, page, count1) {
3333
let userIds = [];
3434
const condition = {
35+
where: {
36+
username: {
37+
[Op.ne]: 'root'
38+
}
39+
},
3540
offset: page * count1,
3641
limit: count1
3742
};
@@ -42,12 +47,8 @@ class AdminDao {
4247
}
4348
});
4449
userIds = userGroup.map(v => v.user_id);
45-
Object.assign(condition, {
46-
where: {
47-
id: {
48-
[Op.in]: userIds
49-
}
50-
}
50+
set(condition, 'where.id', {
51+
[Op.in]: userIds
5152
});
5253
}
5354
const { rows, count } = await UserModel.findAndCountAll(condition);
@@ -134,6 +135,29 @@ class AdminDao {
134135
errorCode: 10021
135136
});
136137
}
138+
139+
const userGroup = await UserGroupModel.findAll({
140+
where: {
141+
user_id: user.id
142+
}
143+
});
144+
const groupIds = userGroup.map(v => v.group_id);
145+
const isAdmin = await GroupModel.findOne({
146+
where: {
147+
name: 'root',
148+
id: {
149+
[Op.in]: groupIds
150+
}
151+
}
152+
});
153+
154+
if (isAdmin) {
155+
throw new Forbidden({
156+
msg: '不可修改root用户的分组',
157+
errorCode: 10078
158+
});
159+
}
160+
137161
for (const id of v.get('body.group_ids') || []) {
138162
const group = await GroupModel.findByPk(id);
139163
if (group.name === 'root') {
@@ -189,7 +213,13 @@ class AdminDao {
189213
}
190214

191215
async getAllGroups () {
192-
const allGroups = await GroupModel.findAll();
216+
const allGroups = await GroupModel.findAll({
217+
where: {
218+
name: {
219+
[Op.ne]: 'root'
220+
}
221+
}
222+
});
193223
return allGroups;
194224
}
195225

app/extensions/file/local-uploader.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class LocalUploader extends Uploader {
2424
if (exist) {
2525
arr.push({
2626
id: exist.id,
27-
path: `${siteDomain}/assets/${exist.path}`,
27+
key: file.fieldname,
28+
path: exist.path,
29+
url: `${siteDomain}/assets/${exist.path}`,
2830
type: exist.type,
2931
name: exist.name,
3032
extension: exist.extension,
@@ -50,7 +52,9 @@ class LocalUploader extends Uploader {
5052
);
5153
arr.push({
5254
id: saved.id,
53-
path: `${siteDomain}/assets/${saved.path}`,
55+
key: file.fieldname,
56+
path: exist.path,
57+
url: `${siteDomain}/assets/${saved.path}`,
5458
type: saved.type,
5559
name: file.name,
5660
extension: saved.extension,

app/models/permission.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class Permission extends Model {
2323
if (
2424
permissions.find(
2525
permission =>
26-
permission.name === permissionName && permission.module === moduleName
26+
permission.name === permissionName &&
27+
permission.module === moduleName
2728
)
2829
) {
2930
continue;
@@ -38,7 +39,9 @@ class Permission extends Model {
3839
}
3940
const permissionIds = [];
4041
for (const { id, name, module: moduleName } of permissions) {
41-
if (info.find(val => val.permission === name && val.module === moduleName)) {
42+
if (
43+
info.find(val => val.permission === name && val.module === moduleName)
44+
) {
4245
continue;
4346
}
4447
await this.destroy({

tests/api/cms/test1.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import "../../helper/initial";
2-
import request from "supertest";
1+
import '../../helper/initial';
2+
import request from 'supertest';
33
import { createApp } from '../../../app/app';
4-
import sequelize from "../../../app/libs/db";
4+
import sequelize from '../../../app/libs/db';
55

6-
describe("test1.test.js", () => {
6+
describe('test1.test.js', () => {
77
// 必须,app示例
88
let app;
99

@@ -21,23 +21,23 @@ describe("test1.test.js", () => {
2121

2222
// 测试 api 的函数
2323
// 测试 api的 URL 为 /cms/test/
24-
test("测试/cms/test/", async () => {
25-
const response = await request(app.callback()).get("/cms/test/");
24+
test('测试/cms/test/', async () => {
25+
const response = await request(app.callback()).get('/cms/test/');
2626
expect(response.status).toBe(200);
2727
expect(response.type).toMatch(/html/);
2828
});
2929

3030
// 这个测试不会通过,缺少认证,可以参考 user2.test.js 添加 bearer
31-
test("测试/cms/user/register 输入不规范用户名", async () => {
31+
test('测试/cms/user/register 输入不规范用户名', async () => {
3232
const response = await request(app.callback())
33-
.post("/cms/user/register")
33+
.post('/cms/user/register')
3434
.send({
35-
username: "p",
36-
password: "123456",
37-
confirm_password: "123456"
35+
username: 'p',
36+
password: '123456',
37+
confirm_password: '123456'
3838
});
3939
expect(response.status).toBe(400);
40-
expect(response.body).toHaveProperty("error_code", 10030);
40+
expect(response.body).toHaveProperty('error_code', 10030);
4141
expect(response.type).toMatch(/json/);
4242
});
4343
});

0 commit comments

Comments
 (0)