feat: 权限控制

This commit is contained in:
xiaojunnuo
2023-06-27 09:29:43 +08:00
parent fdc25dc0d7
commit 27a4c81c6d
37 changed files with 325 additions and 134 deletions
@@ -9,6 +9,7 @@ import {
} from '@midwayjs/decorator';
import { CrudController } from '../../../basic/crud-controller';
import { AccessService } from '../service/access-service';
import { Constants } from '../../../basic/constants';
/**
* 授权
@@ -23,49 +24,49 @@ export class AccessController extends CrudController<AccessService> {
return this.service;
}
@Post('/page')
@Post('/page', { summary: Constants.per.authOnly })
async page(@Body(ALL) body) {
body.query = body.query ?? {};
body.query.userId = this.ctx.user.id;
return super.page(body);
}
@Post('/list')
@Post('/list', { summary: Constants.per.authOnly })
async list(@Body(ALL) body) {
body.userId = this.ctx.user.id;
return super.list(body);
}
@Post('/add')
@Post('/add', { summary: Constants.per.authOnly })
async add(@Body(ALL) bean) {
bean.userId = this.ctx.user.id;
return super.add(bean);
}
@Post('/update')
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean) {
await this.service.checkUserId(bean.id, this.ctx.user.id);
return super.update(bean);
}
@Post('/info')
@Post('/info', { summary: Constants.per.authOnly })
async info(@Query('id') id) {
await this.service.checkUserId(id, this.ctx.user.id);
return super.info(id);
}
@Post('/delete')
@Post('/delete', { summary: Constants.per.authOnly })
async delete(@Query('id') id) {
await this.service.checkUserId(id, this.ctx.user.id);
return super.delete(id);
}
@Post('/define')
@Post('/define', { summary: Constants.per.authOnly })
async define(@Query('type') type) {
const provider = this.service.getDefineByType(type);
return this.ok(provider);
}
@Post('/accessTypeDict')
@Post('/accessTypeDict', { summary: Constants.per.authOnly })
async getAccessTypeDict() {
const list = this.service.getDefineList();
const dict = [];
@@ -8,6 +8,7 @@ import {
} from '@midwayjs/decorator';
import { DnsProviderService } from '../service/dns-provider-service';
import { BaseController } from '../../../basic/base-controller';
import {Constants} from "../../../basic/constants";
/**
* 插件
@@ -18,14 +19,14 @@ export class DnsProviderController extends BaseController {
@Inject()
service: DnsProviderService;
@Post('/list')
@Post('/list', { summary: Constants.per.authOnly })
async list(@Query(ALL) query) {
query.userId = this.ctx.user.id;
const list = this.service.getList();
return this.ok(list);
}
@Post('/dnsProviderTypeDict')
@Post('/dnsProviderTypeDict', { summary: Constants.per.authOnly })
async getDnsProviderTypeDict() {
const list = this.service.getList();
const dict = [];
@@ -13,6 +13,7 @@ import { HistoryService } from '../service/history-service';
import { HistoryLogService } from '../service/history-log-service';
import { HistoryEntity } from '../entity/history';
import { HistoryLogEntity } from '../entity/history-log';
import {Constants} from "../../../basic/constants";
/**
* 证书
@@ -29,13 +30,13 @@ export class HistoryController extends CrudController<HistoryService> {
return this.service;
}
@Post('/page')
@Post('/page', { summary: Constants.per.authOnly })
async page(@Body(ALL) body) {
body.query.userId = this.ctx.user.id;
return super.page(body);
}
@Post('/list')
@Post('/list', { summary: Constants.per.authOnly })
async list(@Body(ALL) body) {
body.userId = this.ctx.user.id;
if (body.pipelineId == null) {
@@ -52,19 +53,19 @@ export class HistoryController extends CrudController<HistoryService> {
return this.ok(listRet);
}
@Post('/add')
@Post('/add', { summary: Constants.per.authOnly })
async add(@Body(ALL) bean: PipelineEntity) {
bean.userId = this.ctx.user.id;
return super.add(bean);
}
@Post('/update')
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean) {
await this.service.checkUserId(bean.id, this.ctx.user.id);
return super.update(bean);
}
@Post('/save')
@Post('/save', { summary: Constants.per.authOnly })
async save(@Body(ALL) bean: HistoryEntity) {
bean.userId = this.ctx.user.id;
if (bean.id > 0) {
@@ -74,7 +75,7 @@ export class HistoryController extends CrudController<HistoryService> {
return this.ok(bean.id);
}
@Post('/saveLog')
@Post('/saveLog', { summary: Constants.per.authOnly })
async saveLog(@Body(ALL) bean: HistoryLogEntity) {
bean.userId = this.ctx.user.id;
if (bean.id > 0) {
@@ -84,20 +85,20 @@ export class HistoryController extends CrudController<HistoryService> {
return this.ok(bean.id);
}
@Post('/delete')
@Post('/delete', { summary: Constants.per.authOnly })
async delete(@Query('id') id) {
await this.service.checkUserId(id, this.ctx.user.id);
return super.delete(id);
}
@Post('/detail')
@Post('/detail', { summary: Constants.per.authOnly })
async detail(@Query('id') id) {
await this.service.checkUserId(id, this.ctx.user.id);
const detail = await this.service.detail(id);
return this.ok(detail);
}
@Post('/logs')
@Post('/logs', { summary: Constants.per.authOnly })
async logs(@Query('id') id) {
await this.logService.checkUserId(id, this.ctx.user.id);
const logInfo = await this.logService.info(id);
@@ -10,6 +10,7 @@ import {
import { CrudController } from '../../../basic/crud-controller';
import { PipelineService } from '../service/pipeline-service';
import { PipelineEntity } from '../entity/pipeline';
import { Constants } from '../../../basic/constants';
/**
* 证书
@@ -24,7 +25,7 @@ export class PipelineController extends CrudController<PipelineService> {
return this.service;
}
@Post('/page')
@Post('/page', { summary: Constants.per.authOnly })
async page(@Body(ALL) body) {
body.query.userId = this.ctx.user.id;
const buildQuery = qb => {
@@ -33,19 +34,19 @@ export class PipelineController extends CrudController<PipelineService> {
return super.page({ ...body, buildQuery });
}
@Post('/add')
@Post('/add', { summary: Constants.per.authOnly })
async add(@Body(ALL) bean: PipelineEntity) {
bean.userId = this.ctx.user.id;
return super.add(bean);
}
@Post('/update')
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean) {
await this.service.checkUserId(bean.id, this.ctx.user.id);
return super.update(bean);
}
@Post('/save')
@Post('/save', { summary: Constants.per.authOnly })
async save(@Body(ALL) bean: PipelineEntity) {
bean.userId = this.ctx.user.id;
if (bean.id > 0) {
@@ -56,20 +57,20 @@ export class PipelineController extends CrudController<PipelineService> {
return this.ok(bean.id);
}
@Post('/delete')
@Post('/delete', { summary: Constants.per.authOnly })
async delete(@Query('id') id) {
await this.service.checkUserId(id, this.ctx.user.id);
return super.delete(id);
}
@Post('/detail')
@Post('/detail', { summary: Constants.per.authOnly })
async detail(@Query('id') id) {
await this.service.checkUserId(id, this.ctx.user.id);
const detail = await this.service.detail(id);
return this.ok(detail);
}
@Post('/trigger')
@Post('/trigger', { summary: Constants.per.authOnly })
async trigger(@Query('id') id) {
await this.service.checkUserId(id, this.ctx.user.id);
await this.service.trigger(id);
@@ -8,6 +8,7 @@ import {
} from '@midwayjs/decorator';
import { BaseController } from '../../../basic/base-controller';
import { PluginService } from '../service/plugin-service';
import { Constants } from '../../../basic/constants';
/**
* 插件
@@ -18,7 +19,7 @@ export class PluginController extends BaseController {
@Inject()
service: PluginService;
@Post('/list')
@Post('/list', { summary: Constants.per.authOnly })
async list(@Query(ALL) query) {
query.userId = this.ctx.user.id;
const list = this.service.getList();