You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
858 lines
73 KiB
858 lines
73 KiB
diff --git a/CONTEXT-MAP.md b/CONTEXT-MAP.md
|
|
index f8253ec..71c6541 100644
|
|
--- a/CONTEXT-MAP.md
|
|
+++ b/CONTEXT-MAP.md
|
|
@@ -9,12 +9,12 @@ This is a multi-module Maven monorepo. Each `crm-{鍩焳` module is a bounded cont
|
|
| `crm-auth` | 璁よ瘉涓庣涓夋柟鐧诲綍 | [`crm-auth/CONTEXT.md`](./crm-auth/CONTEXT.md) |
|
|
| `crm-dict` | 鏁版嵁瀛楀吀(骞冲彴绾ч敭鍊煎瓧鍏? | [`crm-dict/CONTEXT.md`](./crm-dict/CONTEXT.md) |
|
|
| `crm-file` | 鏂囦欢瀛樺偍(涓婁紶/棰勮) | [`crm-file/CONTEXT.md`](./crm-file/CONTEXT.md) |
|
|
-| `crm-base` | 鍩虹鍖?閫氱敤鑳藉姏,闈炰笟鍔″煙) | _(鏆傛棤鐙珛棰嗗煙璇█)_ |
|
|
+| `crm-base` | 鍩虹鍖?閫氱敤鑳藉姏,闈炰笟鍔″煙) | [`crm-base/CONTEXT.md`](./crm-base/CONTEXT.md) |
|
|
| `crm-app` | 鍞竴鍚姩鍏ュ彛 | _(鏆傛棤鐙珛棰嗗煙璇█)_ |
|
|
|
|
## System-wide decisions
|
|
|
|
-ADR 鐩綍 `docs/adr/`(绯荤粺绾у喅绛?銆俙README.md` 褰撳墠寮曠敤浜?ADR-0003 / 0004 / 0006,浣嗘枃浠跺皻鏈惤鍦扳€斺€旂敱 `/domain-modeling` 鍦ㄥ喅绛栫湡姝h瑙e喅鏃惰ˉ榻愩€?+ADR 鐩綍 `docs/adr/`(绯荤粺绾у喅绛?銆俙README.md` 褰撳墠寮曠敤浜?ADR-0003 / 0004 / 0006,浣嗘枃浠跺皻鏈惤鍦扳€斺€旂敱 `/domain-modeling` 鍦ㄥ喅绛栫湡姝h瑙e喅鏃惰ˉ榻愩€侫DR-0016 璁板綍浜?PermissionSeeder seam 鍐崇瓥(娑堥櫎璺ㄦā鍧楁潈闄愮瀛愬寲鐨勫奖瀛愬疄浣?銆?
|
|
## Adding a new context
|
|
|
|
diff --git a/crm-auth/src/main/java/com/crm/auth/config/DataInitializer.java b/crm-auth/src/main/java/com/crm/auth/config/DataInitializer.java
|
|
index 5411a9e..aa18e1b 100644
|
|
--- a/crm-auth/src/main/java/com/crm/auth/config/DataInitializer.java
|
|
+++ b/crm-auth/src/main/java/com/crm/auth/config/DataInitializer.java
|
|
@@ -1,33 +1,33 @@
|
|
package com.crm.auth.config;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
-import com.crm.auth.domain.entity.SysMenu;
|
|
import com.crm.auth.domain.entity.SysRole;
|
|
-import com.crm.auth.domain.entity.SysRoleMenu;
|
|
import com.crm.auth.domain.enums.DataScopeEnum;
|
|
-import com.crm.auth.mapper.SysMenuMapper;
|
|
import com.crm.auth.mapper.SysRoleMapper;
|
|
-import com.crm.auth.mapper.SysRoleMenuMapper;
|
|
+import com.crm.base.domain.dto.ButtonSeed;
|
|
+import com.crm.base.domain.dto.PermissionModuleDescriptor;
|
|
+import com.crm.base.service.PermissionSeeder;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.boot.CommandLineRunner;
|
|
+import org.springframework.core.annotation.Order;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 绯荤粺鏁版嵁鍒濆鍖栵紙骞傜瓑锛夛細姣忔鍚姩閫愰」妫€鏌ワ紝鍙ˉ缂虹殑銆?- * <p>鍒涘缓鍐呯疆绠$悊鍛樿鑹层€佺郴缁熺鐞嗚彍鍗曘€佽鑹茬鐞?button 鏉冮檺鐐癸紝
|
|
- * 骞跺皢鍏ㄩ儴璧勬簮鍒嗛厤缁欑鐞嗗憳瑙掕壊锛圓DR-0012锛夈€?/p>
|
|
+ * <p>鍒涘缓鍐呯疆绠$悊鍛樿鑹诧紝鐒跺悗閫氳繃 {@link PermissionSeeder} seam 绉嶅瓙鍖栫郴缁熺鐞嗚彍鍗曘€?+ * 瑙掕壊绠$悊/鑿滃崟绠$悊/閮ㄩ棬绠$悊鐨?button 鏉冮檺鐐癸紝骞跺皢鍏ㄩ儴璧勬簮鍒嗛厤缁欑鐞嗗憳瑙掕壊锛圓DR-0012銆丄DR-0016锛夈€?/p>
|
|
*/
|
|
@Slf4j
|
|
@Component
|
|
+@Order(1)
|
|
@RequiredArgsConstructor
|
|
public class DataInitializer implements CommandLineRunner {
|
|
|
|
private final SysRoleMapper sysRoleMapper;
|
|
- private final SysMenuMapper sysMenuMapper;
|
|
- private final SysRoleMenuMapper sysRoleMenuMapper;
|
|
+ private final PermissionSeeder permissionSeeder;
|
|
|
|
@Override
|
|
public void run(String... args) {
|
|
@@ -51,115 +51,45 @@ public class DataInitializer implements CommandLineRunner {
|
|
log.info("琛ヨ鍐呯疆瑙掕壊鏍囪锛歿}", adminRole.getRoleCode());
|
|
}
|
|
|
|
- // ---- 涓€绾х洰褰曪細绯荤粺绠$悊 ----
|
|
- SysMenu sysManage = findMenu("绯荤粺绠$悊", 0L);
|
|
- if (sysManage == null) {
|
|
- sysManage = insertMenu(new MenuSeed("绯荤粺绠$悊", 0L, 1, null, null, 0));
|
|
- }
|
|
-
|
|
- // ---- 浜岀骇鑿滃崟 ----
|
|
- SysMenu roleManage = findMenu("瑙掕壊绠$悊", sysManage.getId());
|
|
- if (roleManage == null) {
|
|
- roleManage = insertMenu(new MenuSeed("瑙掕壊绠$悊", sysManage.getId(), 2,
|
|
- "/system/role", "system/role/index", 1));
|
|
- }
|
|
- SysMenu menuManage = findMenu("鑿滃崟绠$悊", sysManage.getId());
|
|
- if (menuManage == null) {
|
|
- menuManage = insertMenu(new MenuSeed("鑿滃崟绠$悊", sysManage.getId(), 2,
|
|
- "/system/menu", "system/menu/index", 2));
|
|
- }
|
|
- SysMenu deptManage = findMenu("閮ㄩ棬绠$悊", sysManage.getId());
|
|
- if (deptManage == null) {
|
|
- deptManage = insertMenu(new MenuSeed("閮ㄩ棬绠$悊", sysManage.getId(), 2,
|
|
- "/system/dept", "system/dept/index", 3));
|
|
- }
|
|
-
|
|
- // ---- 瑙掕壊绠$悊 button 鏉冮檺鐐癸紙ADR-0012锛?----
|
|
- insertButtonIfAbsent("瑙掕壊鍒楄〃", roleManage.getId(), "crm:role:list", "/api/roles/page", 1);
|
|
- insertButtonIfAbsent("瑙掕壊璇︽儏", roleManage.getId(), "crm:role:detail", "/api/roles/detail", 2);
|
|
- insertButtonIfAbsent("瑙掕壊淇濆瓨", roleManage.getId(), "crm:role:save", "/api/roles/saveOrUpdate", 3);
|
|
- insertButtonIfAbsent("瑙掕壊鍒犻櫎", roleManage.getId(), "crm:role:delete", "/api/roles/delete", 4);
|
|
- insertButtonIfAbsent("鏉冮檺鍒嗛厤", roleManage.getId(), "crm:role:assign", "/api/roles/assign-resources", 5);
|
|
-
|
|
- // ---- 瑙掕壊-鑿滃崟缁戝畾锛堢鐞嗗憳鎷ユ湁鎵€鏈夎彍鍗曞拰鏉冮檺鐐癸級 ----
|
|
- bindIfAbsent(adminRole.getId(), sysManage.getId());
|
|
- bindIfAbsent(adminRole.getId(), roleManage.getId());
|
|
- bindIfAbsent(adminRole.getId(), menuManage.getId());
|
|
- bindIfAbsent(adminRole.getId(), deptManage.getId());
|
|
- // 缁戝畾瑙掕壊绠$悊涓嬬殑鍏ㄩ儴 button 鏉冮檺鐐?- List<SysMenu> roleButtons = sysMenuMapper.selectList(
|
|
- new LambdaQueryWrapper<SysMenu>()
|
|
- .eq(SysMenu::getParentId, roleManage.getId())
|
|
- .eq(SysMenu::getMenuType, 3));
|
|
- for (SysMenu btn : roleButtons) {
|
|
- bindIfAbsent(adminRole.getId(), btn.getId());
|
|
- }
|
|
+ // ---- 瑙掕壊绠$悊鑿滃崟 + 5 涓?button 鏉冮檺鐐癸紙ADR-0012锛?----
|
|
+ permissionSeeder.seedModule(new PermissionModuleDescriptor(
|
|
+ "绯荤粺绠$悊",
|
|
+ "瑙掕壊绠$悊",
|
|
+ "/system/role",
|
|
+ "system/role/index",
|
|
+ 1,
|
|
+ List.of(
|
|
+ new ButtonSeed("瑙掕壊鍒楄〃", "crm:role:list", "/api/roles/page", 1),
|
|
+ new ButtonSeed("瑙掕壊璇︽儏", "crm:role:detail", "/api/roles/detail", 2),
|
|
+ new ButtonSeed("瑙掕壊淇濆瓨", "crm:role:save", "/api/roles/saveOrUpdate", 3),
|
|
+ new ButtonSeed("瑙掕壊鍒犻櫎", "crm:role:delete", "/api/roles/delete", 4),
|
|
+ new ButtonSeed("鏉冮檺鍒嗛厤", "crm:role:assign", "/api/roles/assign-resources", 5)
|
|
+ ),
|
|
+ List.of("ROLE_ADMIN")
|
|
+ ));
|
|
+
|
|
+ // ---- 鑿滃崟绠$悊鑿滃崟锛堟棤 button锛?----
|
|
+ permissionSeeder.seedModule(new PermissionModuleDescriptor(
|
|
+ "绯荤粺绠$悊",
|
|
+ "鑿滃崟绠$悊",
|
|
+ "/system/menu",
|
|
+ "system/menu/index",
|
|
+ 2,
|
|
+ List.of(),
|
|
+ List.of("ROLE_ADMIN")
|
|
+ ));
|
|
+
|
|
+ // ---- 閮ㄩ棬绠$悊鑿滃崟锛堟棤 button锛?----
|
|
+ permissionSeeder.seedModule(new PermissionModuleDescriptor(
|
|
+ "绯荤粺绠$悊",
|
|
+ "閮ㄩ棬绠$悊",
|
|
+ "/system/dept",
|
|
+ "system/dept/index",
|
|
+ 3,
|
|
+ List.of(),
|
|
+ List.of("ROLE_ADMIN")
|
|
+ ));
|
|
|
|
log.info("鏉冮檺鏁版嵁鍒濆鍖栨鏌ュ畬鎴?);
|
|
}
|
|
-
|
|
- // ==================== 骞傜瓑杈呭姪鏂规硶 ====================
|
|
-
|
|
- private SysMenu findMenu(String name, Long parentId) {
|
|
- return sysMenuMapper.selectOne(
|
|
- new LambdaQueryWrapper<SysMenu>()
|
|
- .eq(SysMenu::getMenuName, name)
|
|
- .eq(SysMenu::getParentId, parentId));
|
|
- }
|
|
-
|
|
- private SysMenu insertMenu(MenuSeed seed) {
|
|
- SysMenu m = new SysMenu();
|
|
- m.setParentId(seed.parentId());
|
|
- m.setMenuName(seed.name());
|
|
- m.setMenuType(seed.type());
|
|
- m.setPath(seed.path());
|
|
- m.setComponent(seed.component());
|
|
- m.setSort(seed.sort());
|
|
- m.setVisible(true);
|
|
- sysMenuMapper.insert(m);
|
|
- log.info("鍒涘缓鑿滃崟鑺傜偣锛歿} (type={})", seed.name(), seed.type());
|
|
- return m;
|
|
- }
|
|
-
|
|
- /**
|
|
- * 鑿滃崟绉嶅瓙锛氭秷闄?insertMenu 鐨勪綅缃弬鏁版涔夈€?- */
|
|
- private record MenuSeed(String name, Long parentId, int type,
|
|
- String path, String component, int sort) {
|
|
- }
|
|
-
|
|
- private void insertButtonIfAbsent(String name, Long parentId,
|
|
- String perms, String apiUrl, int sort) {
|
|
- Long count = sysMenuMapper.selectCount(
|
|
- new LambdaQueryWrapper<SysMenu>().eq(SysMenu::getPerms, perms));
|
|
- if (count > 0) {
|
|
- return;
|
|
- }
|
|
- SysMenu btn = new SysMenu();
|
|
- btn.setParentId(parentId);
|
|
- btn.setMenuName(name);
|
|
- btn.setMenuType(3);
|
|
- btn.setSort(sort);
|
|
- btn.setVisible(true);
|
|
- btn.setPerms(perms);
|
|
- btn.setDenyBehavior("hide");
|
|
- btn.setApiUrl(apiUrl);
|
|
- btn.setStatus("enabled");
|
|
- sysMenuMapper.insert(btn);
|
|
- log.info("鍒涘缓鏉冮檺鐐癸細{} -> {}", name, perms);
|
|
- }
|
|
-
|
|
- private void bindIfAbsent(Long roleId, Long menuId) {
|
|
- Long count = sysRoleMenuMapper.selectCount(
|
|
- new LambdaQueryWrapper<SysRoleMenu>()
|
|
- .eq(SysRoleMenu::getRoleId, roleId)
|
|
- .eq(SysRoleMenu::getMenuId, menuId));
|
|
- if (count > 0) {
|
|
- return;
|
|
- }
|
|
- SysRoleMenu rm = new SysRoleMenu();
|
|
- rm.setRoleId(roleId);
|
|
- rm.setMenuId(menuId);
|
|
- sysRoleMenuMapper.insert(rm);
|
|
- }
|
|
}
|
|
diff --git a/crm-auth/target/classes/com/crm/auth/config/DataInitializer.class b/crm-auth/target/classes/com/crm/auth/config/DataInitializer.class
|
|
index b6709a2..ff64c05 100644
|
|
Binary files a/crm-auth/target/classes/com/crm/auth/config/DataInitializer.class and b/crm-auth/target/classes/com/crm/auth/config/DataInitializer.class differ
|
|
diff --git a/crm-dict/src/main/java/com/crm/dict/config/DictPermissionInitializer.java b/crm-dict/src/main/java/com/crm/dict/config/DictPermissionInitializer.java
|
|
index b3cc8fe..20a5df5 100644
|
|
--- a/crm-dict/src/main/java/com/crm/dict/config/DictPermissionInitializer.java
|
|
+++ b/crm-dict/src/main/java/com/crm/dict/config/DictPermissionInitializer.java
|
|
@@ -1,25 +1,22 @@
|
|
package com.crm.dict.config;
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
+import com.crm.base.domain.dto.ButtonSeed;
|
|
+import com.crm.base.domain.dto.PermissionModuleDescriptor;
|
|
+import com.crm.base.service.PermissionSeeder;
|
|
import com.crm.dict.constant.DictConstants;
|
|
-import com.crm.dict.domain.entity.SysMenuSeed;
|
|
-import com.crm.dict.domain.entity.SysRoleMenuSeed;
|
|
-import com.crm.dict.domain.entity.SysRoleSeed;
|
|
-import com.crm.dict.mapper.SysMenuSeedMapper;
|
|
-import com.crm.dict.mapper.SysRoleMenuSeedMapper;
|
|
-import com.crm.dict.mapper.SysRoleSeedMapper;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.boot.CommandLineRunner;
|
|
+import org.springframework.core.annotation.Order;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
-import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
- * 鏁版嵁瀛楀吀鏉冮檺绉嶅瓙鍖栵紙骞傜瓑锛孴07锛?- * <p>灏?10 涓?{@code dict:...} 鏉冮檺鐮佺瀛愬寲鍒版潈闄愯祫婧愭爲锛坰ys_menu 鐗╃悊琛級骞剁粦瀹氬唴缃鐞嗗憳瑙掕壊銆?- * 涓?crm-auth DataInitializer 鏃犺€﹀悎锛氱郴缁熺鐞嗙洰褰曠己澶卞垯鑷缓锛汻OLE_ADMIN 缂哄け鍒欒烦杩囩粦瀹氬苟 warn
|
|
+ * 鏁版嵁瀛楀吀鏉冮檺绉嶅瓙鍖栵紙骞傜瓑锛孴07锛孉DR-0016锛?+ * <p>閫氳繃 {@link PermissionSeeder} seam 灏?10 涓?{@code dict:...} 鏉冮檺鐮佺瀛愬寲鍒版潈闄愯祫婧愭爲
|
|
+ * 锛坰ys_menu 鐗╃悊琛級骞剁粦瀹氬唴缃鐞嗗憳瑙掕壊銆備笌 crm-auth DataInitializer 鏃犺€﹀悎锛?+ * 绯荤粺绠$悊鐩綍缂哄け鍒?seam 鑷缓锛汻OLE_ADMIN 缂哄け鍒?seam warn 璺宠繃缁戝畾
|
|
* 锛坈rm-auth 棣栨鍚姩鍒涘缓鍚庯紝瀛楀吀鏉冮檺鍦ㄤ笅娆″惎鍔ㄨˉ缁戯級銆?/p>
|
|
* <p>鏉冮檺鐐瑰啓鍏ヤ簡 api_url锛歝rm-auth 鐨?ApiPermissionInterceptor 鎸?api_url 鎳掑姞杞借鍒欙紝
|
|
* 绉嶅瓙鍖栧畬鎴愬悗涓荤鐐癸紙page/saveOrUpdate/delete/status/set-default 绛夛級鏈巿鏉冭闂嵆琚嫤鎴紱
|
|
@@ -27,15 +24,11 @@ import java.util.List;
|
|
*/
|
|
@Slf4j
|
|
@Component
|
|
+@Order(10)
|
|
@RequiredArgsConstructor
|
|
public class DictPermissionInitializer implements CommandLineRunner {
|
|
|
|
- private final SysMenuSeedMapper sysMenuMapper;
|
|
- private final SysRoleSeedMapper sysRoleMapper;
|
|
- private final SysRoleMenuSeedMapper sysRoleMenuMapper;
|
|
-
|
|
- /** 鎸夐挳绫诲瀷锛堜笌 crm-auth 鑿滃崟绫诲瀷鏋氫妇涓€鑷达級 */
|
|
- private static final int MENU_TYPE_BUTTON = 3;
|
|
+ private final PermissionSeeder permissionSeeder;
|
|
|
|
/** 10 涓潈闄愮偣绉嶅瓙锛?鍚嶇О, 鏉冮檺鐮? apiUrl, 鎺掑簭)銆傛潈闄愮爜涓庡墠绔枃妗?搂8 涓€鑷?*/
|
|
private static final List<ButtonSeed> BUTTON_SEEDS = List.of(
|
|
@@ -54,104 +47,16 @@ public class DictPermissionInitializer implements CommandLineRunner {
|
|
public void run(String... args) {
|
|
log.info("鎵ц鏁版嵁瀛楀吀鏉冮檺绉嶅瓙鍖栨鏌?..");
|
|
|
|
- // ---- 涓€绾х洰褰曪細绯荤粺绠$悊锛堢己澶辫嚜寤猴紝涓?crm-auth DataInitializer 椤哄簭鏃犲叧锛?----
|
|
- SysMenuSeed sysManage = findMenuByName("绯荤粺绠$悊", 0L);
|
|
- if (sysManage == null) {
|
|
- sysManage = insertMenu("绯荤粺绠$悊", 0L, 1, null, null, 0);
|
|
- }
|
|
-
|
|
- // ---- 浜岀骇鑿滃崟锛氭暟鎹瓧鍏革紙鎸傚湪绯荤粺绠$悊涓嬶級 ----
|
|
- SysMenuSeed dictMenu = findMenuByName("鏁版嵁瀛楀吀", sysManage.getId());
|
|
- if (dictMenu == null) {
|
|
- dictMenu = insertMenu("鏁版嵁瀛楀吀", sysManage.getId(), 2,
|
|
- "/system/dict", "system/dict/index", 4);
|
|
- }
|
|
-
|
|
- // ---- 10 涓寜閽潈闄愮偣锛堟寜 perms 骞傜瓑鏌ラ噸锛屽瓨鍦ㄥ嵆璺宠繃锛?----
|
|
- List<Long> buttonIds = new ArrayList<>(BUTTON_SEEDS.size());
|
|
- for (ButtonSeed seed : BUTTON_SEEDS) {
|
|
- buttonIds.add(insertButtonIfAbsent(seed.name(), dictMenu.getId(),
|
|
- seed.perms(), seed.apiUrl(), seed.sort()));
|
|
- }
|
|
-
|
|
- // ---- 缁戝畾鍐呯疆绠$悊鍛樿鑹诧紙缂哄け璺宠繃 + warn锛?----
|
|
- SysRoleSeed admin = sysRoleMapper.selectOne(
|
|
- new LambdaQueryWrapper<SysRoleSeed>().eq(SysRoleSeed::getRoleCode, "ROLE_ADMIN"));
|
|
- if (admin == null) {
|
|
- log.warn("鍐呯疆瑙掕壊 ROLE_ADMIN 涓嶅瓨鍦紝璺宠繃鏁版嵁瀛楀吀鏉冮檺缁戝畾锛坈rm-auth 鍒涘缓璇ヨ鑹插悗涓嬫鍚姩琛ョ粦锛?);
|
|
- return;
|
|
- }
|
|
- bindIfAbsent(admin.getId(), sysManage.getId());
|
|
- bindIfAbsent(admin.getId(), dictMenu.getId());
|
|
- for (Long buttonId : buttonIds) {
|
|
- bindIfAbsent(admin.getId(), buttonId);
|
|
- }
|
|
+ permissionSeeder.seedModule(new PermissionModuleDescriptor(
|
|
+ "绯荤粺绠$悊",
|
|
+ "鏁版嵁瀛楀吀",
|
|
+ "/system/dict",
|
|
+ "system/dict/index",
|
|
+ 4,
|
|
+ BUTTON_SEEDS,
|
|
+ List.of("ROLE_ADMIN")
|
|
+ ));
|
|
|
|
log.info("鏁版嵁瀛楀吀鏉冮檺绉嶅瓙鍖栨鏌ュ畬鎴愶細{} 涓潈闄愮偣", BUTTON_SEEDS.size());
|
|
}
|
|
-
|
|
- // ==================== 骞傜瓑杈呭姪鏂规硶 ====================
|
|
-
|
|
- private SysMenuSeed findMenuByName(String name, Long parentId) {
|
|
- return sysMenuMapper.selectOne(new LambdaQueryWrapper<SysMenuSeed>()
|
|
- .eq(SysMenuSeed::getMenuName, name)
|
|
- .eq(SysMenuSeed::getParentId, parentId));
|
|
- }
|
|
-
|
|
- private SysMenuSeed insertMenu(String name, Long parentId, int type,
|
|
- String path, String component, int sort) {
|
|
- SysMenuSeed m = new SysMenuSeed();
|
|
- m.setParentId(parentId);
|
|
- m.setMenuName(name);
|
|
- m.setMenuType(type);
|
|
- m.setPath(path);
|
|
- m.setComponent(component);
|
|
- m.setSort(sort);
|
|
- m.setVisible(true);
|
|
- sysMenuMapper.insert(m);
|
|
- log.info("鍒涘缓鑿滃崟鑺傜偣锛歿} (type={})", name, type);
|
|
- return m;
|
|
- }
|
|
-
|
|
- /**
|
|
- * 鎸夋潈闄愮爜鏌ラ噸鎻掑叆鎸夐挳鏉冮檺鐐癸紝杩斿洖鍏?id锛堝凡瀛樺湪鍒欒繑鍥炵幇鏈?id锛夈€?- */
|
|
- private Long insertButtonIfAbsent(String name, Long parentId, String perms,
|
|
- String apiUrl, int sort) {
|
|
- SysMenuSeed exist = sysMenuMapper.selectOne(
|
|
- new LambdaQueryWrapper<SysMenuSeed>().eq(SysMenuSeed::getPerms, perms));
|
|
- if (exist != null) {
|
|
- return exist.getId();
|
|
- }
|
|
- SysMenuSeed btn = new SysMenuSeed();
|
|
- btn.setParentId(parentId);
|
|
- btn.setMenuName(name);
|
|
- btn.setMenuType(MENU_TYPE_BUTTON);
|
|
- btn.setSort(sort);
|
|
- btn.setVisible(true);
|
|
- btn.setPerms(perms);
|
|
- btn.setDenyBehavior("hide");
|
|
- btn.setApiUrl(apiUrl);
|
|
- btn.setStatus("enabled");
|
|
- sysMenuMapper.insert(btn);
|
|
- log.info("鍒涘缓鏉冮檺鐐癸細{} -> {}", name, perms);
|
|
- return btn.getId();
|
|
- }
|
|
-
|
|
- private void bindIfAbsent(Long roleId, Long menuId) {
|
|
- Long count = sysRoleMenuMapper.selectCount(new LambdaQueryWrapper<SysRoleMenuSeed>()
|
|
- .eq(SysRoleMenuSeed::getRoleId, roleId)
|
|
- .eq(SysRoleMenuSeed::getMenuId, menuId));
|
|
- if (count > 0) {
|
|
- return;
|
|
- }
|
|
- SysRoleMenuSeed rm = new SysRoleMenuSeed();
|
|
- rm.setRoleId(roleId);
|
|
- rm.setMenuId(menuId);
|
|
- sysRoleMenuMapper.insert(rm);
|
|
- }
|
|
-
|
|
- /** 鎸夐挳绉嶅瓙锛氭秷闄?insertButtonIfAbsent 鐨勪綅缃弬鏁版涔?*/
|
|
- private record ButtonSeed(String name, String perms, String apiUrl, int sort) {
|
|
- }
|
|
}
|
|
diff --git a/crm-dict/src/main/java/com/crm/dict/domain/entity/SysMenuSeed.java b/crm-dict/src/main/java/com/crm/dict/domain/entity/SysMenuSeed.java
|
|
deleted file mode 100644
|
|
index 9982ea6..0000000
|
|
--- a/crm-dict/src/main/java/com/crm/dict/domain/entity/SysMenuSeed.java
|
|
+++ /dev/null
|
|
@@ -1,50 +0,0 @@
|
|
-package com.crm.dict.domain.entity;
|
|
-
|
|
-import com.baomidou.mybatisplus.annotation.TableName;
|
|
-import com.crm.base.domain.entity.BaseEntity;
|
|
-import lombok.Data;
|
|
-import lombok.EqualsAndHashCode;
|
|
-
|
|
-/**
|
|
- * 鏉冮檺璧勬簮鏍戞渶灏忓寲鏄犲皠锛坰ys_menu 鐗╃悊琛紝T07锛?- * <p>浠呯敤浜?crm-dict 骞傜瓑绉嶅瓙鍖栨潈闄愮偣锛屽埢鎰忎笉鏍?@Entity锛氬缓琛ㄥ綊 crm-auth 鐨?SysMenu锛?- * 鏈被鍙仛 MyBatis-Plus 璇诲啓锛岄伩鍏嶄笌 crm-auth 鍙屽疄浣撴槧灏勫悓涓€寮犺〃锛圓DR-0015 闆朵緷璧栫害鏉燂級銆?/p>
|
|
- */
|
|
-@Data
|
|
-@EqualsAndHashCode(callSuper = true)
|
|
-@TableName("sys_menu")
|
|
-public class SysMenuSeed extends BaseEntity {
|
|
-
|
|
- /** 涓婄骇鑿滃崟ID锛屾牴鑺傜偣涓?0 */
|
|
- private Long parentId;
|
|
-
|
|
- /** 鑿滃崟鍚嶇О */
|
|
- private String menuName;
|
|
-
|
|
- /** 绫诲瀷锛?=鐩綍 2=鑿滃崟 3=鎸夐挳 */
|
|
- private Integer menuType;
|
|
-
|
|
- /** 鍓嶇璺敱璺緞锛堢洰褰?鑿滃崟鐢級 */
|
|
- private String path;
|
|
-
|
|
- /** 鍓嶇缁勪欢璺緞锛堣彍鍗曠敤锛?*/
|
|
- private String component;
|
|
-
|
|
- /** 鎺掑簭 */
|
|
- private Integer sort;
|
|
-
|
|
- /** 鏄惁鍙 */
|
|
- private Boolean visible;
|
|
-
|
|
- /** 鏉冮檺鐮侊紙鎸夐挳绾ф潈闄愭爣璇嗭紝濡?dict:item:list锛?*/
|
|
- private String perms;
|
|
-
|
|
- /** 鏃犳潈闄愭椂鐨勫墠绔涓猴細hide 闅愯棌锛宒isable 绂佺敤 */
|
|
- private String denyBehavior;
|
|
-
|
|
- /** 鏉冮檺鐐圭姸鎬侊細enabled 鍚敤锛宒isabled 鍋滅敤锛堝叏灞€鏂矾锛?*/
|
|
- private String status;
|
|
-
|
|
- /** 鎺ュ彛 URL锛堟寜閽搴旂殑鍚庣 API 璺緞锛孉piPermissionInterceptor 鎸夋鍖归厤瑙勫垯锛?*/
|
|
- private String apiUrl;
|
|
-}
|
|
diff --git a/crm-dict/src/main/java/com/crm/dict/domain/entity/SysRoleMenuSeed.java b/crm-dict/src/main/java/com/crm/dict/domain/entity/SysRoleMenuSeed.java
|
|
deleted file mode 100644
|
|
index dc1d863..0000000
|
|
--- a/crm-dict/src/main/java/com/crm/dict/domain/entity/SysRoleMenuSeed.java
|
|
+++ /dev/null
|
|
@@ -1,25 +0,0 @@
|
|
-package com.crm.dict.domain.entity;
|
|
-
|
|
-import com.baomidou.mybatisplus.annotation.IdType;
|
|
-import com.baomidou.mybatisplus.annotation.TableId;
|
|
-import com.baomidou.mybatisplus.annotation.TableName;
|
|
-import lombok.Data;
|
|
-
|
|
-/**
|
|
- * 瑙掕壊-璧勬簮缁戝畾鏈€灏忓寲鏄犲皠锛坰ys_role_menu 鐗╃悊琛紝T07锛?- * <p>浠呯敤浜?crm-dict 骞傜瓑绉嶅瓙鍖栨椂灏嗘潈闄愮偣缁戝畾鍒板唴缃鐞嗗憳瑙掕壊锛?- * 鍒绘剰涓嶆爣 @Entity锛屽缓琛ㄥ綊 crm-auth 鐨?SysRoleMenu锛圓DR-0015 闆朵緷璧栫害鏉燂級銆?/p>
|
|
- */
|
|
-@Data
|
|
-@TableName("sys_role_menu")
|
|
-public class SysRoleMenuSeed {
|
|
-
|
|
- @TableId(type = IdType.ASSIGN_ID)
|
|
- private Long id;
|
|
-
|
|
- /** 瑙掕壊ID */
|
|
- private Long roleId;
|
|
-
|
|
- /** 鑿滃崟/鏉冮檺鐐笽D */
|
|
- private Long menuId;
|
|
-}
|
|
diff --git a/crm-dict/src/main/java/com/crm/dict/domain/entity/SysRoleSeed.java b/crm-dict/src/main/java/com/crm/dict/domain/entity/SysRoleSeed.java
|
|
deleted file mode 100644
|
|
index 1a25d56..0000000
|
|
--- a/crm-dict/src/main/java/com/crm/dict/domain/entity/SysRoleSeed.java
|
|
+++ /dev/null
|
|
@@ -1,32 +0,0 @@
|
|
-package com.crm.dict.domain.entity;
|
|
-
|
|
-import com.baomidou.mybatisplus.annotation.TableName;
|
|
-import com.crm.base.domain.entity.BaseEntity;
|
|
-import lombok.Data;
|
|
-import lombok.EqualsAndHashCode;
|
|
-
|
|
-/**
|
|
- * 绯荤粺瑙掕壊鏈€灏忓寲鏄犲皠锛坰ys_role 鐗╃悊琛紝T07锛?- * <p>浠呯敤浜?crm-dict 骞傜瓑绉嶅瓙鍖栨椂瀹氫綅鍐呯疆绠$悊鍛樿鑹?ROLE_ADMIN锛屽埢鎰忎笉鏍?@Entity锛?- * 寤鸿〃褰?crm-auth 鐨?SysRole锛圓DR-0015 闆朵緷璧栫害鏉燂級銆?/p>
|
|
- */
|
|
-@Data
|
|
-@EqualsAndHashCode(callSuper = true)
|
|
-@TableName("sys_role")
|
|
-public class SysRoleSeed extends BaseEntity {
|
|
-
|
|
- /** 瑙掕壊鍚嶇О */
|
|
- private String roleName;
|
|
-
|
|
- /** 瑙掕壊缂栫爜锛堝 ROLE_ADMIN锛?*/
|
|
- private String roleCode;
|
|
-
|
|
- /** 鏁版嵁鑼冨洿锛?=鏈汉 2=鏈儴闂?3=鏈儴闂ㄥ強瀛愰儴闂?4=鍏ㄩ儴 */
|
|
- private Integer dataScope;
|
|
-
|
|
- /** 鎺掑簭 */
|
|
- private Integer sort;
|
|
-
|
|
- /** 鍐呯疆瑙掕壊鏍囪锛歵rue=绯荤粺鍐呯疆涓嶅彲鍒犻櫎涓嶅彲鏀圭紪鐮?*/
|
|
- private Boolean builtin;
|
|
-}
|
|
diff --git a/crm-dict/src/main/java/com/crm/dict/mapper/SysMenuSeedMapper.java b/crm-dict/src/main/java/com/crm/dict/mapper/SysMenuSeedMapper.java
|
|
deleted file mode 100644
|
|
index 2251978..0000000
|
|
--- a/crm-dict/src/main/java/com/crm/dict/mapper/SysMenuSeedMapper.java
|
|
+++ /dev/null
|
|
@@ -1,12 +0,0 @@
|
|
-package com.crm.dict.mapper;
|
|
-
|
|
-import com.crm.base.mapper.CrmBaseMapper;
|
|
-import com.crm.dict.domain.entity.SysMenuSeed;
|
|
-import org.apache.ibatis.annotations.Mapper;
|
|
-
|
|
-/**
|
|
- * sys_menu 鏈€灏忓寲鏄犲皠 Mapper锛圱07 鏉冮檺绉嶅瓙鍖栦笓鐢級
|
|
- */
|
|
-@Mapper
|
|
-public interface SysMenuSeedMapper extends CrmBaseMapper<SysMenuSeed> {
|
|
-}
|
|
diff --git a/crm-dict/src/main/java/com/crm/dict/mapper/SysRoleMenuSeedMapper.java b/crm-dict/src/main/java/com/crm/dict/mapper/SysRoleMenuSeedMapper.java
|
|
deleted file mode 100644
|
|
index c7c98d5..0000000
|
|
--- a/crm-dict/src/main/java/com/crm/dict/mapper/SysRoleMenuSeedMapper.java
|
|
+++ /dev/null
|
|
@@ -1,12 +0,0 @@
|
|
-package com.crm.dict.mapper;
|
|
-
|
|
-import com.crm.base.mapper.CrmBaseMapper;
|
|
-import com.crm.dict.domain.entity.SysRoleMenuSeed;
|
|
-import org.apache.ibatis.annotations.Mapper;
|
|
-
|
|
-/**
|
|
- * sys_role_menu 鏈€灏忓寲鏄犲皠 Mapper锛圱07 鏉冮檺绉嶅瓙鍖栦笓鐢級
|
|
- */
|
|
-@Mapper
|
|
-public interface SysRoleMenuSeedMapper extends CrmBaseMapper<SysRoleMenuSeed> {
|
|
-}
|
|
diff --git a/crm-dict/src/main/java/com/crm/dict/mapper/SysRoleSeedMapper.java b/crm-dict/src/main/java/com/crm/dict/mapper/SysRoleSeedMapper.java
|
|
deleted file mode 100644
|
|
index 985c73c..0000000
|
|
--- a/crm-dict/src/main/java/com/crm/dict/mapper/SysRoleSeedMapper.java
|
|
+++ /dev/null
|
|
@@ -1,12 +0,0 @@
|
|
-package com.crm.dict.mapper;
|
|
-
|
|
-import com.crm.base.mapper.CrmBaseMapper;
|
|
-import com.crm.dict.domain.entity.SysRoleSeed;
|
|
-import org.apache.ibatis.annotations.Mapper;
|
|
-
|
|
-/**
|
|
- * sys_role 鏈€灏忓寲鏄犲皠 Mapper锛圱07 鏉冮檺绉嶅瓙鍖栦笓鐢級
|
|
- */
|
|
-@Mapper
|
|
-public interface SysRoleSeedMapper extends CrmBaseMapper<SysRoleSeed> {
|
|
-}
|
|
diff --git a/crm-dict/src/test/java/com/crm/dict/config/DictPermissionInitializerTest.java b/crm-dict/src/test/java/com/crm/dict/config/DictPermissionInitializerTest.java
|
|
index 2c7b490..40d52d9 100644
|
|
--- a/crm-dict/src/test/java/com/crm/dict/config/DictPermissionInitializerTest.java
|
|
+++ b/crm-dict/src/test/java/com/crm/dict/config/DictPermissionInitializerTest.java
|
|
@@ -1,63 +1,34 @@
|
|
package com.crm.dict.config;
|
|
|
|
-import com.baomidou.mybatisplus.annotation.DbType;
|
|
-import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
|
-import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
|
|
-import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
|
|
-import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
-import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
|
-import com.crm.base.config.MetaObjectFillHandler;
|
|
+import com.crm.base.domain.dto.ButtonSeed;
|
|
+import com.crm.base.domain.dto.PermissionModuleDescriptor;
|
|
+import com.crm.base.service.PermissionSeeder;
|
|
import com.crm.dict.constant.DictConstants;
|
|
import com.crm.dict.controller.DictGroupController;
|
|
import com.crm.dict.controller.DictItemController;
|
|
-import com.crm.dict.domain.entity.SysMenuSeed;
|
|
-import com.crm.dict.domain.entity.SysRoleMenuSeed;
|
|
-import com.crm.dict.domain.entity.SysRoleSeed;
|
|
-import com.crm.dict.mapper.SysMenuSeedMapper;
|
|
-import com.crm.dict.mapper.SysRoleMenuSeedMapper;
|
|
-import com.crm.dict.mapper.SysRoleSeedMapper;
|
|
-import org.apache.ibatis.mapping.Environment;
|
|
-import org.apache.ibatis.session.LocalCacheScope;
|
|
-import org.apache.ibatis.session.SqlSession;
|
|
-import org.apache.ibatis.session.SqlSessionFactory;
|
|
-import org.apache.ibatis.session.SqlSessionFactoryBuilder;
|
|
-import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
|
|
-import org.h2.jdbcx.JdbcDataSource;
|
|
-import org.junit.jupiter.api.AfterEach;
|
|
-import org.junit.jupiter.api.BeforeAll;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.DisplayName;
|
|
import org.junit.jupiter.api.Test;
|
|
+import org.mockito.ArgumentCaptor;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
import java.lang.reflect.Method;
|
|
-import java.sql.SQLException;
|
|
-import java.sql.Statement;
|
|
-import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
-import java.util.concurrent.atomic.AtomicBoolean;
|
|
-import java.util.stream.Collectors;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
+import static org.mockito.Mockito.*;
|
|
|
|
/**
|
|
- * T07 鏉冮檺绉嶅瓙鍖栭泦鎴愭祴璇曪細绉嶅瓙鍖栧悗 10 涓潈闄愮偣鎸傛爲骞剁粦瀹氱鐞嗗憳 / 骞傜瓑 / ROLE_ADMIN 缂哄け璺宠繃 / Controller 娉ㄨВ濂戠害
|
|
- * <p>H2 鎵嬪伐瑁呴厤锛堜豢 AbstractDictH2Test锛夛紱"鏃犳潈闄愯闂鎷?鐨勫姩鎬佽涓虹敱 crm-auth
|
|
- * ApiPermissionInterceptor锛堟寜 api_url 鎳掑姞杞借鍒欙級涓?Spring Security 淇濊瘉锛?- * 鏈祴璇曢獙璇佺瀛愬寲浜у嚭婊¤冻璇ユ嫤鎴櫒濂戠害锛坅pi_url + status=enabled + perms锛夈€?/p>
|
|
+ * T07 鏉冮檺绉嶅瓙鍖栨祴璇曪紙ADR-0016锛夛細楠岃瘉 DictPermissionInitializer 閫氳繃 PermissionSeeder seam
|
|
+ * 澹版槑姝g‘鐨勬潈闄愭弿杩扮锛屼笖 Controller 绔偣甯?@PreAuthorize 娉ㄨВ銆?+ * <p>涓嶅啀浣跨敤 H2 寤?sys_menu/sys_role/sys_role_menu 琛ㄢ€斺€攕eam 瀹炵幇鍦?crm-auth 鐨?+ * PermissionSeederImplTest 涓泦鎴愭祴璇曘€?/p>
|
|
*/
|
|
@DisplayName("T07 鏉冮檺绉嶅瓙鍖?)
|
|
class DictPermissionInitializerTest {
|
|
|
|
- private static final AtomicBoolean BOOTSTRAPPED = new AtomicBoolean(false);
|
|
-
|
|
- private static SqlSessionFactory sqlSessionFactory;
|
|
-
|
|
- private SqlSession session;
|
|
- private SysMenuSeedMapper sysMenuMapper;
|
|
- private SysRoleSeedMapper sysRoleMapper;
|
|
- private SysRoleMenuSeedMapper sysRoleMenuMapper;
|
|
+ private PermissionSeeder permissionSeeder;
|
|
private DictPermissionInitializer initializer;
|
|
|
|
/** 10 涓潈闄愮爜锛堜笌 DictConstants + 鍓嶇鏂囨。 搂8 涓€鑷达級 */
|
|
@@ -68,160 +39,39 @@ class DictPermissionInitializerTest {
|
|
DictConstants.PERM_ITEM_DELETE, DictConstants.PERM_ITEM_FORCE_DELETE,
|
|
DictConstants.PERM_ITEM_STATUS, DictConstants.PERM_ITEM_DEFAULT);
|
|
|
|
- @BeforeAll
|
|
- static void bootstrap() throws Exception {
|
|
- if (!BOOTSTRAPPED.compareAndSet(false, true)) {
|
|
- return;
|
|
- }
|
|
- JdbcDataSource ds = new JdbcDataSource();
|
|
- ds.setURL("jdbc:h2:mem:dict-perm;MODE=MySQL;DATABASE_TO_LOWER=TRUE;" +
|
|
- "CASE_INSENSITIVE_IDENTIFIERS=TRUE;DB_CLOSE_DELAY=-1;NON_KEYWORDS=VALUE");
|
|
-
|
|
- MybatisConfiguration configuration = new MybatisConfiguration();
|
|
- configuration.setEnvironment(new Environment("dict-perm-test", new JdbcTransactionFactory(), ds));
|
|
- configuration.setMapUnderscoreToCamelCase(true);
|
|
- configuration.setLocalCacheScope(LocalCacheScope.STATEMENT);
|
|
-
|
|
- MybatisPlusInterceptor mpInterceptor = new MybatisPlusInterceptor();
|
|
- mpInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
|
- configuration.addInterceptor(mpInterceptor);
|
|
-
|
|
- GlobalConfigUtils.getGlobalConfig(configuration).setMetaObjectHandler(new MetaObjectFillHandler());
|
|
- GlobalConfigUtils.getGlobalConfig(configuration).setIdentifierGenerator(DefaultIdentifierGenerator.getInstance());
|
|
-
|
|
- configuration.addMapper(SysMenuSeedMapper.class);
|
|
- configuration.addMapper(SysRoleSeedMapper.class);
|
|
- configuration.addMapper(SysRoleMenuSeedMapper.class);
|
|
- sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
|
|
-
|
|
- try (SqlSession s = sqlSessionFactory.openSession(true);
|
|
- Statement st = s.getConnection().createStatement()) {
|
|
- for (String sql : SCHEMA) {
|
|
- st.execute(sql);
|
|
- }
|
|
- }
|
|
- }
|
|
-
|
|
@BeforeEach
|
|
- void setUp() throws SQLException {
|
|
- session = sqlSessionFactory.openSession(true);
|
|
- try (Statement st = session.getConnection().createStatement()) {
|
|
- st.execute("TRUNCATE TABLE sys_role_menu");
|
|
- st.execute("TRUNCATE TABLE sys_menu");
|
|
- st.execute("TRUNCATE TABLE sys_role");
|
|
- }
|
|
- sysMenuMapper = session.getMapper(SysMenuSeedMapper.class);
|
|
- sysRoleMapper = session.getMapper(SysRoleSeedMapper.class);
|
|
- sysRoleMenuMapper = session.getMapper(SysRoleMenuSeedMapper.class);
|
|
- initializer = new DictPermissionInitializer(sysMenuMapper, sysRoleMapper, sysRoleMenuMapper);
|
|
- }
|
|
-
|
|
- @AfterEach
|
|
- void tearDown() {
|
|
- if (session != null) {
|
|
- session.close();
|
|
- }
|
|
+ void setUp() {
|
|
+ permissionSeeder = mock(PermissionSeeder.class);
|
|
+ initializer = new DictPermissionInitializer(permissionSeeder);
|
|
}
|
|
|
|
@Test
|
|
- @DisplayName("绉嶅瓙鍖栵細绯荤粺绠$悊/鏁版嵁瀛楀吀鎸傛爲锛?0 涓潈闄愮偣甯?api_url 涓旂粦瀹氱鐞嗗憳")
|
|
- void seedAll_createsTreeAndBindsAdmin() {
|
|
- SysRoleSeed admin = insertAdminRole();
|
|
-
|
|
+ @DisplayName("seedModule 澹版槑姝g‘鐨勭洰褰曘€佽彍鍗曘€?0 涓寜閽潈闄愮偣鍜岃鑹茬粦瀹?)
|
|
+ void seedModule_declaresCorrectDescriptor() {
|
|
initializer.run();
|
|
|
|
- // 鐩綍涓庤彍鍗?- SysMenuSeed sysManage = findMenu("绯荤粺绠$悊", 0L);
|
|
- assertThat(sysManage).isNotNull();
|
|
- SysMenuSeed dictMenu = findMenu("鏁版嵁瀛楀吀", sysManage.getId());
|
|
- assertThat(dictMenu).isNotNull();
|
|
- assertThat(dictMenu.getMenuType()).isEqualTo(2);
|
|
- assertThat(dictMenu.getPath()).isEqualTo("/system/dict");
|
|
+ ArgumentCaptor<PermissionModuleDescriptor> captor = ArgumentCaptor.forClass(PermissionModuleDescriptor.class);
|
|
+ verify(permissionSeeder, times(1)).seedModule(captor.capture());
|
|
+
|
|
+ PermissionModuleDescriptor descriptor = captor.getValue();
|
|
+ assertThat(descriptor.catalogName()).isEqualTo("绯荤粺绠$悊");
|
|
+ assertThat(descriptor.menuName()).isEqualTo("鏁版嵁瀛楀吀");
|
|
+ assertThat(descriptor.menuPath()).isEqualTo("/system/dict");
|
|
+ assertThat(descriptor.menuComponent()).isEqualTo("system/dict/index");
|
|
+ assertThat(descriptor.menuSort()).isEqualTo(4);
|
|
+ assertThat(descriptor.bindToRoleCodes()).containsExactly("ROLE_ADMIN");
|
|
|
|
- // 10 涓潈闄愮偣锛歱erms 榻愬叏銆佹寜閽被鍨嬨€乪nabled銆乤pi_url 闈炵┖锛圓piPermissionInterceptor 鍔犺浇濂戠害锛?- List<SysMenuSeed> buttons = sysMenuMapper.selectList(null).stream()
|
|
- .filter(m -> m.getMenuType() == 3)
|
|
- .toList();
|
|
+ // 10 涓寜閽潈闄愮偣
|
|
+ List<ButtonSeed> buttons = descriptor.buttons();
|
|
assertThat(buttons).hasSize(10);
|
|
- assertThat(buttons).extracting(SysMenuSeed::getPerms).containsExactlyInAnyOrderElementsOf(PERM_CODES);
|
|
+ assertThat(buttons).extracting(ButtonSeed::perms).containsExactlyInAnyOrderElementsOf(PERM_CODES);
|
|
+
|
|
+ // 姣忎釜鎸夐挳閮芥湁 apiUrl 鍜?sort
|
|
assertThat(buttons).allSatisfy(b -> {
|
|
- assertThat(b.getStatus()).isEqualTo("enabled");
|
|
- assertThat(b.getApiUrl()).isNotBlank();
|
|
- assertThat(b.getParentId()).isEqualTo(dictMenu.getId());
|
|
+ assertThat(b.apiUrl()).isNotBlank();
|
|
+ assertThat(b.sort()).isGreaterThanOrEqualTo(1);
|
|
+ assertThat(b.name()).isNotBlank();
|
|
});
|
|
-
|
|
- // 缁戝畾绠$悊鍛橈細鐩綍 + 鑿滃崟 + 10 鎸夐挳
|
|
- List<SysRoleMenuSeed> binds = sysRoleMenuMapper.selectList(null);
|
|
- assertThat(binds).hasSize(12);
|
|
- assertThat(binds).allMatch(b -> b.getRoleId().equals(admin.getId()));
|
|
- }
|
|
-
|
|
- @Test
|
|
- @DisplayName("骞傜瓑锛氶噸澶嶆墽琛屼笉浜х敓閲嶅鑿滃崟/鏉冮檺鐐?缁戝畾")
|
|
- void seedAll_idempotent() {
|
|
- insertAdminRole();
|
|
-
|
|
- initializer.run();
|
|
- initializer.run();
|
|
-
|
|
- assertThat(sysMenuMapper.selectCount(null)).isEqualTo(12);
|
|
- assertThat(sysRoleMenuMapper.selectCount(null)).isEqualTo(12);
|
|
- }
|
|
-
|
|
- @Test
|
|
- @DisplayName("ROLE_ADMIN 缂哄け锛氭潈闄愮偣鐓у父绉嶅瓙鍖栵紝璺宠繃缁戝畾涓斾笉鎶涘紓甯?)
|
|
- void seedAll_skipsBindingWhenAdminMissing() {
|
|
- initializer.run();
|
|
-
|
|
- assertThat(sysMenuMapper.selectCount(null)).isEqualTo(12);
|
|
- assertThat(sysRoleMenuMapper.selectCount(null)).isZero();
|
|
- }
|
|
-
|
|
- @Test
|
|
- @DisplayName("澶嶇敤鏃㈡湁鏍戯細绯荤粺绠$悊/鏁版嵁瀛楀吀宸插瓨鍦ㄦ椂涓嶈嚜寤猴紝鏉冮檺鐐规寜 perms 琛ラ綈涓嶉噸澶?)
|
|
- void seedAll_reusesExistingMenuTree() {
|
|
- insertAdminRole();
|
|
- // 妯℃嫙 crm-auth DataInitializer 宸插垱寤虹洰褰曪紝涓旈儴鍒嗘潈闄愮偣宸插瓨鍦紙甯?apiUrl锛?- SysMenuSeed sysManage = new SysMenuSeed();
|
|
- sysManage.setParentId(0L);
|
|
- sysManage.setMenuName("绯荤粺绠$悊");
|
|
- sysManage.setMenuType(1);
|
|
- sysManage.setSort(0);
|
|
- sysManage.setVisible(true);
|
|
- sysMenuMapper.insert(sysManage);
|
|
-
|
|
- SysMenuSeed dictMenu = new SysMenuSeed();
|
|
- dictMenu.setParentId(sysManage.getId());
|
|
- dictMenu.setMenuName("鏁版嵁瀛楀吀");
|
|
- dictMenu.setMenuType(2);
|
|
- dictMenu.setPath("/system/dict");
|
|
- dictMenu.setSort(4);
|
|
- dictMenu.setVisible(true);
|
|
- sysMenuMapper.insert(dictMenu);
|
|
-
|
|
- SysMenuSeed existingButton = new SysMenuSeed();
|
|
- existingButton.setParentId(dictMenu.getId());
|
|
- existingButton.setMenuName("鍒嗙粍鏌ヨ");
|
|
- existingButton.setMenuType(3);
|
|
- existingButton.setPerms(DictConstants.PERM_GROUP_LIST);
|
|
- existingButton.setApiUrl("/api/dict/group/page");
|
|
- existingButton.setStatus("enabled");
|
|
- existingButton.setVisible(true);
|
|
- sysMenuMapper.insert(existingButton);
|
|
-
|
|
- initializer.run();
|
|
-
|
|
- // 鏍戜笉閲嶅锛氶潪鎸夐挳鑺傜偣浠?2 涓紝鎸夐挳鎭板ソ 10 涓?- assertThat(sysMenuMapper.selectCount(null)).isEqualTo(12);
|
|
- List<SysMenuSeed> buttons = sysMenuMapper.selectList(null).stream()
|
|
- .filter(m -> m.getMenuType() == 3)
|
|
- .toList();
|
|
- assertThat(buttons).extracting(SysMenuSeed::getPerms).containsExactlyInAnyOrderElementsOf(PERM_CODES);
|
|
- // 宸插瓨鍦ㄦ寜閽繚鎸佸師 id 涓嶉噸寤?- assertThat(buttons.stream().filter(b -> b.getPerms().equals(DictConstants.PERM_GROUP_LIST))
|
|
- .map(SysMenuSeed::getId)).containsExactly(existingButton.getId());
|
|
- // 缁戝畾琛ラ綈
|
|
- assertThat(sysRoleMenuMapper.selectCount(null)).isEqualTo(12);
|
|
}
|
|
|
|
@Test
|
|
@@ -242,49 +92,10 @@ class DictPermissionInitializerTest {
|
|
}
|
|
}
|
|
|
|
- /*-------- 杈呭姪 --------*/
|
|
-
|
|
- private SysRoleSeed insertAdminRole() {
|
|
- SysRoleSeed admin = new SysRoleSeed();
|
|
- admin.setRoleName("绠$悊鍛?);
|
|
- admin.setRoleCode("ROLE_ADMIN");
|
|
- admin.setDataScope(4);
|
|
- admin.setSort(0);
|
|
- admin.setBuiltin(true);
|
|
- sysRoleMapper.insert(admin);
|
|
- return admin;
|
|
- }
|
|
-
|
|
- private SysMenuSeed findMenu(String name, Long parentId) {
|
|
- return sysMenuMapper.selectList(null).stream()
|
|
- .filter(m -> name.equals(m.getMenuName()) && parentId.equals(m.getParentId()))
|
|
- .findFirst().orElse(null);
|
|
- }
|
|
-
|
|
/** 浠?hasAuthority('xxx') 琛ㄨ揪寮忎腑鎻愬彇鏉冮檺鐮?*/
|
|
private static String extractPerm(String expression) {
|
|
int start = expression.indexOf('\'');
|
|
int end = expression.lastIndexOf('\'');
|
|
return expression.substring(start + 1, end);
|
|
}
|
|
-
|
|
- /*-------- 寤鸿〃 DDL锛堜笌 crm-auth 瀹炰綋缁撴瀯瀵归綈锛歴ys_menu 鍚?perms/api_url 绛夋墿灞曞垪锛?-------*/
|
|
-
|
|
- private static final String[] SCHEMA = {
|
|
- "CREATE TABLE IF NOT EXISTS sys_menu (" +
|
|
- "id BIGINT NOT NULL PRIMARY KEY, creator_id VARCHAR(50), create_time DATETIME, " +
|
|
- "updater_id VARCHAR(50), update_time DATETIME, deleted TINYINT NOT NULL DEFAULT 0, " +
|
|
- "parent_id BIGINT NOT NULL DEFAULT 0, menu_name VARCHAR(50) NOT NULL, " +
|
|
- "menu_type TINYINT NOT NULL, path VARCHAR(200), component VARCHAR(200), icon VARCHAR(50), " +
|
|
- "sort INT DEFAULT 0, visible TINYINT DEFAULT 1, description VARCHAR(100), " +
|
|
- "perms VARCHAR(100), deny_behavior VARCHAR(16), status VARCHAR(16) DEFAULT 'enabled', " +
|
|
- "api_url VARCHAR(200))",
|
|
- "CREATE TABLE IF NOT EXISTS sys_role (" +
|
|
- "id BIGINT NOT NULL PRIMARY KEY, creator_id VARCHAR(50), create_time DATETIME, " +
|
|
- "updater_id VARCHAR(50), update_time DATETIME, deleted TINYINT NOT NULL DEFAULT 0, " +
|
|
- "role_name VARCHAR(50), role_code VARCHAR(50), data_scope TINYINT, sort INT, " +
|
|
- "remark VARCHAR(200), builtin BOOLEAN DEFAULT FALSE)",
|
|
- "CREATE TABLE IF NOT EXISTS sys_role_menu (" +
|
|
- "id BIGINT NOT NULL PRIMARY KEY, role_id BIGINT NOT NULL, menu_id BIGINT NOT NULL)",
|
|
- };
|
|
}
|
|
|