Skip to content

Commit 0cc3f83

Browse files
authored
Merge pull request #68 from TaleLin/shirmy-patch-2
feat: change 'permission' for 'auth'
2 parents ea0705e + dd661be commit 0cc3f83

File tree

10 files changed

+46
-42
lines changed

10 files changed

+46
-42
lines changed

README.md

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

3636
### 当前最新版本
3737

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

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

4242
### 文档地址
4343

@@ -61,13 +61,16 @@ QQ 群号:643205479
6161

6262
## 版本日志
6363

64-
最新版本 `0.3.0`
64+
最新版本 `0.3.1`
65+
66+
### 0.3.1
67+
68+
1. `F` 更新 `lin-mizar``0.3.2` 版本,路由属性名由 `auth` --> `permission`
6569

6670
### 0.3.0
6771

6872
1. `A` 将模型层抽离核心库进行重构
6973

70-
7174
## Lin CMS 的特点
7275

7376
Lin CMS 的构筑思想是有其自身特点的。下面我们阐述一些 Lin 的主要特点。

app/api/cms/admin.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ admin.linGet(
2727
'getAllPermissions',
2828
'/permission',
2929
{
30-
auth: '查询所有可分配的权限',
30+
permission: '查询所有可分配的权限',
3131
module: '管理员',
3232
mount: false
3333
},
@@ -42,7 +42,7 @@ admin.linGet(
4242
'getAdminUsers',
4343
'/users',
4444
{
45-
auth: '查询所有用户',
45+
permission: '查询所有用户',
4646
module: '管理员',
4747
mount: false
4848
},
@@ -67,7 +67,7 @@ admin.linPut(
6767
'changeUserPassword',
6868
'/user/:id/password',
6969
{
70-
auth: '修改用户密码',
70+
permission: '修改用户密码',
7171
module: '管理员',
7272
mount: false
7373
},
@@ -86,7 +86,7 @@ admin.linDelete(
8686
'deleteUser',
8787
'/user/:id',
8888
{
89-
auth: '删除用户',
89+
permission: '删除用户',
9090
module: '管理员',
9191
mount: false
9292
},
@@ -106,7 +106,7 @@ admin.linPut(
106106
'updateUser',
107107
'/user/:id',
108108
{
109-
auth: '管理员更新用户信息',
109+
permission: '管理员更新用户信息',
110110
module: '管理员',
111111
mount: false
112112
},
@@ -125,7 +125,7 @@ admin.linGet(
125125
'getAdminGroups',
126126
'/group',
127127
{
128-
auth: '查询所有权限组及其权限',
128+
permission: '查询所有权限组及其权限',
129129
module: '管理员',
130130
mount: false
131131
},
@@ -155,7 +155,7 @@ admin.linGet(
155155
'getAllGroup',
156156
'/group/all',
157157
{
158-
auth: '查询所有权限组',
158+
permission: '查询所有权限组',
159159
module: '管理员',
160160
mount: false
161161
},
@@ -175,7 +175,7 @@ admin.linGet(
175175
'getGroup',
176176
'/group/:id',
177177
{
178-
auth: '查询一个权限组及其权限',
178+
permission: '查询一个权限组及其权限',
179179
module: '管理员',
180180
mount: false
181181
},
@@ -191,7 +191,7 @@ admin.linPost(
191191
'createGroup',
192192
'/group',
193193
{
194-
auth: '新建权限组',
194+
permission: '新建权限组',
195195
module: '管理员',
196196
mount: false
197197
},
@@ -215,7 +215,7 @@ admin.linPut(
215215
'updateGroup',
216216
'/group/:id',
217217
{
218-
auth: '更新一个权限组',
218+
permission: '更新一个权限组',
219219
module: '管理员',
220220
mount: false
221221
},
@@ -234,7 +234,7 @@ admin.linDelete(
234234
'deleteGroup',
235235
'/group/:id',
236236
{
237-
auth: '删除一个权限组',
237+
permission: '删除一个权限组',
238238
module: '管理员',
239239
mount: false
240240
},
@@ -254,7 +254,7 @@ admin.linPost(
254254
'dispatchPermission',
255255
'/permission/dispatch',
256256
{
257-
auth: '分配单个权限',
257+
permission: '分配单个权限',
258258
module: '管理员',
259259
mount: false
260260
},
@@ -273,7 +273,7 @@ admin.linPost(
273273
'dispatchPermissions',
274274
'/permission/dispatch/batch',
275275
{
276-
auth: '分配多个权限',
276+
permission: '分配多个权限',
277277
module: '管理员',
278278
mount: false
279279
},
@@ -292,7 +292,7 @@ admin.linPost(
292292
'removePermissions',
293293
'/permission/remove',
294294
{
295-
auth: '删除多个权限',
295+
permission: '删除多个权限',
296296
module: '管理员',
297297
mount: false
298298
},

app/api/cms/log.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ log.linGet(
1515
'getLogs',
1616
'/',
1717
{
18-
auth: '查询所有日志',
18+
permission: '查询所有日志',
1919
module: '日志',
2020
mount: true
2121
},
@@ -41,7 +41,7 @@ log.linGet(
4141
'getUserLogs',
4242
'/search',
4343
{
44-
auth: '搜索日志',
44+
permission: '搜索日志',
4545
module: '日志',
4646
mount: true
4747
},
@@ -63,7 +63,7 @@ log.linGet(
6363
'getUsers',
6464
'/users',
6565
{
66-
auth: '查询日志记录的用户',
66+
permission: '查询日志记录的用户',
6767
module: '日志',
6868
mount: true
6969
},

app/api/cms/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test.linGet(
1919
'getTestMsg',
2020
'/json',
2121
{
22-
auth: '测试日志记录',
22+
permission: '测试日志记录',
2323
module: '信息',
2424
mount: true
2525
},
@@ -36,7 +36,7 @@ test.linGet(
3636
'getTestInfo',
3737
'/info',
3838
{
39-
auth: '查看lin的信息',
39+
permission: '查看lin的信息',
4040
module: '信息',
4141
mount: true
4242
},

app/api/cms/user.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ user.linPost(
2525
'userRegister',
2626
'/register',
2727
{
28-
auth: '注册',
28+
permission: '注册',
2929
module: '用户',
3030
mount: false
3131
},
@@ -45,7 +45,7 @@ user.linPost(
4545
'userLogin',
4646
'/login',
4747
{
48-
auth: '登陆',
48+
permission: '登陆',
4949
module: '用户',
5050
mount: false
5151
},
@@ -69,7 +69,7 @@ user.linPut(
6969
'userUpdate',
7070
'/',
7171
{
72-
auth: '更新用户信息',
72+
permission: '更新用户信息',
7373
module: '用户',
7474
mount: false
7575
},
@@ -88,7 +88,7 @@ user.linPut(
8888
'userUpdatePassword',
8989
'/change_password',
9090
{
91-
auth: '修改密码',
91+
permission: '修改密码',
9292
module: '用户',
9393
mount: false
9494
},
@@ -112,7 +112,7 @@ user.linGet(
112112
'userGetToken',
113113
'/refresh',
114114
{
115-
auth: '刷新令牌',
115+
permission: '刷新令牌',
116116
module: '用户',
117117
mount: false
118118
},
@@ -131,7 +131,7 @@ user.linGet(
131131
'userGetPermissions',
132132
'/permissions',
133133
{
134-
auth: '查询自己拥有的权限',
134+
permission: '查询自己拥有的权限',
135135
module: '用户',
136136
mount: true
137137
},
@@ -146,7 +146,7 @@ user.linGet(
146146
'getInformation',
147147
'/information',
148148
{
149-
auth: '查询自己信息',
149+
permission: '查询自己信息',
150150
module: '用户',
151151
mount: true
152152
},

app/api/v1/book.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ bookApi.linDelete(
7272
'deleteBook',
7373
'/:id',
7474
{
75-
auth: '删除图书',
75+
permission: '删除图书',
7676
module: '图书',
7777
mount: true
7878
},

app/middleware/jwt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async function groupRequired (ctx, next) {
112112
if (ctx.matched) {
113113
const routeName = ctx._matchedRouteName || ctx.routerName;
114114
const endpoint = `${ctx.method} ${routeName}`;
115-
const { auth, module } = routeMetaInfo.get(endpoint);
115+
const { permission, module } = routeMetaInfo.get(endpoint);
116116
const userGroup = await UserGroupModel.findAll({
117117
where: {
118118
user_id: ctx.currentUser.id
@@ -129,7 +129,7 @@ async function groupRequired (ctx, next) {
129129
const permissionIds = uniq(groupPermission.map(v => v.permission_id));
130130
const item = await PermissionModel.findOne({
131131
where: {
132-
name: auth,
132+
name: permission,
133133
module,
134134
id: {
135135
[Op.in]: permissionIds

app/middleware/logger.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const REG_XP = /(?<=\{)[^}]*(?=\})/g;
1313
* "getTestMsg",
1414
* "/json",
1515
* {
16-
* auth: "hello",
16+
* permission: "hello",
1717
* module: "world",
1818
* mount: true
1919
* },
@@ -44,9 +44,9 @@ function writeLog (template, ctx) {
4444
);
4545
if (ctx.matched) {
4646
const info = findAuthAndModule(ctx);
47-
let auth = '';
47+
let permission = '';
4848
if (info) {
49-
auth = get(info, 'auth');
49+
permission = get(info, 'permission');
5050
}
5151
const statusCode = ctx.status || 0;
5252
LogModel.createLog(
@@ -57,7 +57,7 @@ function writeLog (template, ctx) {
5757
status_code: statusCode,
5858
method: ctx.request.method,
5959
path: ctx.request.path,
60-
permission: auth
60+
permission
6161
},
6262
true
6363
);

app/models/permission.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ class Permission extends Model {
1919
transaction = await sequelize.transaction();
2020
const info = Array.from(routeMetaInfo.values());
2121
const permissions = await this.findAll();
22-
for (const { auth, module: moduleName } of info) {
22+
for (const { permission: permissionName, module: moduleName } of info) {
2323
if (
2424
permissions.find(
2525
permission =>
26-
permission.name === auth && permission.module === moduleName
26+
permission.name === permissionName && permission.module === moduleName
2727
)
2828
) {
2929
continue;
3030
}
3131
await this.create(
3232
{
33-
name: auth,
33+
name: permissionName,
3434
module: moduleName
3535
},
3636
{ transaction }
3737
);
3838
}
3939
const permissionIds = [];
4040
for (const { id, name, module: moduleName } of permissions) {
41-
if (info.find(val => val.auth === name && val.module === moduleName)) {
41+
if (info.find(val => val.permission === name && val.module === moduleName)) {
4242
continue;
4343
}
4444
await this.destroy({

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"koa-bodyparser": "^4.2.1",
4747
"koa-mount": "^4.0.0",
4848
"koa-static": "^5.0.0",
49-
"lin-mizar": "^0.3.1",
49+
"lin-mizar": "^0.3.2",
50+
"mysql2": "^2.1.0",
5051
"sequelize": "^5.3.5"
5152
}
5253
}

0 commit comments

Comments
 (0)