fix(jd): 后管京东库权限对调——商品行写收归超管档、分类可写放开到管理人员全部可见组(2026-11-23 客户口径「删除权限只有公司管理员有;管理人员只有分类权限」)

This commit is contained in:
2026-11-23 16:32:01 +08:00
parent 7e9618e425
commit 85e6c2e663
4 changed files with 105 additions and 74 deletions
@@ -80,8 +80,8 @@ import static org.mockito.Mockito.when;
* <p><b>V203 分类按数据权限分组隔离(2026-11-16 用户口径)</b>:分类归属存
* {@code biz_jd_product_group_assign} 的 (product_id, owner_group_id) 一行,读面靠
* {@code owner_group_id} 取「当前分组」的分类(缺省=作用域默认分组),归类的写权限
* 由 {@link JdCategoryScopeService} 判「该组可写」——商品行编辑/删除走管理员级写闸
* (2026-11-17 用户口径「超管+管理员都可以,只有普通员工不能」)。
* 由 {@link JdCategoryScopeService} 判「该组可写」——商品行编辑/删除走超管级写闸
* (2026-11-23 客户口径「删除权限只有公司管理员有;管理人员只有分类权限」)。
* 本类把作用域服务整体 mock 掉(四档角色矩阵在 {@code JdCategoryScopeServiceTest} 里钉),
* 只钉控制器怎么用它、以及拒绝语义不被吞。</p>
*/
@@ -260,26 +260,27 @@ class AdminJdProductControllerTest {
"名单读端点必须过可见组闸(canRead,同组普通号能看名单)");
}
// ===================== 写权限分档(2026-11-17:超管级+管理员可写,普通账号只读) =====================
// ===================== 写权限分档(2026-11-23:仅超管级可写商品,admin 只有分类权限) =====================
/** 写端点越权闸的结构判据:商品行四条写路由走管理员级写闸,读三条走菜单正门。 */
/** 写端点越权闸的结构判据:商品行四条写路由走超管级写闸,读三条走菜单正门。 */
@Test
void 商品页读写权限分档_商品行写端点逐条走管理员级写闸() throws IOException {
void 商品页读写权限分档_商品行写端点逐条走超管级写闸() throws IOException {
String source = stripComments(Files.readString(CONTROLLER));
assertEquals(4, count(source, "requireJdProductWrite(request)"),
"编辑/上传图片/单行删除/批量删除四条商品行写路由必须逐条走管理员级写闸"
+ "(归类不在此列:V203 起归本组管理员可做)");
"编辑/上传图片/单行删除/批量删除四条商品行写路由必须逐条走超管级写闸"
+ "(归类不在此列:2026-11-23 起归可见组管理员可做,走 requireWritableGroup)");
assertEquals(6, count(source, "requireJdAccess(request)"),
"列表/类目/详情/归类四条读+组内写路由与导出,加写闸内部一处,共六处菜单权限正门"
+ "(v1.7 导出走读闸:导出属读行为,不走商品行写闸)");
assertTrue(source.contains("仅超级管理员或管理员可以编辑或删除京东数据库数据"),
"普通账号写商品的 403 文案必须点名超管与管理员(2026-11-17 口径)");
assertTrue(source.contains("仅超级管理员或公司超级管理员可以编辑或删除京东数据库数据"),
"被拒账号写商品的 403 文案必须点名两档超管(2026-11-23 客户口径「删除权限只有公司管理员有」)");
assertTrue(source.contains("operator.superAdmin()"),
"写闸必须在菜单口径之上再判 superAdmin(平台超管直放)");
assertTrue(source.contains("DeviceSessionPolicy.isCompanySuperAdmin(role)"),
"写闸必须放行公司超级管理员(超管档,2026-11-17 口径「只有普通员工不能」)");
assertTrue(source.contains("\"admin\".equals(role)"),
"写闸必须放行 admin 角色(管理员档,2026-11-17 口径「超管+管理员都可以」)");
"写闸必须放行公司超级管理员(超管档)");
assertFalse(source.contains("\"admin\".equals(role)"),
"写闸不得再放行 admin 角色(2026-11-23 客户口径:管理人员只有分类权限、没有商品行写;"
+ "改回去即「弄反了」复发)");
}
@Test
@@ -325,21 +326,21 @@ class AdminJdProductControllerTest {
updateBody.setTitle("标题");
BusinessException updateEx = assertThrows(BusinessException.class,
() -> controller.update(11L, updateBody, request));
assertTrue(updateEx.getMessage().contains("仅超级管理员或管理员"), "编辑被拒文案点名超管与管理员");
assertTrue(updateEx.getMessage().contains("仅超级管理员或公司超级管理员"), "编辑被拒文案点名两档超管");
BusinessException deleteEx = assertThrows(BusinessException.class,
() -> controller.delete(11L, request));
assertTrue(deleteEx.getMessage().contains("仅超级管理员或管理员"));
assertTrue(deleteEx.getMessage().contains("仅超级管理员或公司超级管理员"));
JdProductBatchDeleteRequest batchBody = new JdProductBatchDeleteRequest();
batchBody.setIds(List.of(11L, 12L));
BusinessException batchEx = assertThrows(BusinessException.class,
() -> controller.batchDelete(batchBody, request));
assertTrue(batchEx.getMessage().contains("仅超级管理员或管理员"));
assertTrue(batchEx.getMessage().contains("仅超级管理员或公司超级管理员"));
BusinessException uploadEx = assertThrows(BusinessException.class,
() -> controller.uploadImage(11L, mock(MultipartFile.class), "MAIN", null, null, request));
assertTrue(uploadEx.getMessage().contains("仅超级管理员或管理员"),
assertTrue(uploadEx.getMessage().contains("仅超级管理员或公司超级管理员"),
"上传/替换图片改桶内对象=写动作,必须同闸");
verify(updateService, never()).update(any(), any());
@@ -348,9 +349,12 @@ class AdminJdProductControllerTest {
verify(deleteService, never()).delete(any());
}
/** 2026-11-17 口径「超管+管理员都可以」:admin 档四条写入口全放行、公司超管(超管档)同闸放行。 */
/**
* 2026-11-23 客户口径「删除权限只有公司管理员有;管理人员只有分类权限」:
* admin 档四条商品行写入口一律 403 且不触服务,公司超管(超管档)同闸放行。
*/
@Test
void 管理员与公司超管有菜单权限即可写商品_写入口放行且触服务() {
void 管理人员写商品一律403_公司超管写入口放行且触服务() {
JdProductQueryService queryService = mock(JdProductQueryService.class);
JdProductDeleteService deleteService = mock(JdProductDeleteService.class);
JdProductUpdateService updateService = mock(JdProductUpdateService.class);
@@ -364,7 +368,7 @@ class AdminJdProductControllerTest {
operator.setId(9L);
HttpServletRequest request = mock(HttpServletRequest.class);
when(authSupport.requireUser(request)).thenReturn(operator);
// 管理员(admin 档,非任何超管):菜单权限命中后商品行写全放行。
// 管理人员(admin 档,非任何超管):菜单权限命中只给读;商品行写四条入口全拒。
when(authSupport.currentRole(operator)).thenReturn("admin");
PermissionMenuItemVo grant = new PermissionMenuItemVo();
grant.setColumnKey(COLUMN_KEY);
@@ -373,32 +377,32 @@ class AdminJdProductControllerTest {
JdProductUpdateRequest updateBody = new JdProductUpdateRequest();
updateBody.setTitle("标题");
JdProductDetailVo detailVo = new JdProductDetailVo();
detailVo.setId(11L);
when(updateService.update(11L, updateBody)).thenReturn(11L);
when(queryService.detail(11L, null)).thenReturn(detailVo);
assertEquals(Boolean.TRUE, controller.update(11L, updateBody, request).isSuccess(),
"admin 档编辑放行必须是 success 信封(B80-03)");
verify(updateService).update(11L, updateBody);
BusinessException updateEx = assertThrows(BusinessException.class,
() -> controller.update(11L, updateBody, request));
assertTrue(updateEx.getMessage().contains("仅超级管理员或公司超级管理员"),
"admin 档编辑被拒——2026-11-17「超管+管理员都可以」已被客户判为弄反,不得回潜");
when(updateService.uploadImage(11L, null, "MAIN", null, null)).thenReturn(11L);
assertEquals(Boolean.TRUE,
controller.uploadImage(11L, null, "MAIN", null, null, request).isSuccess(),
"admin 档上传图片同闸放行");
verify(updateService).uploadImage(11L, null, "MAIN", null, null);
BusinessException uploadEx = assertThrows(BusinessException.class,
() -> controller.uploadImage(11L, null, "MAIN", null, null, request));
assertTrue(uploadEx.getMessage().contains("仅超级管理员或公司超级管理员"));
BusinessException deleteEx = assertThrows(BusinessException.class,
() -> controller.delete(11L, request));
assertTrue(deleteEx.getMessage().contains("仅超级管理员或公司超级管理员"));
JdProductDeleteVo receipt = new JdProductDeleteVo();
receipt.setDeleted(1);
when(deleteService.delete(List.of(11L))).thenReturn(receipt);
assertEquals(Boolean.TRUE, controller.delete(11L, request).isSuccess(), "admin 档单行删除放行");
JdProductBatchDeleteRequest batchBody = new JdProductBatchDeleteRequest();
batchBody.setIds(List.of(11L, 12L));
when(deleteService.delete(List.of(11L, 12L))).thenReturn(receipt);
assertEquals(Boolean.TRUE, controller.batchDelete(batchBody, request).isSuccess(), "admin 档批量删除放行");
verify(deleteService).delete(List.of(11L));
verify(deleteService).delete(List.of(11L, 12L));
BusinessException batchEx = assertThrows(BusinessException.class,
() -> controller.batchDelete(batchBody, request));
assertTrue(batchEx.getMessage().contains("仅超级管理员或公司超级管理员"));
verify(updateService, never()).update(any(), any());
verify(updateService, never()).uploadImage(any(), any(), any(), any(), any());
verify(deleteService, never()).delete(any());
// 公司超管=超管档:同一道闸放行(单条删除代表性钉住,防「只放平台超管」回潜)。
JdProductDeleteVo receipt = new JdProductDeleteVo();
receipt.setDeleted(1);
AdminUserEntity companySuper = new AdminUserEntity();
companySuper.setId(8L);
HttpServletRequest companyRequest = mock(HttpServletRequest.class);
@@ -407,7 +411,7 @@ class AdminJdProductControllerTest {
when(permissionMenuService.getUserColumnPermissions(8L, "admin")).thenReturn(List.of(grant));
when(deleteService.delete(List.of(21L))).thenReturn(receipt);
assertEquals(Boolean.TRUE, controller.delete(21L, companyRequest).isSuccess(),
"公司超级管理员属超管档,商品行写同闸放行(2026-11-17 口径)");
"公司超级管理员属超管档,商品行写同闸放行(2026-11-23 口径「删除权限只有公司管理员有」)");
verify(deleteService).delete(List.of(21L));
}
@@ -30,7 +30,7 @@ import static org.mockito.Mockito.when;
*
* <p>四档矩阵(2026-11-17 起各档可见集最后统一过「只留京东档 platform='jd' 分组」的平台闸):
* 平台超管=全部公司全部组可读可写;公司超管=本公司全部组;
* 管理员(组长)=自己带的组可写、自己所属组的组长带的分组只读;
* 管理员=全部可见组可写(2026-11-23 客户口径「管理人员只有分类权限」,不再要求组长身份);
* 普通号=与管理员同可见、<b>零可写</b>(能开弹窗看,不能增删改分类、不能归类)。
* 另钉三条收敛语义:不可见组读 403(不做空结果降级)、无分组上下文读回 null(页面照常可用)、
* 写侧在「无可写组 / 多可写组未选 / 该组不可写 / 组行不存在」四种形状下的文案。
@@ -161,8 +161,13 @@ class JdCategoryScopeServiceTest {
verify(adminUserMapper, never()).selectBatchIds(any());
}
/**
* 2026-11-23 客户口径「管理人员只有分类权限」:admin 档对全部<b>可见</b> jd 分组可写,
* 不再要求组长身份(旧口径「仅自己带的组可写、上司组只读」已被判为弄反——客户侧
* 管理人员普遍不是组长,拿不到分类入口)。可见性边界不变:不可见组仍双拒。
*/
@Test
void 组长_自己带的组可写_自己所属组的组长带的分组只读() {
void 管理人员_全部可见组可写_含非组长身份所属组的组() {
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
when(adminAuthSupport.currentRole(operator)).thenReturn("admin");
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(false);
@@ -173,9 +178,30 @@ class JdCategoryScopeServiceTest {
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
assertThat(scope.visibleGroupIds()).containsExactly(10L, 11L);
assertThat(scope.writableGroupIds()).containsExactly(10L);
assertThat(scope.writableGroupIds()).containsExactly(10L, 11L);
assertThat(scope.canRead(11L)).isTrue();
assertThat(scope.canWrite(11L)).isFalse();
assertThat(scope.canWrite(11L)).isTrue();
// 不可见组仍双拒:可写放开只到可见集为止,V203 分组隔离不松。
assertThat(scope.canRead(99L)).isFalse();
assertThat(scope.canWrite(99L)).isFalse();
}
/** 非组长的普通管理人员(只靠成员关系可见组)同样拿到分类可写——客户账号 阿华226655 的形状。 */
@Test
void 管理人员非组长_成员关系可见的组也可写分类() {
AdminUserEntity operator = user(USER_ID, COMPANY_ID);
when(adminAuthSupport.currentRole(operator)).thenReturn("admin");
when(dataReadScope.isPlatformSuperAdmin(operator)).thenReturn(false);
when(shopManageGroupMapper.selectLedGroups(USER_ID)).thenReturn(List.of());
when(shopManageGroupMapper.selectLeaderIdsByMemberUserId(USER_ID)).thenReturn(List.of(3L));
when(shopManageGroupMapper.selectLedGroups(3L)).thenReturn(List.of(group(11L, COMPANY_ID, "上司的组")));
JdCategoryScopeService.JdCategoryScope scope = service.resolve(operator);
assertThat(scope.visibleGroupIds()).containsExactly(11L);
assertThat(scope.writableGroupIds()).containsExactly(11L);
assertThat(scope.groups()).singleElement()
.satisfies(option -> assertThat(option.isEditable()).isTrue());
}
@Test