diff --git a/.vscode/settings.json b/.vscode/settings.json index bf25c3e8d..8414615d6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,7 @@ ], "editor.defaultFormatter": "dbaeumer.vscode-eslint", "[typescript]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "vscode.typescript-language-features" }, "editor.tabSize": 2, "explorer.autoReveal": false, diff --git a/packages/core/acme-client/package.json b/packages/core/acme-client/package.json index 0340db046..4145ac99c 100644 --- a/packages/core/acme-client/package.json +++ b/packages/core/acme-client/package.json @@ -53,7 +53,7 @@ "prepublishOnly": "npm run build-docs", "test": "mocha -t 60000 \"test/setup.js\" \"test/**/*.spec.js\"", "pub": "npm publish", - "compile": "tsc --skipLibCheck --watch" + "compile": "echo '1'" }, "repository": { "type": "git", diff --git a/packages/libs/lib-server/src/basic/base-controller.ts b/packages/libs/lib-server/src/basic/base-controller.ts index 158eec008..26920077a 100644 --- a/packages/libs/lib-server/src/basic/base-controller.ts +++ b/packages/libs/lib-server/src/basic/base-controller.ts @@ -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,44 @@ export abstract class BaseController { } } + async 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) + await this.checkProjectPermission(userId, projectId,permission) + return projectId; + } + + async getProjectUserId(permission:string){ + let userId = this.getUserId() + const projectId = await this.getProjectId(permission) + if(projectId){ + userId = 0 + } + return { + projectId,userId + } + } + async getProjectUserIdRead(){ + return await this.getProjectUserId("read") + } + async getProjectUserIdWrite(){ + return await this.getProjectUserId("write") + } + async getProjectUserIdAdmin(){ + return await this.getProjectUserId("admin") + } + + async checkProjectPermission(userId: number, projectId: number,permission:string) { + const projectService:any = await this.applicationContext.getAsync("projectService"); + await projectService.checkPermission({userId,projectId,permission}) + } + + } diff --git a/packages/libs/lib-server/src/basic/index.ts b/packages/libs/lib-server/src/basic/index.ts index 184d3339e..d012ec35c 100644 --- a/packages/libs/lib-server/src/basic/index.ts +++ b/packages/libs/lib-server/src/basic/index.ts @@ -5,3 +5,4 @@ export * from './enum-item.js'; export * from './exception/index.js'; export * from './result.js'; export * from './base-service.js'; +export * from "./mode.js" \ No newline at end of file diff --git a/packages/libs/lib-server/src/basic/mode.ts b/packages/libs/lib-server/src/basic/mode.ts new file mode 100644 index 000000000..2f8318150 --- /dev/null +++ b/packages/libs/lib-server/src/basic/mode.ts @@ -0,0 +1,12 @@ +let adminMode = "saas" + +export function setAdminMode(mode:string = "saas"){ + adminMode = mode +} +export function getAdminMode(){ + return adminMode +} + +export function isEnterprise(){ + return adminMode === "enterprise" +} \ No newline at end of file diff --git a/packages/libs/lib-server/src/system/settings/service/sys-settings-service.ts b/packages/libs/lib-server/src/system/settings/service/sys-settings-service.ts index 5cb56673d..5ae977b12 100644 --- a/packages/libs/lib-server/src/system/settings/service/sys-settings-service.ts +++ b/packages/libs/lib-server/src/system/settings/service/sys-settings-service.ts @@ -7,9 +7,10 @@ import { BaseSettings, SysInstallInfo, SysPrivateSettings, SysPublicSettings, Sy import { getAllSslProviderDomains, setSslProviderReverseProxies } from '@certd/acme-client'; import { cache, logger, mergeUtils, setGlobalProxy } from '@certd/basic'; import * as dns from 'node:dns'; -import { BaseService } from '../../../basic/index.js'; +import { BaseService, setAdminMode } from '../../../basic/index.js'; import { executorQueue } from '../../basic/service/executor-queue.js'; -const {merge} = mergeUtils; +import { isComm } from '@certd/plus-core'; +const { merge } = mergeUtils; /** * 设置 */ @@ -116,7 +117,15 @@ export class SysSettingsService extends BaseService { } async savePublicSettings(bean: SysPublicSettings) { + if(isComm()){ + if(bean.adminMode === 'enterprise'){ + throw new Error("商业版不支持使用企业管理模式") + } + } + await this.saveSetting(bean); + //让设置生效 + await this.reloadPublicSettings(); } async getPrivateSettings(): Promise { @@ -137,23 +146,33 @@ export class SysSettingsService extends BaseService { await this.reloadPrivateSettings(); } + async reloadSettings() { + await this.reloadPrivateSettings() + await this.reloadPublicSettings() + } + + async reloadPublicSettings() { + const publicSetting = await this.getPublicSettings() + setAdminMode(publicSetting.adminMode) + } + async reloadPrivateSettings() { - const bean = await this.getPrivateSettings(); + const privateSetting = await this.getPrivateSettings(); const opts = { - httpProxy: bean.httpProxy, - httpsProxy: bean.httpsProxy, + httpProxy: privateSetting.httpProxy, + httpsProxy: privateSetting.httpsProxy, }; setGlobalProxy(opts); - if (bean.dnsResultOrder) { - dns.setDefaultResultOrder(bean.dnsResultOrder as any); + if (privateSetting.dnsResultOrder) { + dns.setDefaultResultOrder(privateSetting.dnsResultOrder as any); } - if (bean.pipelineMaxRunningCount){ - executorQueue.setMaxRunningCount(bean.pipelineMaxRunningCount); + if (privateSetting.pipelineMaxRunningCount) { + executorQueue.setMaxRunningCount(privateSetting.pipelineMaxRunningCount); } - setSslProviderReverseProxies(bean.reverseProxies); + setSslProviderReverseProxies(privateSetting.reverseProxies); } async updateByKey(key: string, setting: any) { diff --git a/packages/ui/certd-client/src/api/service.ts b/packages/ui/certd-client/src/api/service.ts index fc4df40d4..9a322f6d7 100644 --- a/packages/ui/certd-client/src/api/service.ts +++ b/packages/ui/certd-client/src/api/service.ts @@ -3,6 +3,7 @@ import { get } from "lodash-es"; import { errorLog, errorCreate } from "./tools"; import { env } from "/src/utils/util.env"; import { useUserStore } from "/@/store/user"; +import { useProjectStore } from "../store/project"; export class CodeError extends Error { code: number; @@ -138,11 +139,17 @@ function createRequestFunction(service: any) { const configDefault = { headers: { "Content-Type": get(config, "headers.Content-Type", "application/json"), - }, + } as any, timeout: 30000, baseURL: env.API, data: {}, }; + const projectStore = useProjectStore(); + + if (projectStore.isEnterprise && !config.url.startsWith("/sys")) { + configDefault.headers["project-id"] = projectStore.currentProjectId; + } + const userStore = useUserStore(); const token = userStore.getToken; if (token != null) { diff --git a/packages/ui/certd-client/src/components/index.ts b/packages/ui/certd-client/src/components/index.ts index d751e9c7d..fdb3d94a5 100644 --- a/packages/ui/certd-client/src/components/index.ts +++ b/packages/ui/certd-client/src/components/index.ts @@ -16,6 +16,7 @@ import { defineAsyncComponent } from "vue"; import NotificationSelector from "../views/certd/notification/notification-selector/index.vue"; import EmailSelector from "./email-selector/index.vue"; import ValidTimeFormat from "./valid-time-format.vue"; +import ProjectSelector from "./project-selector/index.vue"; export default { install(app: any) { app.component( @@ -45,5 +46,6 @@ export default { app.component("ExpiresTimeText", ExpiresTimeText); app.use(vip); app.use(Plugins); + app.component("ProjectSelector", ProjectSelector); }, }; diff --git a/packages/ui/certd-client/src/components/plugins/common/domain-selector.vue b/packages/ui/certd-client/src/components/plugins/common/domain-selector.vue index 79812dc85..1c761873e 100644 --- a/packages/ui/certd-client/src/components/plugins/common/domain-selector.vue +++ b/packages/ui/certd-client/src/components/plugins/common/domain-selector.vue @@ -10,7 +10,6 @@ :options="optionsRef" :value="value" v-bind="attrs" - :open="openProp" @click="onClick" @update:value="emit('update:value', $event)" > diff --git a/packages/ui/certd-client/src/components/project-selector/api.ts b/packages/ui/certd-client/src/components/project-selector/api.ts new file mode 100644 index 000000000..f50033e89 --- /dev/null +++ b/packages/ui/certd-client/src/components/project-selector/api.ts @@ -0,0 +1,9 @@ +import { request } from "/src/api/service"; + +export async function MyProjectList() { + return await request({ + url: "/enterprise/project/list", + method: "post", + data: {}, + }); +} diff --git a/packages/ui/certd-client/src/components/project-selector/index.vue b/packages/ui/certd-client/src/components/project-selector/index.vue new file mode 100644 index 000000000..9b7805f36 --- /dev/null +++ b/packages/ui/certd-client/src/components/project-selector/index.vue @@ -0,0 +1,44 @@ + + + + diff --git a/packages/ui/certd-client/src/layout/layout-basic.vue b/packages/ui/certd-client/src/layout/layout-basic.vue index 5d79e9c69..4b0ae6414 100644 --- a/packages/ui/certd-client/src/layout/layout-basic.vue +++ b/packages/ui/certd-client/src/layout/layout-basic.vue @@ -81,6 +81,11 @@ provide("fn:ai.open", openChat);