后台:添加操作日志
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import {Application, RouteRecord, FrontendOrBackendSession, HandlerCallback } from "pinus";
|
||||
import { GM_API_TYPE, STATUS } from "../../../consts";
|
||||
import { GMGroupModel } from "../../../db/GMGroup";
|
||||
import { GMRecordModel } from "../../../db/GMRecord";
|
||||
import { GMUserGroupModel } from "../../../db/GMUserGroup";
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
|
||||
export function tokenFilter(app: Application) {
|
||||
return new Filter(app);
|
||||
@@ -12,11 +18,34 @@ Filter.prototype.before = async function (routeRecord: RouteRecord, msg: any, se
|
||||
const uid = session.get('uid');
|
||||
let route = routeRecord.route;
|
||||
console.log('********uid', uid, route);
|
||||
let dicApi = gameData.apiByUrl.get(route);
|
||||
if(!dicApi) {
|
||||
return next(new Error(), resResult(STATUS.GM_MISS_API));
|
||||
}
|
||||
let userGroup = await GMUserGroupModel.getUserGroupByUid(uid);
|
||||
if(!userGroup) {
|
||||
return next(new Error(), resResult(STATUS.GM_NO_AUTHORITY_GET));
|
||||
}
|
||||
let group = await GMGroupModel.getGroupById(userGroup.groupId);
|
||||
|
||||
if(!group) {
|
||||
return next(new Error(), resResult(STATUS.GM_NO_AUTHORITY_GET));
|
||||
}
|
||||
|
||||
if(!group.apis.includes(0) && !group.apis.includes(dicApi.id)) {
|
||||
return next(new Error(), resResult(STATUS.GM_NO_AUTHORITY_GET));
|
||||
}
|
||||
|
||||
next(null);
|
||||
};
|
||||
|
||||
Filter.prototype.after = function (err: Error, routeRecord: RouteRecord, msg: any, session: FrontendOrBackendSession, resp: any, next: HandlerCallback) {
|
||||
const uid = session.get('uid');
|
||||
let route = routeRecord.route;
|
||||
|
||||
let dicApi = gameData.apiByUrl.get(route);
|
||||
if(dicApi.type != GM_API_TYPE.find) {
|
||||
GMRecordModel.createRecord(uid, route, JSON.stringify(msg||{}), JSON.stringify(resp||{}));
|
||||
}
|
||||
next(err);
|
||||
};
|
||||
@@ -2,7 +2,7 @@ import { GMUserModel } from '@db/GMUser';
|
||||
import { GMUserGroupModel } from '@db/GMUserGroup'
|
||||
import { GMGroupModel } from '@db/GMGroup'
|
||||
import { GMRecordModel } from '@db/GMRecord'
|
||||
import { STATUS } from '@consts';
|
||||
import { GM_API_TYPE, STATUS } from '@consts';
|
||||
import { gameData } from '@pubUtils/data';
|
||||
|
||||
module.exports = () => {
|
||||
@@ -44,8 +44,8 @@ module.exports = () => {
|
||||
|
||||
ctx.user = user;
|
||||
await next();
|
||||
if(ctx.request.method == "POST") {
|
||||
await GMRecordModel.createRecord(user?user.uid:0, ctx.request.url, JSON.stringify(ctx.request.body||{}), JSON.stringify(ctx.body||{}));
|
||||
if(dicApi.type != GM_API_TYPE.find) {
|
||||
GMRecordModel.createRecord(user?user.uid:0, ctx.request.url, JSON.stringify(ctx.request.body||{}), JSON.stringify(ctx.body||{}));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { GMUserModel } from '@db/GMUser';
|
||||
import { GMUserGroupModel } from '@db/GMUserGroup'
|
||||
import { GMGroupModel } from '@db/GMGroup'
|
||||
import { GMRecordModel } from '@db/GMRecord'
|
||||
import { STATUS } from '@consts';
|
||||
import { GM_API_TYPE, STATUS } from '@consts';
|
||||
import { gameData } from 'app/pubUtils/data';
|
||||
|
||||
module.exports = () => {
|
||||
@@ -25,25 +25,27 @@ module.exports = () => {
|
||||
ctx.body = ctx.service.utils.resResult(STATUS.GM_MISS_API);
|
||||
return;
|
||||
}
|
||||
let userGroups = await GMUserGroupModel.getUserGroupByUid(user.uid, ctx.app.config.realEnv);
|
||||
let flag = 0;
|
||||
for(let userGroup of userGroups) {
|
||||
let { groupId } = userGroup;
|
||||
let group = await GMGroupModel.getGroupById(groupId);
|
||||
if(group) {
|
||||
if(group.apis.includes(dicApi.id)) {
|
||||
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") {
|
||||
await GMRecordModel.createRecord(user?user.uid:0, ctx.request.url, JSON.stringify(ctx.request.body||{}), JSON.stringify(ctx.body||{}));
|
||||
if(dicApi.type != GM_API_TYPE.find) {
|
||||
GMRecordModel.createRecord(user?user.uid:0, ctx.request.url, JSON.stringify(ctx.request.body||{}), JSON.stringify(ctx.body||{}));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user