diff --git a/CHANGELOG.md b/CHANGELOG.md index 915f97fbd..5122aa2aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # 🚀 版本日志 +## 2.9.10 + +### 🐣 新增功能 + +1. 【server】新增全局工作空间变量 + +### 🐞 解决BUG、优化功能 + +------ + ## 2.9.9 (2022-08-22) ### 🐣 新增功能 diff --git a/modules/common/src/main/java/io/jpom/common/Const.java b/modules/common/src/main/java/io/jpom/common/Const.java index b0f770005..72b400b33 100644 --- a/modules/common/src/main/java/io/jpom/common/Const.java +++ b/modules/common/src/main/java/io/jpom/common/Const.java @@ -27,64 +27,68 @@ package io.jpom.common; * Const class */ public class Const { - /** - * String const - */ - public static final String ID_STR = "id"; - public static final String GROUP_STR = "group"; + /** + * String const + */ + public static final String ID_STR = "id"; + public static final String GROUP_STR = "group"; - /** - * 应用程序类型的配置 key - */ - public static final String APPLICATION_NAME = "spring.application.name"; + /** + * 应用程序类型的配置 key + */ + public static final String APPLICATION_NAME = "spring.application.name"; - /** - * String get - */ - public static final String GET_STR = "get"; + /** + * String get + */ + public static final String GET_STR = "get"; - /** - * id_rsa - */ - public static final String ID_RSA = "_id_rsa"; - /** - * sshkey - */ - public static final String SSH_KEY = "sshkey"; + /** + * id_rsa + */ + public static final String ID_RSA = "_id_rsa"; + /** + * sshkey + */ + public static final String SSH_KEY = "sshkey"; - /** - * SQL backup default directory name - * 数据库备份默认目录名称 - */ - public static final String BACKUP_DIRECTORY_NAME = "backup"; - /** - * h2 数据库表名字段 - */ - public static final String TABLE_NAME = "TABLE_NAME"; - /** - * 备份 SQL 文件 后缀 - */ - public static final String SQL_FILE_SUFFIX = ".sql"; - /** - * 升级提示语 - */ - public static final String UPGRADE_MSG = "升级(重启)中大约需要30秒~2分钟左右"; + /** + * SQL backup default directory name + * 数据库备份默认目录名称 + */ + public static final String BACKUP_DIRECTORY_NAME = "backup"; + /** + * h2 数据库表名字段 + */ + public static final String TABLE_NAME = "TABLE_NAME"; + /** + * 备份 SQL 文件 后缀 + */ + public static final String SQL_FILE_SUFFIX = ".sql"; + /** + * 升级提示语 + */ + public static final String UPGRADE_MSG = "升级(重启)中大约需要30秒~2分钟左右"; - /** - * 请求 header - */ - public static final String WORKSPACEID_REQ_HEADER = "workspaceId"; - /** - * 默认的工作空间 - */ - public static final String WORKSPACE_DEFAULT_ID = "DEFAULT"; - /** - * websocket 传输 agent 包 buffer size - */ - public static final int DEFAULT_BUFFER_SIZE = 1024 * 1024; - /** - * id 最大长度 - */ - public static final int ID_MAX_LEN = 50; + /** + * 请求 header + */ + public static final String WORKSPACEID_REQ_HEADER = "workspaceId"; + /** + * 工作空间全局 + */ + public static final String WORKSPACE_GLOBAL = "GLOBAL"; + /** + * 默认的工作空间 + */ + public static final String WORKSPACE_DEFAULT_ID = "DEFAULT"; + /** + * websocket 传输 agent 包 buffer size + */ + public static final int DEFAULT_BUFFER_SIZE = 1024 * 1024; + /** + * id 最大长度 + */ + public static final int ID_MAX_LEN = 50; } diff --git a/modules/server/src/main/java/io/jpom/controller/system/WorkspaceEnvVarController.java b/modules/server/src/main/java/io/jpom/controller/system/WorkspaceEnvVarController.java index bfc4cb83f..54da64ab6 100644 --- a/modules/server/src/main/java/io/jpom/controller/system/WorkspaceEnvVarController.java +++ b/modules/server/src/main/java/io/jpom/controller/system/WorkspaceEnvVarController.java @@ -32,6 +32,7 @@ import cn.jiangzeyin.common.validator.ValidatorItem; import cn.jiangzeyin.common.validator.ValidatorRule; import com.alibaba.fastjson.JSONObject; import io.jpom.common.BaseServerController; +import io.jpom.common.Const; import io.jpom.common.forward.NodeForward; import io.jpom.common.forward.NodeUrl; import io.jpom.model.PageResultDto; @@ -78,7 +79,6 @@ public class WorkspaceEnvVarController extends BaseServerController { @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE) @Feature(method = MethodFeature.LIST) public String list() { - workspaceEnvVarService.getCheckUserWorkspace(getRequest()); PageResultDto listPage = workspaceEnvVarService.listPage(getRequest()); listPage.each(workspaceEnvVarModel -> { Integer privacy = workspaceEnvVarModel.getPrivacy(); @@ -192,7 +192,7 @@ public class WorkspaceEnvVarController extends BaseServerController { // Entity entity = Entity.create(); entity.set("name", name); - entity.set("workspaceId", workspaceId); + entity.set("workspaceId", CollUtil.newArrayList(workspaceId, Const.WORKSPACE_GLOBAL)); if (StrUtil.isNotEmpty(id)) { entity.set("id", StrUtil.format(" <> {}", id)); } diff --git a/modules/server/src/main/java/io/jpom/service/h2db/BaseWorkspaceService.java b/modules/server/src/main/java/io/jpom/service/h2db/BaseWorkspaceService.java index 0eb456dd1..3a19bda57 100644 --- a/modules/server/src/main/java/io/jpom/service/h2db/BaseWorkspaceService.java +++ b/modules/server/src/main/java/io/jpom/service/h2db/BaseWorkspaceService.java @@ -148,29 +148,24 @@ public abstract class BaseWorkspaceService extends public PageResultDto listPage(HttpServletRequest request) { // 验证工作空间权限 Map paramMap = ServletUtil.getParamMap(request); - String workspaceId = request.getParameter("workspaceId"); - if (StrUtil.isEmpty(workspaceId)) { - workspaceId = this.getCheckUserWorkspace(request); - } - Assert.hasText(workspaceId, "此接口需要传workspaceId!"); + String workspaceId = this.getCheckUserWorkspace(request); + //Assert.hasText(workspaceId, "此接口需要传workspaceId!"); paramMap.put("workspaceId", workspaceId); return super.listPage(paramMap); } - - /** - * 根据 workspaceId获取空间变量列表 - * - * @param workspaceId - * @return - */ - public List listByWorkspaceId(String workspaceId) { - Entity entity = Entity.create(); - entity.set("workspaceId", workspaceId); - List entities = super.queryList(entity); - return super.entityToBeanList(entities); - } - +// /** +// * 根据 workspaceId获取空间变量列表 +// * +// * @param workspaceId +// * @return +// */ +// public List listByWorkspaceId(String workspaceId) { +// Entity entity = Entity.create(); +// entity.set("workspaceId", workspaceId); +// List entities = super.queryList(entity); +// return super.entityToBeanList(entities); +// } /** * 删除 @@ -202,9 +197,9 @@ public abstract class BaseWorkspaceService extends } public static String getWorkspaceId(HttpServletRequest request) { - String workspaceId = ServletUtil.getHeader(request, Const.WORKSPACEID_REQ_HEADER, CharsetUtil.CHARSET_UTF_8); + String workspaceId = request.getParameter(Const.WORKSPACEID_REQ_HEADER); if (StrUtil.isEmpty(workspaceId)) { - workspaceId = request.getParameter(Const.WORKSPACEID_REQ_HEADER); + workspaceId = ServletUtil.getHeader(request, Const.WORKSPACEID_REQ_HEADER, CharsetUtil.CHARSET_UTF_8); } return StrUtil.emptyToDefault(workspaceId, Const.WORKSPACE_DEFAULT_ID); } @@ -248,6 +243,10 @@ public abstract class BaseWorkspaceService extends // 超级管理员 return; } + if (StrUtil.equals(workspaceId, Const.WORKSPACE_GLOBAL)) { + // 全局 ID 忽略 + return; + } // 查询绑定的权限 UserBindWorkspaceService userBindWorkspaceService = SpringUtil.getBean(UserBindWorkspaceService.class); boolean exists = userBindWorkspaceService.exists(userModel, workspaceId); diff --git a/modules/server/src/main/java/io/jpom/service/system/WorkspaceEnvVarService.java b/modules/server/src/main/java/io/jpom/service/system/WorkspaceEnvVarService.java index 480fa69d5..113e32c87 100644 --- a/modules/server/src/main/java/io/jpom/service/system/WorkspaceEnvVarService.java +++ b/modules/server/src/main/java/io/jpom/service/system/WorkspaceEnvVarService.java @@ -24,6 +24,8 @@ package io.jpom.service.system; import cn.hutool.core.collection.CollStreamUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.db.Entity; +import io.jpom.common.Const; import io.jpom.model.data.WorkspaceEnvVarModel; import io.jpom.service.h2db.BaseWorkspaceService; import io.jpom.util.StringUtil; @@ -41,9 +43,9 @@ import java.util.Map; public class WorkspaceEnvVarService extends BaseWorkspaceService { public Map getEnv(String workspaceId) { - WorkspaceEnvVarModel workspaceEnvVarModel = new WorkspaceEnvVarModel(); - workspaceEnvVarModel.setWorkspaceId(workspaceId); - List list = super.listByBean(workspaceEnvVarModel); + Entity entity = Entity.create(); + entity.set("workspaceId", CollUtil.newArrayList(workspaceId, Const.WORKSPACE_GLOBAL)); + List list = super.listByEntity(entity); Map map = CollStreamUtil.toMap(list, WorkspaceEnvVarModel::getName, WorkspaceEnvVarModel::getValue); // java.lang.UnsupportedOperationException HashMap hashMap = new HashMap<>(CollUtil.size(list) + 10); diff --git a/modules/server/src/main/resources/menus/index.json b/modules/server/src/main/resources/menus/index.json index 628364c8c..f57362b42 100644 --- a/modules/server/src/main/resources/menus/index.json +++ b/modules/server/src/main/resources/menus/index.json @@ -169,6 +169,11 @@ "title": "工作空间", "role": "system" }, + { + "id": "globalEnv", + "title": "全局变量", + "role": "system" + }, { "id": "cacheManage", "title": "缓存管理", diff --git a/web-vue/src/pages/system/global-env.vue b/web-vue/src/pages/system/global-env.vue new file mode 100644 index 000000000..0441f1e74 --- /dev/null +++ b/web-vue/src/pages/system/global-env.vue @@ -0,0 +1,14 @@ + + diff --git a/web-vue/src/pages/system/workspace-env.vue b/web-vue/src/pages/system/workspace-env.vue new file mode 100644 index 000000000..e0971d35b --- /dev/null +++ b/web-vue/src/pages/system/workspace-env.vue @@ -0,0 +1,242 @@ + + diff --git a/web-vue/src/pages/system/workspace.vue b/web-vue/src/pages/system/workspace.vue index e0fa4a963..2b81579a7 100644 --- a/web-vue/src/pages/system/workspace.vue +++ b/web-vue/src/pages/system/workspace.vue @@ -49,116 +49,28 @@ -
- - - - - 搜索 - 新增 - -
- - - - - {{ text }} - - - {{ text }} - - - {{ text }} - - - -
- - - - - - - - - - - - - - - - - - - - - {{ item.name }} - - - - + diff --git a/web-vue/src/router/index.js b/web-vue/src/router/index.js index 6444c2085..d81b4e27d 100644 --- a/web-vue/src/router/index.js +++ b/web-vue/src/router/index.js @@ -180,6 +180,11 @@ const children = [ name: "system-workspace", component: () => import("../pages/system/workspace"), }, + { + path: "/system/global-env", + name: "global-env", + component: () => import("../pages/system/global-env"), + }, ]; const router = new Router({ diff --git a/web-vue/src/router/route-menu.js b/web-vue/src/router/route-menu.js index 01c5f1fcf..8e7ca5486 100644 --- a/web-vue/src/router/route-menu.js +++ b/web-vue/src/router/route-menu.js @@ -41,6 +41,7 @@ const routeMenuMap = { // 数据库备份 backup: "/system/backup", workspace: "/system/workspace", + globalEnv: "/system/global-env", }; export default routeMenuMap;