mirror of
https://github.com/certd/certd.git
synced 2026-04-14 04:20:52 +08:00
chore: project controller
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
import { Inject } from '@midwayjs/core';
|
||||
import { ApplicationContext, Inject } from '@midwayjs/core';
|
||||
import type {IMidwayContainer} from '@midwayjs/core';
|
||||
import * as koa from '@midwayjs/koa';
|
||||
import { Constants } from './constants.js';
|
||||
import { isEnterprise } from './mode.js';
|
||||
|
||||
|
||||
export abstract class BaseController {
|
||||
@Inject()
|
||||
ctx: koa.Context;
|
||||
|
||||
@ApplicationContext()
|
||||
applicationContext: IMidwayContainer;
|
||||
|
||||
/**
|
||||
* 成功返回
|
||||
* @param data 返回数据
|
||||
@@ -55,4 +61,36 @@ export abstract class BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
getProjectId(permission:string) {
|
||||
if (!isEnterprise()) {
|
||||
return null
|
||||
}
|
||||
const projectIdStr = this.ctx.headers["project-id"] as string;
|
||||
if (!projectIdStr) {
|
||||
throw new Error("projectId 不能为空")
|
||||
}
|
||||
const userId = this.getUserId()
|
||||
const projectId = parseInt(projectIdStr)
|
||||
this.checkProjectPermission(userId, projectId,permission)
|
||||
return projectId;
|
||||
}
|
||||
|
||||
getProjectUserId(permission:string){
|
||||
let userId = this.getUserId()
|
||||
const projectId = this.getProjectId(permission)
|
||||
if(projectId){
|
||||
userId = 0
|
||||
}
|
||||
return {
|
||||
projectId,userId
|
||||
}
|
||||
}
|
||||
|
||||
async checkProjectPermission(userId: number, projectId: number,permission:string) {
|
||||
const projectService:any = await this.applicationContext.getAsync("projectService");
|
||||
await projectService.checkPermission({userId,projectId,permission})
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user