Skip to content

Commit

Permalink
Merge pull request #76 from TaleLin/develop
Browse files Browse the repository at this point in the history
feat(*): 优化 permission 设置方式; 添加 code-message 映射; 支持自定义工作目录; 更新核心库 lin-mizar 到 0.3.3; HttpException 不允许直接修改 status; 传入的参数由 errorCode 改为 code
  • Loading branch information
smileShirmy authored Jun 21, 2020
2 parents 10ec44d + 85b07fb commit 3099950
Show file tree
Hide file tree
Showing 36 changed files with 878 additions and 607 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
127 changes: 31 additions & 96 deletions app/api/cms/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,24 @@ import {
DispatchPermissionsValidator,
RemovePermissionsValidator
} from '../../validator/admin';
import {
PositiveIdValidator,
PaginateValidator
} from '../../validator/common';
import { PositiveIdValidator, PaginateValidator } from '../../validator/common';

import { adminRequired } from '../../middleware/jwt';
import { AdminDao } from '../../dao/admin';

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

const adminDao = new AdminDao();

admin.linGet(
'getAllPermissions',
'/permission',
{
permission: '查询所有可分配的权限',
module: '管理员',
mount: false
},
admin.permission('查询所有可分配的权限'),
adminRequired,
async ctx => {
const permissions = await adminDao.getAllPermissions();
Expand All @@ -41,11 +37,7 @@ admin.linGet(
admin.linGet(
'getAdminUsers',
'/users',
{
permission: '查询所有用户',
module: '管理员',
mount: false
},
admin.permission('查询所有用户'),
adminRequired,
async ctx => {
const v = await new AdminUsersValidator().validate(ctx);
Expand All @@ -66,69 +58,50 @@ admin.linGet(
admin.linPut(
'changeUserPassword',
'/user/:id/password',
{
permission: '修改用户密码',
module: '管理员',
mount: false
},
admin.permission('修改用户密码'),
adminRequired,
async ctx => {
const v = await new ResetPasswordValidator().validate(ctx);
await adminDao.changeUserPassword(ctx, v);
ctx.success({
msg: '密码修改成功',
errorCode: 2
code: 4
});
}
);

admin.linDelete(
'deleteUser',
'/user/:id',
{
permission: '删除用户',
module: '管理员',
mount: false
},
admin.permission('删除用户'),
adminRequired,
async ctx => {
const v = await new PositiveIdValidator().validate(ctx);
const id = v.get('path.id');
await adminDao.deleteUser(ctx, id);
ctx.success({
msg: '删除用户成功',
errorCode: 3
code: 5
});
}
);

admin.linPut(
'updateUser',
'/user/:id',
{
permission: '管理员更新用户信息',
module: '管理员',
mount: false
},
admin.permission('管理员更新用户信息'),
adminRequired,
async ctx => {
const v = await new UpdateUserInfoValidator().validate(ctx);
await adminDao.updateUserInfo(ctx, v);
ctx.success({
msg: '更新用户成功',
errorCode: 4
code: 6
});
}
);

admin.linGet(
'getAdminGroups',
'/group',
{
permission: '查询所有权限组及其权限',
module: '管理员',
mount: false
},
admin.permission('查询所有权限组及其权限'),
adminRequired,
async ctx => {
const v = await new PaginateValidator().validate(ctx);
Expand All @@ -139,7 +112,7 @@ admin.linGet(
);
if (groups.length < 1) {
throw new NotFound({
msg: '未找到任何权限组'
code: 10024
});
}
ctx.json({
Expand All @@ -154,17 +127,13 @@ admin.linGet(
admin.linGet(
'getAllGroup',
'/group/all',
{
permission: '查询所有权限组',
module: '管理员',
mount: false
},
admin.permission('查询所有权限组'),
adminRequired,
async ctx => {
const groups = await adminDao.getAllGroups();
if (!groups || groups.length < 1) {
throw new NotFound({
msg: '未找到任何权限组'
code: 10024
});
}
ctx.json(groups);
Expand All @@ -174,11 +143,7 @@ admin.linGet(
admin.linGet(
'getGroup',
'/group/:id',
{
permission: '查询一个权限组及其权限',
module: '管理员',
mount: false
},
admin.permission('查询一个权限组及其权限'),
adminRequired,
async ctx => {
const v = await new PositiveIdValidator().validate(ctx);
Expand All @@ -190,119 +155,89 @@ admin.linGet(
admin.linPost(
'createGroup',
'/group',
{
permission: '新建权限组',
module: '管理员',
mount: false
},
admin.permission('新建权限组'),
adminRequired,
async ctx => {
const v = await new NewGroupValidator().validate(ctx);
const ok = await adminDao.createGroup(ctx, v);
if (!ok) {
throw new Failed({
msg: '新建分组失败'
code: 10027
});
}
ctx.success({
msg: '新建分组成功',
errorCode: 13
code: 15
});
}
);

admin.linPut(
'updateGroup',
'/group/:id',
{
permission: '更新一个权限组',
module: '管理员',
mount: false
},
admin.permission('更新一个权限组'),
adminRequired,
async ctx => {
const v = await new UpdateGroupValidator().validate(ctx);
await adminDao.updateGroup(ctx, v);
ctx.success({
msg: '更新分组成功',
errorCode: 5
code: 7
});
}
);

admin.linDelete(
'deleteGroup',
'/group/:id',
{
permission: '删除一个权限组',
module: '管理员',
mount: false
},
admin.permission('删除一个权限组'),
adminRequired,
async ctx => {
const v = await new PositiveIdValidator().validate(ctx);
const id = v.get('path.id');
await adminDao.deleteGroup(ctx, id);
ctx.success({
msg: '删除分组成功',
errorCode: 6
code: 8
});
}
);

admin.linPost(
'dispatchPermission',
'/permission/dispatch',
{
permission: '分配单个权限',
module: '管理员',
mount: false
},
admin.permission('分配单个权限'),
adminRequired,
async ctx => {
const v = await new DispatchPermissionValidator().validate(ctx);
await adminDao.dispatchPermission(ctx, v);
ctx.success({
msg: '添加权限成功',
errorCode: 6
code: 9
});
}
);

admin.linPost(
'dispatchPermissions',
'/permission/dispatch/batch',
{
permission: '分配多个权限',
module: '管理员',
mount: false
},
admin.permission('分配多个权限'),
adminRequired,
async ctx => {
const v = await new DispatchPermissionsValidator().validate(ctx);
await adminDao.dispatchPermissions(ctx, v);
ctx.success({
msg: '添加权限成功',
errorCode: 7
code: 9
});
}
);

admin.linPost(
'removePermissions',
'/permission/remove',
{
permission: '删除多个权限',
module: '管理员',
mount: false
},
admin.permission('删除多个权限'),
adminRequired,
async ctx => {
const v = await new RemovePermissionsValidator().validate(ctx);
await adminDao.removePermissions(ctx, v);
ctx.success({
msg: '删除权限成功',
errorCode: 8
code: 10
});
}
);
Expand Down
4 changes: 2 additions & 2 deletions app/api/cms/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const file = new LinRouter({
prefix: '/cms/file'
});

file.linPost('upload', '/', {}, loginRequired, async ctx => {
file.linPost('upload', '/', loginRequired, async ctx => {
const files = await ctx.multipart();
if (files.length < 1) {
throw new ParametersException({ msg: '未找到符合条件的文件资源' });
throw new ParametersException({ code: 10033 });
}
const uploader = new LocalUploader('app/assets');
const arr = await uploader.upload(files);
Expand Down
23 changes: 6 additions & 17 deletions app/api/cms/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,23 @@ import { groupRequired } from '../../middleware/jwt';
import { LogDao } from '../../dao/log';

const log = new LinRouter({
prefix: '/cms/log'
prefix: '/cms/log',
module: '日志'
});

const logDao = new LogDao();

log.linGet(
'getLogs',
'/',
{
permission: '查询所有日志',
module: '日志',
mount: true
},
log.permission('查询所有日志'),
groupRequired,
async ctx => {
const v = await new LogFindValidator().validate(ctx);
const { rows, total } = await logDao.getLogs(v);
if (!rows || rows.length < 1) {
throw new NotFound({
msg: '没有找到相关日志'
code: 10220
});
}
ctx.json({
Expand All @@ -40,11 +37,7 @@ log.linGet(
log.linGet(
'getUserLogs',
'/search',
{
permission: '搜索日志',
module: '日志',
mount: true
},
log.permission('搜索日志'),
groupRequired,
async ctx => {
const v = await new LogFindValidator().validate(ctx);
Expand All @@ -62,11 +55,7 @@ log.linGet(
log.linGet(
'getUsers',
'/users',
{
permission: '查询日志记录的用户',
module: '日志',
mount: true
},
log.permission('查询日志记录的用户'),
groupRequired,
async ctx => {
const v = await new PaginateValidator().validate(ctx);
Expand Down
Loading

0 comments on commit 3099950

Please sign in to comment.