From 92b9b4335d66f14b73f369cd2cb0527534ca625a Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Sun, 27 Mar 2022 13:09:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=9D=83=E9=99=90=E7=BB=A7=E6=89=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/dataset/DataSetGroupService.java | 4 + .../service/dataset/DataSetTableService.java | 5 + .../service/panel/PanelGroupService.java | 15 +- .../main/resources/db/migration/V33__1.9.sql | 158 ++++++++++++++++++ 4 files changed, 179 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetGroupService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetGroupService.java index a6b42f3038..c7144d4129 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetGroupService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetGroupService.java @@ -5,6 +5,7 @@ import io.dataease.base.domain.DatasetGroup; import io.dataease.base.domain.DatasetGroupExample; import io.dataease.base.mapper.DatasetGroupMapper; import io.dataease.base.mapper.ext.ExtDataSetGroupMapper; +import io.dataease.commons.constants.AuthConstants; import io.dataease.commons.constants.DePermissionType; import io.dataease.commons.utils.AuthUtils; import io.dataease.commons.utils.BeanUtils; @@ -14,6 +15,7 @@ import io.dataease.controller.request.dataset.DataSetTableRequest; import io.dataease.dto.dataset.DataSetGroupDTO; import io.dataease.dto.dataset.DataSetTableDTO; import io.dataease.i18n.Translator; +import io.dataease.listener.util.CacheUtils; import io.dataease.service.sys.SysAuthService; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; @@ -49,6 +51,8 @@ public class DataSetGroupService { datasetGroup.setCreateBy(AuthUtils.getUser().getUsername()); datasetGroup.setCreateTime(System.currentTimeMillis()); datasetGroupMapper.insert(datasetGroup); + // 清理权限缓存 + CacheUtils.removeAll(AuthConstants.USER_PERMISSION_CACHE_NAME); } else { datasetGroupMapper.updateByPrimaryKeySelective(datasetGroup); } diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index ed4e4a9d64..9cfd313b05 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -24,6 +24,7 @@ import io.dataease.dto.dataset.union.UnionParamDTO; import io.dataease.dto.datasource.TableField; import io.dataease.exception.DataEaseException; import io.dataease.i18n.Translator; +import io.dataease.listener.util.CacheUtils; import io.dataease.plugins.common.constants.DatasourceTypes; import io.dataease.plugins.loader.ClassloaderResponsity; import io.dataease.provider.ProviderFactory; @@ -115,6 +116,10 @@ public class DataSetTableService { public void batchInsert(List datasetTable) throws Exception { for (DataSetTableRequest table : datasetTable) { save(table); + // 清理权限缓存 + CacheUtils.removeAll(AuthConstants.USER_DATASET_NAME); + CacheUtils.removeAll(AuthConstants.ROLE_DATASET_NAME); + CacheUtils.removeAll(AuthConstants.DEPT_DATASET_NAME); } } diff --git a/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java b/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java index 1d47c4da11..b88280396b 100644 --- a/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java +++ b/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java @@ -6,6 +6,7 @@ import io.dataease.auth.annotation.DeCleaner; import io.dataease.base.domain.*; import io.dataease.base.mapper.*; import io.dataease.base.mapper.ext.*; +import io.dataease.commons.constants.AuthConstants; import io.dataease.commons.constants.CommonConstants; import io.dataease.commons.constants.DePermissionType; import io.dataease.commons.constants.PanelConstants; @@ -24,6 +25,7 @@ import io.dataease.dto.panel.linkJump.PanelLinkJumpBaseRequest; import io.dataease.dto.panel.po.PanelViewInsertDTO; import io.dataease.exception.DataEaseException; import io.dataease.i18n.Translator; +import io.dataease.listener.util.CacheUtils; import io.dataease.service.chart.ChartViewService; import io.dataease.service.dataset.DataSetTableService; import io.dataease.service.sys.SysAuthService; @@ -119,6 +121,8 @@ public class PanelGroupService { checkPanelName(request.getName(), request.getPid(), PanelConstants.OPT_TYPE_INSERT, null, request.getNodeType()); panelId = newPanel(request); panelGroupMapper.insert(request); + // 清理权限缓存 + clearPermissionCache(); } else if ("toDefaultPanel".equals(request.getOptType())) { panelId = UUID.randomUUID().toString(); // 转存为默认仪表板 @@ -133,8 +137,12 @@ public class PanelGroupService { newDefaultPanel.setCreateBy(AuthUtils.getUser().getUsername()); checkPanelName(newDefaultPanel.getName(), newDefaultPanel.getPid(), PanelConstants.OPT_TYPE_INSERT, newDefaultPanel.getId(), newDefaultPanel.getNodeType()); panelGroupMapper.insertSelective(newDefaultPanel); + // 清理权限缓存 + clearPermissionCache(); } else if ("copy".equals(request.getOptType())) { panelId = this.panelGroupCopy(request, null, true); + // 清理权限缓存 + clearPermissionCache(); } else if ("move".equals(request.getOptType())) { PanelGroupWithBLOBs panelInfo = panelGroupMapper.selectByPrimaryKey(request.getId()); if (panelInfo.getPid().equalsIgnoreCase(request.getPid())) { @@ -431,9 +439,10 @@ public class PanelGroupService { } return null; } - - public void findPanelAttachInfo(String panelId) { - + private void clearPermissionCache(){ + CacheUtils.removeAll(AuthConstants.USER_PANEL_NAME); + CacheUtils.removeAll(AuthConstants.ROLE_PANEL_NAME); + CacheUtils.removeAll(AuthConstants.DEPT_PANEL_NAME); } diff --git a/backend/src/main/resources/db/migration/V33__1.9.sql b/backend/src/main/resources/db/migration/V33__1.9.sql index be23dae42e..6a1d66b0b3 100644 --- a/backend/src/main/resources/db/migration/V33__1.9.sql +++ b/backend/src/main/resources/db/migration/V33__1.9.sql @@ -89,3 +89,161 @@ INSERT INTO `system_parameter`(`param_key`, `param_value`, `type`, `sort`) VALUE UPDATE `demo_gdp_district_top100` set `province` = '新疆维吾尔自治区' WHERE `province` = '新疆维吾尔族自治区'; +ALTER TABLE `sys_auth` +ADD COLUMN `copy_from` varchar(255) NULL COMMENT '复制来源' AFTER `update_time`, +ADD COLUMN `copy_id` varchar(255) NULL COMMENT '复制ID' AFTER `copy_from`; + +ALTER TABLE `sys_auth_detail` +ADD COLUMN `copy_from` varchar(255) NULL COMMENT '复制来源' AFTER `update_time`, +ADD COLUMN `copy_id` varchar(255) NULL COMMENT '复制ID' AFTER `copy_from`; + + +-- ---------------------------- +-- Function structure for copy_auth +-- ---------------------------- +DROP FUNCTION IF EXISTS `copy_auth`; +delimiter ;; +CREATE FUNCTION `copy_auth`(authSource varchar(255),authSourceType varchar(255),authUser varchar(255)) + RETURNS varchar(255) CHARSET utf8mb4 + READS SQL DATA +BEGIN + +DECLARE authId varchar(255); + +DECLARE userId varchar(255); + +DECLARE copyId varchar(255); + +select uuid() into authId; + +select uuid() into copyId; + +select max(sys_user.user_id) into userId from sys_user where username= authUser; + +delete from sys_auth_detail where auth_id in ( +select id from sys_auth where sys_auth.auth_source=authSource and sys_auth.auth_source_type=authSourceType +); + +delete from sys_auth where sys_auth.auth_source=authSource and sys_auth.auth_source_type=authSourceType; + +INSERT INTO sys_auth ( + id, + auth_source, + auth_source_type, + auth_target, + auth_target_type, + auth_time, + auth_user +) +VALUES + ( + authId, + authSource, + authSourceType, + userId, + 'user', + unix_timestamp( + now())* 1000,'auto'); + + INSERT INTO sys_auth_detail ( + id, + auth_id, + privilege_name, + privilege_type, + privilege_value, + privilege_extend, + remark, + create_user, + create_time + ) SELECT + uuid() AS id, + authId AS auth_id, + sys_auth_detail.privilege_name, + sys_auth_detail.privilege_type, + 1, + sys_auth_detail.privilege_extend, + sys_auth_detail.remark, + 'auto' AS create_user, + unix_timestamp(now())* 1000 AS create_time + FROM + sys_auth_detail where auth_id =authSourceType; + +/**继承第一父级权限**/ + +insert into sys_auth( +id, + auth_source, + auth_source_type, + auth_target, + auth_target_type, + auth_time, + auth_user, + copy_from, + copy_id +) +SELECT + uuid() as id, + authSource as auth_source, + authSourceType as auth_source_type, + auth_target, + auth_target_type, + NOW()* 1000 as auth_time, + 'auto' as auth_user, + id as copy_from, + copyId as copy_id +FROM + sys_auth +WHERE + auth_source IN ( + SELECT + pid + FROM + v_auth_model + WHERE + id = authSource + AND model_type = authSourceType + ) + AND auth_source_type = authSourceType; +INSERT INTO sys_auth_detail ( + id, + auth_id, + privilege_name, + privilege_type, + privilege_value, + privilege_extend, + remark, + create_user, + create_time, + copy_from, + copy_id +) SELECT +uuid() AS id, +sa_copy.t_id AS auth_id, +sys_auth_detail.privilege_name, +sys_auth_detail.privilege_type, +sys_auth_detail.privilege_value, +sys_auth_detail.privilege_extend, +sys_auth_detail.remark, +'auto' AS create_user, +unix_timestamp( +now())* 1000 AS create_time, +id AS copy_from, +copyId AS copy_id +FROM + sys_auth_detail + INNER JOIN ( + SELECT + id AS t_id, + copy_from AS s_id + FROM + sys_auth + WHERE + copy_id = copyId + ) sa_copy ON sys_auth_detail.auth_id = sa_copy.s_id; + +RETURN 'success'; + +END +;; +delimiter ; +