后台:权限

This commit is contained in:
luying
2021-12-21 19:42:37 +08:00
parent 151ac33b91
commit 7d0808a9dc
26 changed files with 1009 additions and 818 deletions
+18 -16
View File
@@ -2,8 +2,8 @@ import { GMUserModel } from '@db/GMUser';
import { GMUserGroupModel } from '@db/GMUserGroup'
import { GMGroupModel } from '@db/GMGroup'
import { GMRecordModel } from '@db/GMRecord'
import { ApiModel } from '@db/Api';
import { STATUS } from '@consts';
import { gameData } from '@pubUtils/data';
module.exports = () => {
return async function tokenParser(ctx, next) {
@@ -20,26 +20,28 @@ module.exports = () => {
return;
}
const url = ctx.request.url;
let apiResult = await ApiModel.getApi(url);
if(!apiResult) {
let dicApi = gameData.apiByUrl.get(url);
if(!dicApi) {
ctx.body = ctx.service.utils.resResult(STATUS.GM_MISS_API);
return;
}
let userGroups = await GMUserGroupModel.getUserGroupByUid(user.uid, 1);
let flag = 0;
for(let userGroup of userGroups) {
let { groupId } = userGroup;
let group = await GMGroupModel.getGroupById(groupId);
if(group) {
if(group.apis.includes(apiResult.apiId)) {
flag = 1; break;
}
}
}
if(flag != 1) {
let userGroup = await GMUserGroupModel.getUserGroupByUid(user.uid);
if(!userGroup) {
ctx.body = ctx.service.utils.resResult(STATUS.GM_NO_AUTHORITY_GET);
return;
return
}
let group = await GMGroupModel.getGroupById(userGroup.groupId);
if(!group) {
ctx.body = ctx.service.utils.resResult(STATUS.GM_NO_AUTHORITY_GET);
return
}
if(!group.apis.includes(0) && !group.apis.includes(dicApi.id)) {
ctx.body = ctx.service.utils.resResult(STATUS.GM_NO_AUTHORITY_GET);
return
}
ctx.user = user;
await next();
if(ctx.request.method == "POST") {