Skip to content

Commit

Permalink
feat(*): 更新文档; 更新 group level 字段定义
Browse files Browse the repository at this point in the history
  • Loading branch information
smileShirmy committed Jun 21, 2020
1 parent 43d4cc8 commit 85b07fb
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 40 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ Lin-CMS 是林间有风团队经过大量项目实践所提炼出的一套**内

### 当前最新版本

lin-mizar(核心库) :0.3.2
lin-mizar(核心库) :0.3.3

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

### 文档地址

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

## 版本日志

最新版本 `0.3.3`
最新版本 `0.3.4`

### 0.3.4

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

### 0.3.3

Expand Down
4 changes: 3 additions & 1 deletion app/api/cms/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import { AdminDao } from '../../dao/admin';

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

const adminDao = new AdminDao();
Expand Down
4 changes: 3 additions & 1 deletion app/api/cms/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import { UserDao } from '../../dao/user';

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

const userDao = new UserDao();
Expand Down
6 changes: 3 additions & 3 deletions app/lib/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const IdentityType = {
};

const GroupLevel = {
Root: 'root',
Guest: 'guest',
User: 'user'
Root: 1,
Guest: 2,
User: 3
};

export { MountType, IdentityType, GroupLevel };
6 changes: 3 additions & 3 deletions app/model/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ Group.init(
comment: '分组信息:例如:搬砖的人'
},
level: {
type: Sequelize.ENUM('root', 'guest', 'user'),
defaultValue: 'user',
comment: '分组级别(root、guest分组只能存在一个'
type: Sequelize.INTEGER(2),
defaultValue: 3,
comment: '分组级别 1:root 2:guest 3:user(root、guest分组只能存在一个)'
}
},
merge(
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lin-cms-koa",
"version": "0.3.3",
"version": "0.3.4",
"description": "simple and practical CMS implememted by koa",
"main": "app/starter.js",
"scripts": {
Expand Down Expand Up @@ -48,9 +48,9 @@
"koa-bodyparser": "^4.2.1",
"koa-mount": "^4.0.0",
"koa-static": "^5.0.0",
"lin-mizar": "^0.3.2",
"lin-mizar": "^0.3.3",
"mysql2": "^2.1.0",
"sequelize": "^5.3.5",
"sequelize": "^5.21.13",
"validator": "^13.1.1"
}
}
6 changes: 3 additions & 3 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ CREATE TABLE lin_group
id int(10) unsigned NOT NULL AUTO_INCREMENT,
name varchar(60) NOT NULL COMMENT '分组名称,例如:搬砖者',
info varchar(255) DEFAULT NULL COMMENT '分组信息:例如:搬砖的人',
level ENUM('root', 'guest', 'user') DEFAULT 'user' COMMENT '分组级别(root、guest分组只能存在一个',
level tinyint(2) NOT NULL DEFAULT 3 COMMENT '分组级别 1:root 2:guest 3:user(root、guest分组只能存在一个)',
create_time datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
update_time datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
delete_time datetime(3) DEFAULT NULL,
Expand Down Expand Up @@ -190,10 +190,10 @@ VALUES (1, 1, 'USERNAME_PASSWORD', 'root',
'sha1$c419e500$1$84869e5560ebf3de26b6690386484929456d6c07');

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

INSERT INTO lin_group(id, name, info, level)
VALUES (2, 'guest', '游客组', 'guest');
VALUES (2, 'guest', '游客组', 2);

INSERT INTO lin_user_group(id, user_id, group_id)
VALUES (1, 1, 1);
Expand Down
41 changes: 19 additions & 22 deletions test/api/cms/admin.spec.js → test/api/cms/admin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import sequelize from '../../../app/lib/db';
import { saveTokens, getToken } from '../../helper/token';
import { get, isNumber, isArray } from 'lodash';

const sleep = (time) => new Promise(resolve => {
setTimeout(() => {
resolve();
}, time);
});

describe('/cms/admin', () => {
const { UserModel, UserIdentityModel } = require('../../../app/model/user');
const { GroupModel } = require('../../../app/model/group');
Expand All @@ -26,27 +20,28 @@ describe('/cms/admin', () => {

let token;

beforeAll(async () => {
beforeAll(async (done) => {
console.log('start admin');
// 初始化 app
app = await createApp();
done();
});

beforeEach(async () => {
await sleep(100);
await sequelize.query('START TRANSACTION;');
await sleep(100);
});

afterEach(async () => {
await sleep(100);
await sequelize.query('ROLLBACK;');
await sleep(100);
afterAll(async (done) => {
setTimeout(async () => {
await sequelize.close();
done();
}, 500);
});

afterAll(() => {
setTimeout(() => {
sequelize.close();
}, 500);
beforeEach(async (done) => {
await sequelize.sync({ force: true });
await UserModel.create({ username: 'root', nickname: 'root' });
await UserIdentityModel.create({ user_id: 1, identity_type: IdentityType.Password, identifier: 'root', credential: 'sha1$c419e500$1$84869e5560ebf3de26b6690386484929456d6c07' });
await GroupModel.create({ name: 'root', info: '超级用户组', level: 1 });
await GroupModel.create({ name: 'guest', info: '游客组', level: 2 });
await UserGroupModel.create({ user_id: 1, group_id: 1 });
done();
});

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

it('查询所有可分配的权限', async () => {
await PermissionModel.create({ name: '查看信息', module: '信息' });

const response = await request(app.callback())
.get('/cms/admin/permission')
.auth(token, {
type: 'bearer'
});
expect(response.status).toBe(200);
expect(response.type).toMatch(/json/);
const is = isArray(get(response, 'body.日志'));
const is = isArray(get(response, 'body.信息'));
expect(is).toBeTruthy();
});

Expand Down
2 changes: 1 addition & 1 deletion test/helper/initial.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { config } = require('lin-mizar/lin/config');
// 初始化数据库配置
(() => {
const settings = require('../../app/config/setting');
const secure = require('../../app/config/secure');
const secure = require('./secure');
const codeMessage = require('../../app/config/code-message');
config.getConfigFromObj({
...settings,
Expand Down
16 changes: 16 additions & 0 deletions test/helper/secure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

module.exports = {
db: {
database: 'lin-cms-test',
host: 'localhost',
dialect: 'mysql',
port: 3306,
username: 'root',
password: '123456',
logging: false,
timezone: '+08:00'
},
secret:
'\x88W\xf09\x91\x07\x98\x89\x87\x96\xa0A\xc68\xf9\xecJJU\x17\xc5V\xbe\x8b\xef\xd7\xd8\xd3\xe6\x95*4'
};

0 comments on commit 85b07fb

Please sign in to comment.