Skip to content

Commit 85b07fb

Browse files
committed
feat(*): 更新文档; 更新 group level 字段定义
1 parent 43d4cc8 commit 85b07fb

File tree

10 files changed

+65
-40
lines changed

10 files changed

+65
-40
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ Lin-CMS 是林间有风团队经过大量项目实践所提炼出的一套**内
3535

3636
### 当前最新版本
3737

38-
lin-mizar(核心库) :0.3.2
38+
lin-mizar(核心库) :0.3.3
3939

40-
lin-cms-koa(当前示例工程):0.3.3
40+
lin-cms-koa(当前示例工程):0.3.4
4141

4242
### 文档地址
4343

@@ -61,7 +61,15 @@ QQ 群号:643205479
6161

6262
## 版本日志
6363

64-
最新版本 `0.3.3`
64+
最新版本 `0.3.4`
65+
66+
### 0.3.4
67+
68+
1. `U` 更新路由视图权限挂载的方式
69+
2. `U` HttpException 不允许直接修改 status,传入的参数由 errorCode 改为 code
70+
3. `U` 新增 code-message 配置,返回的成功码和错误码都在这里配置
71+
4. `U` 支持自定义工作目录
72+
5. `U` 更新核心库 lin-mizar 到 0.3.3 版本
6573

6674
### 0.3.3
6775

app/api/cms/admin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import { AdminDao } from '../../dao/admin';
1616

1717
const admin = new LinRouter({
1818
prefix: '/cms/admin',
19-
module: '管理员'
19+
module: '管理员',
20+
// 管理员权限暂不支持分配,开启分配后也无实际作用
21+
mountPermission: false
2022
});
2123

2224
const adminDao = new AdminDao();

app/api/cms/user.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import { UserDao } from '../../dao/user';
1717

1818
const user = new LinRouter({
1919
prefix: '/cms/user',
20-
module: '用户'
20+
module: '用户',
21+
// 用户权限暂不支持分配,开启分配后也无实际作用
22+
mountPermission: false
2123
});
2224

2325
const userDao = new UserDao();

app/lib/type.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const IdentityType = {
88
};
99

1010
const GroupLevel = {
11-
Root: 'root',
12-
Guest: 'guest',
13-
User: 'user'
11+
Root: 1,
12+
Guest: 2,
13+
User: 3
1414
};
1515

1616
export { MountType, IdentityType, GroupLevel };

app/model/group.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ Group.init(
3535
comment: '分组信息:例如:搬砖的人'
3636
},
3737
level: {
38-
type: Sequelize.ENUM('root', 'guest', 'user'),
39-
defaultValue: 'user',
40-
comment: '分组级别(root、guest分组只能存在一个'
38+
type: Sequelize.INTEGER(2),
39+
defaultValue: 3,
40+
comment: '分组级别 1:root 2:guest 3:user(root、guest分组只能存在一个)'
4141
}
4242
},
4343
merge(

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lin-cms-koa",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "simple and practical CMS implememted by koa",
55
"main": "app/starter.js",
66
"scripts": {
@@ -48,9 +48,9 @@
4848
"koa-bodyparser": "^4.2.1",
4949
"koa-mount": "^4.0.0",
5050
"koa-static": "^5.0.0",
51-
"lin-mizar": "^0.3.2",
51+
"lin-mizar": "^0.3.3",
5252
"mysql2": "^2.1.0",
53-
"sequelize": "^5.3.5",
53+
"sequelize": "^5.21.13",
5454
"validator": "^13.1.1"
5555
}
5656
}

schema.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ CREATE TABLE lin_group
7272
id int(10) unsigned NOT NULL AUTO_INCREMENT,
7373
name varchar(60) NOT NULL COMMENT '分组名称,例如:搬砖者',
7474
info varchar(255) DEFAULT NULL COMMENT '分组信息:例如:搬砖的人',
75-
level ENUM('root', 'guest', 'user') DEFAULT 'user' COMMENT '分组级别(root、guest分组只能存在一个',
75+
level tinyint(2) NOT NULL DEFAULT 3 COMMENT '分组级别 1:root 2:guest 3:user(root、guest分组只能存在一个)',
7676
create_time datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
7777
update_time datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
7878
delete_time datetime(3) DEFAULT NULL,
@@ -190,10 +190,10 @@ VALUES (1, 1, 'USERNAME_PASSWORD', 'root',
190190
'sha1$c419e500$1$84869e5560ebf3de26b6690386484929456d6c07');
191191

