Compare commits

...

5 Commits

Author SHA1 Message Date
xiaojunnuo 316537eb4d fix: 修复偶尔下载证书报未授权的错误 2026-02-27 00:37:24 +08:00
xiaojunnuo b2c421600c chore: 首页数据统计项目显示 2026-02-27 00:14:53 +08:00
xiaojunnuo 787f6ef528 perf: 任务步骤页面增加串行执行提示说明 2026-02-27 00:06:44 +08:00
xiaojunnuo 8578547467 chore: project permission 2026-02-26 23:50:15 +08:00
xiaojunnuo 51ab6d6da1 perf: 【破坏性更新】错误返回信息msg字段名统一改成message,与成功的返回结构一致 2026-02-26 23:50:01 +08:00
38 changed files with 225 additions and 75 deletions
@@ -34,7 +34,7 @@ export abstract class BaseController {
fail(msg: string, code?: any) {
return {
code: code ? code : Constants.res.error.code,
msg: msg ? msg : Constants.res.error.code,
message: msg ? msg : Constants.res.error.code,
};
}
@@ -4,7 +4,7 @@
export class BaseException extends Error {
code: number;
data?:any
constructor(name, code, message,data?:any) {
constructor(name: string, code: number, message: string ,data?:any) {
super(message);
this.name = name;
this.code = code;
+7 -7
View File
@@ -1,19 +1,19 @@
export class Result<T> {
code: number;
msg: string;
message: string;
data: T;
constructor(code, msg, data?) {
constructor(code, message, data?) {
this.code = code;
this.msg = msg;
this.message = message;
this.data = data;
}
static error(code = 1, msg, data?: any) {
return new Result(code, msg, data);
static error(code = 1, message, data?: any) {
return new Result(code, message, data);
}
static success(msg, data?) {
return new Result(0, msg, data);
static success(message, data?) {
return new Result(0, message, data);
}
}
+8 -6
View File
@@ -136,27 +136,29 @@ function createService() {
*/
function createRequestFunction(service: any) {
return function (config: any) {
const configDefault = {
const configDefault: any = {
headers: {
"Content-Type": get(config, "headers.Content-Type", "application/json"),
} as any,
timeout: 30000,
baseURL: env.API,
data: {},
params: {},
};
const projectStore = useProjectStore();
if (projectStore.isEnterprise && !config.url.startsWith("/sys") && !config.url.startsWith("http")) {
configDefault.headers["project-id"] = projectStore.currentProjectId;
}
const userStore = useUserStore();
const token = userStore.getToken;
if (token != null) {
// @ts-ignore
configDefault.headers.Authorization = token;
}
return service(Object.assign(configDefault, config));
Object.assign(configDefault, config);
if (projectStore.isEnterprise && !config.url.startsWith("/sys") && !config.url.startsWith("http")) {
configDefault.params.projectId = projectStore.currentProjectId;
}
return service(configDefault);
};
}
@@ -17,6 +17,8 @@ import NotificationSelector from "../views/certd/notification/notification-selec
import EmailSelector from "./email-selector/index.vue";
import ValidTimeFormat from "./valid-time-format.vue";
import ProjectSelector from "./project-selector/index.vue";
import ProjectCurrent from "./project-selector/project-current.vue";
export default {
install(app: any) {
app.component(
@@ -47,5 +49,6 @@ export default {
app.use(vip);
app.use(Plugins);
app.component("ProjectSelector", ProjectSelector);
app.component("ProjectCurrent", ProjectCurrent);
},
};
@@ -3,21 +3,25 @@
<template #overlay>
<a-menu @click="handleMenuClick">
<a-menu-item v-for="item in projectStore.myProjects" :key="item.id">
{{ item.name }}
<div class="flex items-center justify-between w-full">
<span class="mr-1">{{ item.name }}</span>
<fs-values-format :model-value="item.permission" :dict="projectPermissionDict"></fs-values-format>
</div>
</a-menu-item>
</a-menu>
</template>
<div class="rounded pl-3 pr-3 px-2 py-1 flex-center flex pointer items-center bg-accent h-10 button-text" title="当前项目">
<fs-icon icon="ion:apps" class="mr-1"></fs-icon>
<!-- <fs-icon icon="ion:apps" class="mr-1"></fs-icon> -->
当前项目{{ projectStore.currentProject?.name || "..." }}
<fs-icon icon="ion:chevron-down-outline" class="ml-1"></fs-icon>
<fs-icon :icon="currentIcon" class="ml-5"></fs-icon>
</div>
</a-dropdown>
</template>
<script lang="ts" setup>
import { onMounted } from "vue";
import { computed, onMounted } from "vue";
import { useProjectStore } from "/@/store/project";
import { useDicts } from "/@/views/certd/dicts";
defineOptions({
name: "ProjectSelector",
});
@@ -25,12 +29,18 @@ defineOptions({
const projectStore = useProjectStore();
onMounted(async () => {
await projectStore.reload();
console.log(projectStore.myProjects);
});
function handleMenuClick({ key }: any) {
projectStore.changeCurrentProject(key);
window.location.reload();
}
const { projectPermissionDict } = useDicts();
const currentIcon = computed(() => {
return projectPermissionDict.dataMap[projectStore.currentProject?.permission || ""]?.icon || "";
});
</script>
<style lang="less">
.project-selector {
@@ -0,0 +1,28 @@
<template>
<a-tag color="green" class="flex-center flex pointer items-center button-text" title="当前项目">
<!-- <fs-icon icon="ion:apps" class="mr-1"></fs-icon> -->
当前项目{{ projectStore.currentProject?.name || "..." }}
<fs-icon :icon="currentIcon" class="ml-5"></fs-icon>
</a-tag>
</template>
<script lang="ts" setup>
import { computed, onMounted } from "vue";
import { useProjectStore } from "/@/store/project";
import { useDicts } from "/@/views/certd/dicts";
defineOptions({
name: "ProjectCurrent",
});
const projectStore = useProjectStore();
// onMounted(async () => {
// await projectStore.reload();
// });
const { projectPermissionDict } = useDicts();
const currentIcon = computed(() => {
return projectPermissionDict.dataMap[projectStore.currentProject?.permission || ""]?.icon || "";
});
</script>
<style lang="less"></style>
@@ -8,6 +8,7 @@ export type UseCrudPermissionExtraProps = {
export type UseCrudPermissionExtra = (props: UseCrudPermissionExtraProps) => any;
export type UseCrudPermissionCompProps = {
isProjectPermission?: boolean;
projectPermission?: string;
prefix?: string;
extra?: UseCrudPermissionExtra;
[key: string]: any;
@@ -69,17 +70,17 @@ export function useCrudPermission({ permission }: UseCrudPermissionProps) {
let addPermission = "add";
if (isProjectPermission) {
addPermission = "write";
addPermission = per.projectPermission || "write";
}
let editPermission = "edit";
if (isProjectPermission) {
editPermission = "write";
editPermission = per.projectPermission || "write";
}
let removePermission = "remove";
if (isProjectPermission) {
removePermission = "write";
removePermission = per.projectPermission || "write";
}
return LodashMerge(
{
@@ -241,6 +241,10 @@ export const certdResources = [
icon: "mi:user-check",
auth: true,
isMenu: true,
show: () => {
const projectStore = useProjectStore();
return !projectStore.isEnterprise;
},
},
},
{
@@ -22,7 +22,10 @@ export default defineComponent({
setup() {
const api = createAddonApi({ from: "user", addonType: "" });
addonProvide(api);
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: { api } });
const { crudBinding, crudRef, crudExpose } = useFs({
createCrudOptions,
context: { api, permission: { isProjectPermission: true } },
});
// 页面打开后获取列表数据
onMounted(() => {
@@ -18,7 +18,12 @@ import createCrudOptions from "./crud";
export default defineComponent({
name: "BasicGroupManager",
setup() {
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: {} });
const { crudBinding, crudRef, crudExpose } = useFs({
createCrudOptions,
context: {
permission: { isProjectPermission: true },
},
});
// 页面打开后获取列表数据
onMounted(() => {
@@ -8,6 +8,7 @@ import { useSettingStore } from "/@/store/settings";
import { message, Modal } from "ant-design-vue";
import CnameTip from "/@/components/plugins/cert/domains-verify-plan-editor/cname-tip.vue";
import { useCnameImport } from "./use";
import { useCrudPermission } from "/@/plugin/permission";
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
const crudBinding = crudExpose.crudBinding;
const router = useRouter();
@@ -45,6 +46,8 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
{ label: t("certd.validation_timed_out"), value: "timeout", color: "red" },
],
});
const { hasActionPermission } = useCrudPermission(context);
return {
crudOptions: {
settings: {
@@ -75,6 +78,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
icon: "ion:add-circle-outline",
},
import: {
show: hasActionPermission("write"),
title: "导入CNAME记录",
type: "primary",
text: "批量导入",
@@ -12,7 +12,7 @@
</template>
<fs-crud ref="crudRef" v-bind="crudBinding">
<template #pagination-left>
<a-tooltip :title="t('certd.batch_delete')">
<a-tooltip v-if="hasActionPermission('write')" :title="t('certd.batch_delete')">
<fs-button icon="DeleteOutlined" @click="handleBatchDelete"></fs-button>
</a-tooltip>
</template>
@@ -27,13 +27,20 @@ import createCrudOptions from "./crud";
import { message, Modal } from "ant-design-vue";
import { DeleteBatch } from "./api";
import { useI18n } from "/src/locales";
import { useCrudPermission } from "/@/plugin/permission";
const { t } = useI18n();
defineOptions({
name: "CnameRecord",
});
const { crudBinding, crudRef, crudExpose, context } = useFs({ createCrudOptions });
const context: any = {
permission: { isProjectPermission: true },
};
const { hasActionPermission } = useCrudPermission(context);
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context });
const selectedRowKeys = context.selectedRowKeys;
const handleBatchDelete = () => {
@@ -4,16 +4,22 @@ import { GetMyProjectList } from "./project/api";
const projectPermissionDict = dict({
data: [
{
label: "read",
value: "只读",
value: "read",
label: "只读",
color: "cyan",
icon: "material-symbols:folder-eye-outline-sharp",
},
{
label: "write",
value: "读写",
value: "write",
label: "读写",
color: "green",
icon: "material-symbols:edit-square-outline-rounded",
},
{
label: "admin",
value: "管理员",
value: "admin",
label: "管理员",
color: "orange",
icon: "material-symbols:manage-accounts-rounded",
},
],
});
@@ -5,7 +5,7 @@
</template>
<fs-crud ref="crudRef" v-bind="crudBinding">
<template #pagination-left>
<a-tooltip :title="t('certd.batchDelete')">
<a-tooltip v-if="hasActionPermission('write')" :title="t('certd.batchDelete')">
<fs-button icon="DeleteOutlined" @click="handleBatchDelete"></fs-button>
</a-tooltip>
</template>
@@ -20,13 +20,20 @@ import createCrudOptions from "./crud";
import { message, Modal } from "ant-design-vue";
import { DeleteBatch } from "./api";
import { useI18n } from "/src/locales";
import { useCrudPermission } from "/@/plugin/permission";
const { t } = useI18n();
defineOptions({
name: "PipelineHistory",
});
const { crudBinding, crudRef, crudExpose, context } = useFs({ createCrudOptions });
const context: any = {
permission: { isProjectPermission: true },
};
const { hasActionPermission } = useCrudPermission(context);
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context });
const selectedRowKeys = context.selectedRowKeys;
const handleBatchDelete = () => {
@@ -12,6 +12,7 @@ import { useCertUpload } from "/@/views/certd/pipeline/cert-upload/use";
import { useSettingStore } from "/@/store/settings";
import { useProjectStore } from "/@/store/project";
import { useDicts } from "../../dicts";
import { useUserStore } from "/@/store/user";
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
const { t } = useI18n();
@@ -39,6 +40,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
const { myProjectDict } = useDicts();
const settingStore = useSettingStore();
const projectStore = useProjectStore();
const userStore = useUserStore();
const model = useModal();
const viewCert = async (row: any) => {
const cert = await api.GetCert(row.id);
@@ -140,7 +142,12 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
notification.error({ message: t("certd.certificateNotGenerated") });
return;
}
window.open("/api/monitor/cert/download?id=" + row.id);
let url = "/api/monitor/cert/download?id=" + row.id;
if (projectStore.isEnterprise) {
url += `&projectId=${projectStore.currentProject?.id}`;
}
url += `&token=${userStore.getToken}`;
window.open(url);
},
},
},
@@ -21,7 +21,7 @@ const { t } = useI18n();
defineOptions({
name: "CertStore",
});
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: {} });
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: { permission: { isProjectPermission: true } } });
// 页面打开后获取列表数据
onMounted(() => {
@@ -37,7 +37,7 @@
<div class="helper">{{ t("monitor.setting.cronTrigger") }}</div>
</a-form-item>
<a-form-item label=" " :colon="false" :wrapper-col="{ span: 16 }">
<loading-button type="primary" html-type="button" :click="doSave">{{ t("certd.save") }}</loading-button>
<loading-button type="primary" html-type="button" :click="doSave" :disabled="!hasActionPermission('write')">{{ t("certd.save") }}</loading-button>
</a-form-item>
</a-form>
</div>
@@ -55,6 +55,7 @@ import { utils } from "/@/utils";
import NotificationSelector from "/@/views/certd/notification/notification-selector/index.vue";
import { useI18n } from "/src/locales";
import { useSettingStore } from "/src/store/settings";
import { useCrudPermission } from "/@/plugin/permission";
const { t } = useI18n();
@@ -73,6 +74,8 @@ async function loadUserSettings() {
merge(formState, data);
}
const { hasActionPermission } = useCrudPermission({ permission: { isProjectPermission: true } });
loadUserSettings();
const doSave = async (form: any) => {
await utils.sleep(300);
@@ -22,7 +22,7 @@ export default defineComponent({
setup() {
const api = createNotificationApi();
notificationProvide(api);
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: { api } });
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: { api, permission: { isProjectPermission: true } } });
// 页面打开后获取列表数据
onMounted(() => {
@@ -19,7 +19,7 @@ import { OPEN_API_DOC } from "/@/views/certd/open/openkey/api";
defineOptions({
name: "OpenKey",
});
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: {} });
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: { permission: { isProjectPermission: true } } });
// 页面打开后获取列表数据
onMounted(() => {
@@ -124,11 +124,11 @@ export default function ({ crudExpose, context: { selectedRowKeys, openCertApply
click() {
openCertApplyDialog({ key: "CertApply" });
},
show: hasActionPermission("add"),
show: hasActionPermission("write"),
},
uploadCert: {
order: 2,
show: hasActionPermission("uploadCert"),
show: hasActionPermission("write"),
text: t("certd.commercialCertHosting"),
type: "primary",
tooltip: {
@@ -14,12 +14,16 @@
import { defineComponent, onActivated, onMounted } from "vue";
import { useFs } from "@fast-crud/fast-crud";
import createCrudOptions from "./crud";
import { createApi } from "./api";
export default defineComponent({
name: "PipelineGroupManager",
setup() {
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context: {} });
const { crudBinding, crudRef, crudExpose } = useFs({
createCrudOptions,
context: {
permission: { isProjectPermission: true },
},
});
// 页面打开后获取列表数据
onMounted(() => {
@@ -37,11 +37,11 @@
<div v-if="selectedRowKeys.length > 0" class="batch-actions">
<div class="batch-actions-inner">
<span>{{ t("certd.selectedCount", { count: selectedRowKeys.length }) }}</span>
<fs-button icon="ion:trash-outline" class="color-red" type="link" :text="t('certd.batchDelete')" @click="batchDelete"></fs-button>
<fs-button v-if="hasActionPermission('write')" icon="ion:trash-outline" class="color-red" type="link" :text="t('certd.batchDelete')" @click="batchDelete"></fs-button>
<batch-rerun :selected-row-keys="selectedRowKeys" @change="batchFinished"></batch-rerun>
<change-group :selected-row-keys="selectedRowKeys" @change="batchFinished"></change-group>
<change-notification :selected-row-keys="selectedRowKeys" @change="batchFinished"></change-notification>
<change-trigger :selected-row-keys="selectedRowKeys" @change="batchFinished"></change-trigger>
<change-group v-if="hasActionPermission('write')" :selected-row-keys="selectedRowKeys" @change="batchFinished"></change-group>
<change-notification v-if="hasActionPermission('write')" :selected-row-keys="selectedRowKeys" @change="batchFinished"></change-notification>
<change-trigger v-if="hasActionPermission('write')" :selected-row-keys="selectedRowKeys" @change="batchFinished"></change-trigger>
</div>
</div>
<template #form-bottom>
@@ -49,6 +49,7 @@
</div>
</template>
</v-draggable>
<div v-if="currentTask.steps?.length > 0" class="helper mt-6">任务步骤会串行执行如果前面步骤失败后面的步骤不会运行</div>
</a-form-item>
</div>
</a-form>
@@ -17,7 +17,7 @@
</template>
<fs-crud ref="crudRef" v-bind="crudBinding">
<template #pagination-left>
<a-tooltip :title="t('certd.batchDelete')">
<a-tooltip v-if="hasActionPermission('write')" :title="t('certd.batchDelete')">
<fs-button icon="DeleteOutlined" @click="handleBatchDelete"></fs-button>
</a-tooltip>
</template>
@@ -32,13 +32,21 @@ import createCrudOptions from "./crud";
import { message, Modal } from "ant-design-vue";
import { DeleteBatch } from "./api";
import { useI18n } from "/src/locales";
import { useCrudPermission } from "/@/plugin/permission";
const { t } = useI18n();
defineOptions({
name: "CnameRecord",
});
const { crudBinding, crudRef, crudExpose, context } = useFs({ createCrudOptions });
const context: any = {
permission: {
isProjectPermission: true,
},
};
const { hasActionPermission } = useCrudPermission({ permission: context.permission });
context.hasActionPermission = hasActionPermission;
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context });
const selectedRowKeys = context.selectedRowKeys;
const handleBatchDelete = () => {
@@ -3,8 +3,12 @@ import { notification } from "ant-design-vue";
import CertView from "/@/views/certd/pipeline/cert-view.vue";
import { env } from "/@/utils/util.env";
import { useModal } from "/@/use/use-modal";
import { useProjectStore } from "/@/store/project";
import { useUserStore } from "/@/store/user";
export function useCertViewer() {
const projectStore = useProjectStore();
const userStore = useUserStore();
const model = useModal();
const viewCert = async (id: number) => {
const cert = await api.GetCert(id);
@@ -33,7 +37,11 @@ export function useCertViewer() {
content: () => {
const children = [];
for (const file of files) {
const downloadUrl = `${env.API}/pi/history/download?pipelineId=${id}&fileId=${file.id}`;
let downloadUrl = `${env.API}/pi/history/download?pipelineId=${id}&fileId=${file.id}`;
if (projectStore.isEnterprise) {
downloadUrl += `&projectId=${projectStore.currentProject?.id}`;
}
downloadUrl += `&token=${userStore.getToken}`;
children.push(
<div>
<div class={"flex-o m-5"}>
@@ -6,7 +6,7 @@ import * as api from "./api";
import { useSettingStore } from "/@/store/settings";
import { useUserStore } from "/@/store/user";
import { useI18n } from "/src/locales";
import { userDict } from "../../dicts";
import { useDicts } from "../../dicts";
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
const router = useRouter();
@@ -35,6 +35,8 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
const selectedRowKeys: Ref<any[]> = ref([]);
context.selectedRowKeys = selectedRowKeys;
const { userDict } = useDicts();
return {
crudOptions: {
settings: {
@@ -30,7 +30,8 @@ const { t } = useI18n();
defineOptions({
name: "MyProjectManager",
});
const { crudBinding, crudRef, crudExpose, context } = useFs({ createCrudOptions });
const context: any = { permission: { isProjectPermission: true, projectPermission: "admin" } };
const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context });
const selectedRowKeys = context.selectedRowKeys;
const handleBatchDelete = () => {
@@ -35,6 +35,11 @@
<a-divider type="vertical" />
<vip-button mode="nav" style="font-size: 12px"></vip-button>
</template>
<template v-if="settingsStore.isEnterprise">
<a-divider type="vertical" />
<project-current></project-current>
</template>
<template v-if="settingsStore.isComm">
<a-divider type="vertical" />
<suite-card class="m-0"></suite-card>
@@ -40,9 +40,7 @@ export class LoginController extends BaseController {
}
private writeTokenCookie(token: { expire: any; token: any }) {
this.ctx.cookies.set("certd_token", token.token, {
maxAge: 1000 * token.expire
});
// this.loginService.writeTokenCookie(this.ctx,token);
}
@Post('/loginBySms', { summary: Constants.per.guest })
@@ -70,6 +70,8 @@ export class ConnectController extends BaseController {
})
return this.ok({ loginUrl, ticket });
}
@Get('/callback/:type', { summary: Constants.per.guest })
public async callback(@Param('type') type: string, @Query() query: Record<string, string>) {
@@ -154,10 +156,15 @@ export class ConnectController extends BaseController {
});
}
this.writeTokenCookie(loginRes);
//返回登录成功token
return this.ok(loginRes);
}
private writeTokenCookie(token: { expire: any; token: any }) {
// this.loginService.writeTokenCookie(this.ctx,token);
}
@Post('/autoRegister', { summary: Constants.per.guest })
public async autoRegister(@Body(ALL) body: { validationCode: string, type: string }) {
@@ -183,6 +190,7 @@ export class ConnectController extends BaseController {
});
const loginRes = await this.loginService.generateToken(newUser);
this.writeTokenCookie(loginRes);
return this.ok(loginRes);
}
@@ -46,14 +46,15 @@ export class StatisticController extends BaseController {
@Post('/count', { summary: Constants.per.authOnly })
public async count() {
const pipelineCount = await this.pipelineService.count({ userId: this.getUserId() });
const pipelineStatusCount = await this.pipelineService.statusCount({ userId: this.getUserId() });
const pipelineEnableCount = await this.pipelineService.enableCount({ userId: this.getUserId() });
const {userId,projectId} = await this.getProjectUserIdRead();
const pipelineCount = await this.pipelineService.count({ userId,projectId });
const pipelineStatusCount = await this.pipelineService.statusCount({ userId,projectId });
const pipelineEnableCount = await this.pipelineService.enableCount({ userId,projectId });
const historyCount = await this.historyService.countPerDay({ userId: this.getUserId(), days: 7 });
const expiringList = await this.pipelineService.latestExpiringList({ userId: this.getUserId(), count: 5 });
const historyCount = await this.historyService.countPerDay({ userId,projectId, days: 7 });
const expiringList = await this.pipelineService.latestExpiringList({ userId,projectId, count: 5 });
const certCount = await this.certInfoService.count({ userId: this.getUserId() });
const certCount = await this.certInfoService.count({ userId,projectId });
const count: UserStatisticCount = {
pipelineCount,
@@ -162,12 +162,15 @@ export class CertInfoController extends CrudController<CertInfoService> {
@Get('/download', { summary: Constants.per.authOnly })
async download(@Query('id') id: number) {
await this.checkOwner(this.getService(),id,"read");
const {userId,projectId} =await this.checkOwner(this.getService(),id,"read");
const certInfo = await this.getService().info(id)
if (certInfo == null) {
throw new CommonException('file not found');
}
if (certInfo.userId !== this.getUserId()) {
if (certInfo.userId !== userId) {
throw new CommonException('file not found');
}
if (projectId && certInfo.projectId !== projectId) {
throw new CommonException('file not found');
}
// koa send file
@@ -241,7 +241,7 @@ export class HistoryController extends CrudController<HistoryService> {
history = await this.service.getLastHistory(pipelineId);
}
if (history == null) {
throw new CommonException('historyId is null');
throw new CommonException('流水线还未运行过');
}
const {projectId} = await this.getProjectUserIdRead()
if (projectId) {
@@ -199,6 +199,12 @@ export class LoginService {
return this.generateToken(info);
}
writeTokenCookie(ctx:any,token: { expire: any; token: any }) {
ctx.cookies.set("certd_token", token.token, {
maxAge: 1000 * token.expire
});
}
/**
* 生成token
@@ -191,11 +191,12 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
});
}
async count({ userId }: { userId: number }) {
async count({ userId,projectId }: { userId: number,projectId?:number }) {
const total = await this.repository.count({
where: {
userId,
expiresTime: Not(IsNull()),
projectId,
},
});
@@ -203,6 +204,7 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
where: {
userId,
expiresTime: LessThan(new Date().getTime()),
projectId,
},
});
@@ -210,6 +212,7 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
where: {
userId,
expiresTime: Between(new Date().getTime(), new Date().getTime() + 15 * 24 * 60 * 60 * 1000),
projectId,
},
});
@@ -183,7 +183,7 @@ export class HistoryService extends BaseService<HistoryEntity> {
}
}
async countPerDay(param: { days: number; userId?: any }) {
async countPerDay(param: { days: number; userId?: any,projectId?:number }) {
const todayEnd = dayjs().endOf('day');
const where: any = {
createTime: MoreThan(todayEnd.add(-param.days, 'day').toDate()),
@@ -191,6 +191,9 @@ export class HistoryService extends BaseService<HistoryEntity> {
if (param.userId > 0) {
where.userId = param.userId;
}
if (param.projectId > 0) {
where.projectId = param.projectId;
}
const result = await this.getRepository()
.createQueryBuilder('main')
.select(`${this.dbAdapter.date('main.createTime')} AS date`) // 将UNIX时间戳转换为日期
@@ -824,35 +824,41 @@ export class PipelineService extends BaseService<PipelineEntity> {
await this.historyLogService.addOrUpdate(logEntity);
}
async count(param: { userId?: any }) {
async count(param: { userId?: any,projectId?:number }) {
const count = await this.repository.count({
where: {
userId: param.userId
userId: param.userId,
projectId: param.projectId,
isTemplate: false
}
});
return count;
}
async statusCount(param: { userId?: any } = {}) {
async statusCount(param: { userId?: any,projectId?:number } = {}) {
const statusCount = await this.repository
.createQueryBuilder()
.select("status")
.addSelect("count(1)", "count")
.where({
userId: param.userId
userId: param.userId,
projectId: param.projectId,
isTemplate: false
})
.groupBy("status")
.getRawMany();
return statusCount;
}
async enableCount(param: { userId?: any } = {}) {
async enableCount(param: { userId?: any,projectId?:number } = {}) {
const statusCount = await this.repository
.createQueryBuilder()
.select("disabled")
.addSelect("count(1)", "count")
.where({
userId: param.userId
userId: param.userId,
projectId: param.projectId,
isTemplate: false
})
.groupBy("disabled")
.getRawMany();
@@ -866,7 +872,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
return result;
}
async latestExpiringList({ userId }: any) {
async latestExpiringList({ userId,projectId }: any) {
let list = await this.repository.find({
select: {
id: true,
@@ -875,7 +881,9 @@ export class PipelineService extends BaseService<PipelineEntity> {
},
where: {
userId,
disabled: false
disabled: false,
projectId,
isTemplate: false
}
});
await this.fillLastVars(list);
@@ -897,7 +905,8 @@ export class PipelineService extends BaseService<PipelineEntity> {
.addSelect("COUNT(1) AS count")
.where({
// 0点
createTime: MoreThan(todayEnd.add(-param.days, "day").toDate())
createTime: MoreThan(todayEnd.add(-param.days, "day").toDate()),
isTemplate: false
})
.groupBy("date")
.getRawMany();