This commit is contained in:
xiaojunnuo
2024-10-10 02:15:05 +08:00
parent b5d8935159
commit f0b2a61246
26 changed files with 262 additions and 120 deletions
@@ -19,36 +19,36 @@ export class AccessController extends CrudController<AccessService> {
@Post('/page', { summary: Constants.per.authOnly })
async page(@Body(ALL) body) {
body.query = body.query ?? {};
body.query.userId = this.ctx.user.id;
body.query.userId = this.getUserId();
return await super.page(body);
}
@Post('/list', { summary: Constants.per.authOnly })
async list(@Body(ALL) body) {
body.userId = this.ctx.user.id;
body.userId = this.getUserId();
return super.list(body);
}
@Post('/add', { summary: Constants.per.authOnly })
async add(@Body(ALL) bean) {
bean.userId = this.ctx.user.id;
bean.userId = this.getUserId();
return super.add(bean);
}
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean) {
await this.service.checkUserId(bean.id, this.ctx.user.id);
await this.service.checkUserId(bean.id, this.getUserId());
return super.update(bean);
}
@Post('/info', { summary: Constants.per.authOnly })
async info(@Query('id') id: number) {
await this.service.checkUserId(id, this.ctx.user.id);
await this.service.checkUserId(id, this.getUserId());
return super.info(id);
}
@Post('/delete', { summary: Constants.per.authOnly })
async delete(@Query('id') id: number) {
await this.service.checkUserId(id, this.ctx.user.id);
await this.service.checkUserId(id, this.getUserId());
return super.delete(id);
}
@@ -14,7 +14,7 @@ export class DnsProviderController extends BaseController {
@Post('/list', { summary: Constants.per.authOnly })
async list(@Query(ALL) query: any) {
query.userId = this.ctx.user.id;
query.userId = this.getUserId();
const list = this.service.getList();
return this.ok(list);
}
@@ -41,8 +41,8 @@ export class HistoryController extends CrudController<HistoryService> {
const publicSettings = await this.sysSettingsService.getPublicSettings();
const pipelineQuery: any = {};
if (!(publicSettings.managerOtherUserPipeline && isAdmin)) {
body.query.userId = this.ctx.user.id;
pipelineQuery.userId = this.ctx.user.id;
body.query.userId = this.getUserId();
pipelineQuery.userId = this.getUserId();
}
let pipelineIds: any = null;
@@ -70,7 +70,7 @@ export class HistoryController extends CrudController<HistoryService> {
async list(@Body(ALL) body) {
const isAdmin = await this.authService.isAdmin(this.ctx);
if (!isAdmin) {
body.userId = this.ctx.user.id;
body.userId = this.getUserId();
}
if (body.pipelineId == null) {
return this.ok([]);
@@ -84,7 +84,7 @@ export class HistoryController extends CrudController<HistoryService> {
@Post('/add', { summary: Constants.per.authOnly })
async add(@Body(ALL) bean: PipelineEntity) {
bean.userId = this.ctx.user.id;
bean.userId = this.getUserId();
return super.add(bean);
}
@@ -96,7 +96,7 @@ export class HistoryController extends CrudController<HistoryService> {
@Post('/save', { summary: Constants.per.authOnly })
async save(@Body(ALL) bean: HistoryEntity) {
bean.userId = this.ctx.user.id;
bean.userId = this.getUserId();
if (bean.id > 0) {
await this.authService.checkEntityUserId(this.ctx, this.getService(), bean.id);
}
@@ -106,7 +106,7 @@ export class HistoryController extends CrudController<HistoryService> {
@Post('/saveLog', { summary: Constants.per.authOnly })
async saveLog(@Body(ALL) bean: HistoryLogEntity) {
bean.userId = this.ctx.user.id;
bean.userId = this.getUserId();
if (bean.id > 0) {
await this.authService.checkEntityUserId(this.ctx, this.getService(), bean.id);
}
@@ -125,7 +125,7 @@ export class HistoryController extends CrudController<HistoryService> {
async deleteByIds(@Body(ALL) body: any) {
await this.authService.checkEntityUserId(this.ctx, this.getService(), body.ids);
const isAdmin = await this.authService.isAdmin(this.ctx);
const userId = isAdmin ? null : this.ctx.user.id;
const userId = isAdmin ? null : this.getUserId();
await this.getService().deleteByIds(body.ids, userId);
return this.ok();
}
@@ -162,7 +162,7 @@ export class HistoryController extends CrudController<HistoryService> {
if (history == null) {
throw new CommonException('historyId is null');
}
if (history.userId !== this.ctx.user.id) {
if (history.userId !== this.getUserId()) {
throw new PermissionException();
}
return await this.service.getFiles(history);
@@ -29,7 +29,7 @@ export class PipelineController extends CrudController<PipelineService> {
const isAdmin = await this.authService.isAdmin(this.ctx);
const publicSettings = await this.sysSettingsService.getPublicSettings();
if (!(publicSettings.managerOtherUserPipeline && isAdmin)) {
body.query.userId = this.ctx.user.id;
body.query.userId = this.getUserId();
}
const title = body.query.title;
@@ -50,7 +50,7 @@ export class PipelineController extends CrudController<PipelineService> {
@Post('/add', { summary: Constants.per.authOnly })
async add(@Body(ALL) bean: PipelineEntity) {
bean.userId = this.ctx.user.id;
bean.userId = this.getUserId();
return super.add(bean);
}
@@ -62,7 +62,7 @@ export class PipelineController extends CrudController<PipelineService> {
@Post('/save', { summary: Constants.per.authOnly })
async save(@Body(ALL) bean: PipelineEntity) {
bean.userId = this.ctx.user.id;
bean.userId = this.getUserId();
if (bean.id > 0) {
await this.authService.checkEntityUserId(this.ctx, this.getService(), bean.id);
}
@@ -14,14 +14,14 @@ export class PluginController extends BaseController {
@Post('/list', { summary: Constants.per.authOnly })
async list(@Query(ALL) query: any) {
query.userId = this.ctx.user.id;
query.userId = this.getUserId();
const list = this.service.getList();
return this.ok(list);
}
@Post('/groups', { summary: Constants.per.authOnly })
async groups(@Query(ALL) query: any) {
query.userId = this.ctx.user.id;
query.userId = this.getUserId();
const group = this.service.getGroups();
return this.ok(group);
}
@@ -68,6 +68,9 @@ export class HistoryService extends BaseService<HistoryEntity> {
}
private async clear(pipelineId: number, keepCount = 20) {
if (pipelineId == null) {
return;
}
const count = await this.repository.count({
where: {
pipelineId,
@@ -139,6 +142,9 @@ export class HistoryService extends BaseService<HistoryEntity> {
}
async deleteByIds(ids: number[], userId: number) {
if (!ids || ids.length === 0) {
return;
}
const condition: any = {
id: In(ids),
};
@@ -150,6 +156,9 @@ export class HistoryService extends BaseService<HistoryEntity> {
}
async deleteByPipelineId(id: number) {
if (id == null) {
return;
}
await this.repository.delete({
pipelineId: id,
});