192192
INSERT INTO lin_group(id, name, info, level)
193-
VALUES (1, 'root', '超级用户组', 'root');
193+
VALUES (1, 'root', '超级用户组', 1);
194194

195195
INSERT INTO lin_group(id, name, info, level)
196-
VALUES (2, 'guest', '游客组', 'guest');
196+
VALUES (2, 'guest', '游客组', 2);
197197

198198
INSERT INTO lin_user_group(id, user_id, group_id)
199199
VALUES (1, 1, 1);
Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ import sequelize from '../../../app/lib/db';
77
import { saveTokens, getToken } from '../../helper/token';
88
import { get, isNumber, isArray } from 'lodash';
99

10-
const sleep = (time) => new Promise(resolve => {
11-
setTimeout(() => {
12-
resolve();
13-
}, time);
14-
});
15-
1610
describe('/cms/admin', () => {
1711
const { UserModel, UserIdentityModel } = require('../../../app/model/user');
1812
const { GroupModel } = require('../../../app/model/group');
@@ -26,27 +20,28 @@ describe('/cms/admin', () => {
2620

2721
let token;
2822

29-
beforeAll(async () => {
23+
beforeAll(async (done) => {
24+
console.log('start admin');
3025
// 初始化 app
3126
app = await createApp();
27+
done();
3228
});
3329

34-
beforeEach(async () => {
35-
await sleep(100);
36-
await sequelize.query('START TRANSACTION;');
37-
await sleep(100);
38-
});
39-
40-
afterEach(async () => {
41-
await sleep(100);
42-
await sequelize.query('ROLLBACK;');
43-
await sleep(100);
30+
afterAll(async (done) => {
31+
setTimeout(async () => {
32+
await sequelize.close();
33+
done();
34+
}, 500);
4435
});
4536

46-
afterAll(() => {
47-
setTimeout(() => {
48-
sequelize.close();
49-
}, 500);
37+
beforeEach(async (done) => {
38+
await sequelize.sync({ force: true });
39+
await UserModel.create({ username: 'root', nickname: 'root' });
40+
await UserIdentityModel.create({ user_id: 1, identity_type: IdentityType.Password, identifier: 'root', credential: 'sha1$c419e500$1$84869e5560ebf3de26b6690386484929456d6c07' });
41+
await GroupModel.create({ name: 'root', info: '超级用户组', level: 1 });
42+
await GroupModel.create({ name: 'guest', info: '游客组', level: 2 });
43+
await UserGroupModel.create({ user_id: 1, group_id: 1 });
44+
done();
5045
});
5146

5247
it('超级管理员登录', async () => {
@@ -63,14 +58,16 @@ describe('/cms/admin', () => {
6358
});
6459

6560
it('查询所有可分配的权限', async () => {
61+
await PermissionModel.create({ name: '查看信息', module: '信息' });
62+
6663
const response = await request(app.callback())
6764
.get('/cms/admin/permission')
6865
.auth(token, {
6966
type: 'bearer'
7067
});
7168
expect(response.status).toBe(200);
7269
expect(response.type).toMatch(/json/);
73-
const is = isArray(get(response, 'body.日志'));
70+
const is = isArray(get(response, 'body.信息'));
7471
expect(is).toBeTruthy();
7572
});
7673

test/helper/initial.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { config } = require('lin-mizar/lin/config');
33
// 初始化数据库配置
44
(() => {
55
const settings = require('../../app/config/setting');
6-
const secure = require('../../app/config/secure');
6+
const secure = require('./secure');
77
const codeMessage = require('../../app/config/code-message');
88
config.getConfigFromObj({
99
...settings,

test/helper/secure.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
module.exports = {
4+
db: {
5+
database: 'lin-cms-test',
6+
host: 'localhost',
7+
dialect: 'mysql',
8+
port: 3306,
9+
username: 'root',
10+
password: '123456',
11+
logging: false,
12+
timezone: '+08:00'
13+
},
14+
secret:
15+
'\x88W\xf09\x91\x07\x98\x89\x87\x96\xa0A\xc68\xf9\xecJJU\x17\xc5V\xbe\x8b\xef\xd7\xd8\xd3\xe6\x95*4'
16+
};

0 commit comments

Comments
 (0)