fix(多公司): 公司目录读端点摘掉菜单闸门,别再把它当数据可见性用
GET /api/admin/companies 同时是「用户管理」页公司下拉的数据源,而它第一行查的是 admin_companies 菜单权限 —— V143 只插了 columns 那一行、一笔 user_column_permission 都没发,于是 15 个公司内管理员一打开用户管理页就吃 403。收窄本来已由 role + companyId 完成,本公司管理员能读到的那一行就是登录响应和 /current-user 里本来就回带的自己的公司名, 这道闸门一个字节都没多守住,却把整个页面挡住了。 写入口(create/update)继续走 ensureSuperAdmin 不变;MENU_KEY 与 PermissionMenuService 依赖随闸门一起删净,护栏 CompanyReadPathMenuGateTest 用源码扫描钉住"公司服务不查菜单", 并自检取样集非空(闸门在用户管理、生成记录两处仍是正当手段,必须扫得到)。
This commit is contained in:
+6
-13
@@ -7,7 +7,6 @@ import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.company.mapper.CompanyMapper;
|
||||
import com.nanri.aiimage.modules.company.model.dto.CompanySaveRequest;
|
||||
import com.nanri.aiimage.modules.company.model.entity.CompanyEntity;
|
||||
import com.nanri.aiimage.modules.permission.service.PermissionMenuService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -26,16 +25,12 @@ public class CompanyService {
|
||||
public static final int STATUS_ACTIVE = 1;
|
||||
public static final int STATUS_DISABLED = 0;
|
||||
|
||||
/** 后台「公司管理」菜单的 column_key(V143 插入 columns 表那一行的值)。 */
|
||||
public static final String MENU_KEY = "admin_companies";
|
||||
|
||||
/** 列宽取自 V143:company_name varchar(128)、remark varchar(255)。超长先进校验,别让 MySQL 报 1406 变 500。 */
|
||||
private static final int NAME_MAX_LENGTH = 128;
|
||||
private static final int REMARK_MAX_LENGTH = 255;
|
||||
|
||||
private final CompanyMapper companyMapper;
|
||||
private final AdminAuthSupport adminAuthSupport;
|
||||
private final PermissionMenuService permissionMenuService;
|
||||
|
||||
/** 建号指定的公司必须真实存在且启用:否则账号挂在查不到的公司上,按公司筛选时整体失明。 */
|
||||
public CompanyEntity requireActive(Long companyId) {
|
||||
@@ -54,9 +49,13 @@ public class CompanyService {
|
||||
*
|
||||
* <p>读口径必须和写口径一起收窄——只把写拦成超管、列表仍返回全部公司,等于把别家公司的
|
||||
* 名字泄露给本公司管理员。管理员没有公司归属时是拒绝,不是"那就不过滤"。</p>
|
||||
*
|
||||
* <p>这里<b>不查菜单权限</b>:{@code admin_companies} 那道闸门管的是「公司管理」这个页面
|
||||
* 出不出现在侧边栏,而本方法同时是「用户管理」页公司下拉的数据源,两者不是一回事。
|
||||
* 收窄靠 role + companyId 已经到位,本公司管理员能读到的那一行就是他在登录响应和
|
||||
* /current-user 里本来就拿着的那个自己的公司名,菜单闸门在这里多守不住一个字节。</p>
|
||||
*/
|
||||
public List<CompanyEntity> listVisible(AdminUserEntity operator) {
|
||||
ensureCompanyMenu(operator);
|
||||
String role = adminAuthSupport.currentRole(operator);
|
||||
if (role == null) {
|
||||
throw new BusinessException(403, "需要管理员权限");
|
||||
@@ -78,7 +77,7 @@ public class CompanyService {
|
||||
*
|
||||
* <p><b>这个方法不做权限判断</b>:它只是把调用方已经拿在手里的那些 id 换成名字,
|
||||
* 谁能看到哪些行由调用方的查询范围决定(同 {@code AdminUserService.loadCreatorMap} 的口径)。
|
||||
* 要给前端列公司目录请走 {@link #listVisible},它才带收窄与菜单闸门。</p>
|
||||
* 要给前端列公司目录请走 {@link #listVisible},它才按角色和公司收窄。</p>
|
||||
*/
|
||||
public Map<Long, String> namesByIds(Collection<Long> companyIds) {
|
||||
if (companyIds == null || companyIds.isEmpty()) {
|
||||
@@ -196,12 +195,6 @@ public class CompanyService {
|
||||
return remark;
|
||||
}
|
||||
|
||||
private void ensureCompanyMenu(AdminUserEntity operator) {
|
||||
if (!permissionMenuService.hasAnyAdminMenu(operator, List.of(MENU_KEY))) {
|
||||
throw new BusinessException(403, "无权访问公司管理模块");
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureSuperAdmin(AdminUserEntity operator) {
|
||||
if (!"super_admin".equals(adminAuthSupport.currentRole(operator))) {
|
||||
throw new BusinessException(403, "只有超级管理员可以新增或修改公司");
|
||||
|
||||
Reference in New Issue
Block a user