mirror of
https://github.com/certd/certd.git
synced 2026-04-24 12:27:25 +08:00
chore: admin mode
This commit is contained in:
@@ -11,7 +11,7 @@ CREATE TABLE "cd_project"
|
||||
|
||||
|
||||
CREATE INDEX "index_project_user_id" ON "cd_project" ("user_id");
|
||||
INSERT INTO cd_project (id, user_id, "name", "disabled") VALUES (1, 0, 'default', false);
|
||||
INSERT INTO cd_project (id, user_id, "name", "disabled") VALUES (1, 1, 'default', false);
|
||||
|
||||
|
||||
ALTER TABLE cd_cert_info ADD COLUMN project_id integer;
|
||||
@@ -33,21 +33,60 @@ ALTER TABLE cd_addon ADD COLUMN project_id integer;
|
||||
CREATE INDEX "index_addon_project_id" ON "cd_addon" ("project_id");
|
||||
|
||||
ALTER TABLE pi_pipeline ADD COLUMN project_id integer;
|
||||
CREATE INDEX "index_pipeline_project_id" ON "cd_pipeline" ("project_id");
|
||||
CREATE INDEX "index_pipeline_project_id" ON "pi_pipeline" ("project_id");
|
||||
|
||||
ALTER TABLE pi_pipeline_group ADD COLUMN project_id integer;
|
||||
CREATE INDEX "index_pipeline_group_project_id" ON "cd_pipeline_group" ("project_id");
|
||||
CREATE INDEX "index_pipeline_group_project_id" ON "pi_pipeline_group" ("project_id");
|
||||
|
||||
ALTER TABLE pi_storage ADD COLUMN project_id integer;
|
||||
CREATE INDEX "index_storage_project_id" ON "cd_storage" ("project_id");
|
||||
CREATE INDEX "index_storage_project_id" ON "pi_storage" ("project_id");
|
||||
|
||||
ALTER TABLE pi_notification ADD COLUMN project_id integer;
|
||||
CREATE INDEX "index_notification_project_id" ON "cd_notification" ("project_id");
|
||||
CREATE INDEX "index_notification_project_id" ON "pi_notification" ("project_id");
|
||||
|
||||
ALTER TABLE pi_history ADD COLUMN project_id integer;
|
||||
CREATE INDEX "index_history_project_id" ON "cd_history" ("project_id");
|
||||
CREATE INDEX "index_history_project_id" ON "pi_history" ("project_id");
|
||||
|
||||
ALTER TABLE pi_history_log ADD COLUMN project_id integer;
|
||||
CREATE INDEX "index_history_log_project_id" ON "cd_history_log" ("project_id");
|
||||
CREATE INDEX "index_history_log_project_id" ON "pi_history_log" ("project_id");
|
||||
|
||||
ALTER TABLE pi_template ADD COLUMN project_id integer;
|
||||
CREATE INDEX "index_template_project_id" ON "pi_template" ("project_id");
|
||||
|
||||
|
||||
|
||||
CREATE TABLE "cd_project_member"
|
||||
(
|
||||
"id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
"project_id" integer NOT NULL,
|
||||
"permission" varchar(128) NOT NULL DEFAULT ('read'),
|
||||
"create_time" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
|
||||
"update_time" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP)
|
||||
);
|
||||
|
||||
|
||||
CREATE INDEX "index_project_member_user_id" ON "cd_project_member" ("user_id");
|
||||
CREATE INDEX "index_project_member_project_id" ON "cd_project_member" ("project_id");
|
||||
|
||||
|
||||
CREATE TABLE "cd_audit_log"
|
||||
(
|
||||
"id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
"username" varchar(128) NOT NULL,
|
||||
"project_id" integer NOT NULL,
|
||||
"project_name" varchar(512) NOT NULL,
|
||||
"type" varchar(128) NOT NULL,
|
||||
"action" varchar(128) NOT NULL DEFAULT ('read'),
|
||||
"content" text NOT NULL,
|
||||
"ip_address" varchar(128) NOT NULL,
|
||||
"create_time" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
|
||||
"update_time" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP)
|
||||
);
|
||||
|
||||
|
||||
CREATE INDEX "index_audit_log_user_id" ON "cd_audit_log" ("user_id");
|
||||
CREATE INDEX "index_audit_log_project_id" ON "cd_audit_log" ("project_id");
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { BaseController, Constants } from '@certd/lib-server';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
|
||||
import { ProjectService } from '../../../modules/sys/enterprise/service/project-service.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/enterprise/project')
|
||||
export class UserProjectController extends BaseController {
|
||||
@Inject()
|
||||
service: ProjectService;
|
||||
@Inject()
|
||||
authService: AuthService;
|
||||
|
||||
getService(): ProjectService {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/list', { summary: Constants.per.authOnly })
|
||||
async list(@Body(ALL) body: any) {
|
||||
const userId= this.getUserId();
|
||||
const res = await this.service.getByUserId(userId);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,9 @@ export class AuditLogEntity {
|
||||
@Column({ name: 'project_name', comment: '项目名称' })
|
||||
projectName: string;
|
||||
|
||||
@Column({ name: 'type', comment: '类型' })
|
||||
type: string;
|
||||
|
||||
@Column({ name: 'action', comment: '操作' })
|
||||
action: string;
|
||||
|
||||
|
||||
@@ -28,4 +28,7 @@ export class ProjectEntity {
|
||||
default: () => 'CURRENT_TIMESTAMP',
|
||||
})
|
||||
updateTime: Date;
|
||||
|
||||
// user permission read write admin
|
||||
permission:string
|
||||
}
|
||||
|
||||
@@ -38,4 +38,12 @@ export class ProjectMemberService extends BaseService<ProjectMemberEntity> {
|
||||
return await super.add(bean)
|
||||
}
|
||||
|
||||
async getByUserId(userId: number) {
|
||||
return await this.repository.find({
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import {Inject, Provide, Scope, ScopeEnum} from '@midwayjs/core';
|
||||
import {BaseService, SysSettingsService} from '@certd/lib-server';
|
||||
import {InjectEntityModel} from '@midwayjs/typeorm';
|
||||
import {Repository} from 'typeorm';
|
||||
import {In, Repository} from 'typeorm';
|
||||
import { ProjectEntity } from '../entity/project.js';
|
||||
import { ProjectMemberService } from './project-member-service.js';
|
||||
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||
@@ -10,6 +11,8 @@ export class ProjectService extends BaseService<ProjectEntity> {
|
||||
@InjectEntityModel(ProjectEntity)
|
||||
repository: Repository<ProjectEntity>;
|
||||
|
||||
@Inject()
|
||||
projectMemberService: ProjectMemberService;
|
||||
|
||||
@Inject()
|
||||
sysSettingsService: SysSettingsService;
|
||||
@@ -56,4 +59,26 @@ export class ProjectService extends BaseService<ProjectEntity> {
|
||||
project.disabled = disabled;
|
||||
await this.repository.save(project);
|
||||
}
|
||||
|
||||
async getByUserId(userId: number) {
|
||||
|
||||
const memberList = await this.projectMemberService.getByUserId(userId);
|
||||
const projectIds = memberList.map(item => item.projectId);
|
||||
const projectList = await this.repository.find({
|
||||
where: {
|
||||
id: In(projectIds),
|
||||
},
|
||||
});
|
||||
|
||||
const memberPermissionMap = memberList.reduce((prev, cur) => {
|
||||
prev[cur.projectId] = cur.permission;
|
||||
return prev;
|
||||
}, {} as Record<number, string>);
|
||||
|
||||
projectList.forEach(item => {
|
||||
item.permission = memberPermissionMap[item.id] || 'read';
|
||||
})
|
||||
|
||||
return projectList
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user