功能:补齐权限分配前端提示与禁选
This commit is contained in:
+11
@@ -87,6 +87,17 @@ public class AdminPermissionController {
|
||||
return Result.success(permissionVOs);
|
||||
}
|
||||
|
||||
@GetMapping("/assignable/{userId}")
|
||||
@RequirePermission("permission:assign")
|
||||
public Result<List<Long>> listAssignablePermissionIds(HttpServletRequest request, @PathVariable Long userId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, userId, "无权给其他店铺用户分配权限");
|
||||
}
|
||||
Long currentUserId = (Long) request.getAttribute("userId");
|
||||
return Result.success(permissionService.listAssignablePermissionIds(userId, currentUserId));
|
||||
}
|
||||
|
||||
@GetMapping("/user/current")
|
||||
public Result<List<PermissionVO>> getCurrentUserPermissions(HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
|
||||
@@ -73,6 +73,15 @@ public interface PermissionService extends IService<PermissionDO> {
|
||||
*/
|
||||
List<PermissionVO> listUserPermissions(Long userId);
|
||||
|
||||
/**
|
||||
* 查询当前操作人可给目标用户分配的权限ID列表
|
||||
*
|
||||
* @param targetUserId 目标用户ID
|
||||
* @param currentUserId 当前操作人ID
|
||||
* @return 可分配的权限ID列表
|
||||
*/
|
||||
List<Long> listAssignablePermissionIds(Long targetUserId, Long currentUserId);
|
||||
|
||||
/**
|
||||
* 给用户分配权限
|
||||
*
|
||||
|
||||
+50
@@ -152,6 +152,56 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
|
||||
return permissionVOs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> listAssignablePermissionIds(Long targetUserId, Long currentUserId) {
|
||||
UserDO currentUser = userMapper.selectById(currentUserId);
|
||||
if (currentUser == null || Integer.valueOf(1).equals(currentUser.getIsDelete())) {
|
||||
throw new RuntimeException("当前用户不存在");
|
||||
}
|
||||
|
||||
UserDO targetUser = userMapper.selectById(targetUserId);
|
||||
if (targetUser == null || Integer.valueOf(1).equals(targetUser.getIsDelete())) {
|
||||
throw new RuntimeException("目标用户不存在");
|
||||
}
|
||||
|
||||
if (!hasPermission(currentUserId, "permission:assign")) {
|
||||
throw new RuntimeException("权限不足,无法分配权限");
|
||||
}
|
||||
|
||||
boolean platformAdmin = Integer.valueOf(4).equals(currentUser.getType());
|
||||
Long currentShopId = RequestShopContext.getCurrentShopId();
|
||||
if (!PermissionPolicy.canManageUserType(currentUser.getType(), targetUser.getType())) {
|
||||
throw new RuntimeException("当前角色不能维护该用户的权限");
|
||||
}
|
||||
|
||||
if (!platformAdmin) {
|
||||
if (currentUserId.equals(targetUserId)) {
|
||||
throw new RuntimeException("不允许给自己调整权限");
|
||||
}
|
||||
if (currentShopId == null || !userShopBindingSupport.isUserAccessibleInShop(targetUserId, currentShopId)) {
|
||||
throw new RuntimeException("只能给本店铺用户分配权限");
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> baseAllowedPermissionCodes = PermissionPolicy.getDefaultPermissionCodeSet(targetUser.getType());
|
||||
Set<String> operatorPermissionCodes = platformAdmin
|
||||
? Collections.emptySet()
|
||||
: listPermissionCodesByUserId(currentUserId);
|
||||
Set<String> assignablePermissionCodes = platformAdmin
|
||||
? baseAllowedPermissionCodes
|
||||
: baseAllowedPermissionCodes.stream()
|
||||
.filter(operatorPermissionCodes::contains)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
return permissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(PermissionDO.class)
|
||||
.eq(PermissionDO::getIsDelete, 0)
|
||||
).stream()
|
||||
.filter(permission -> assignablePermissionCodes.contains(permission.getPermissionCode()))
|
||||
.map(PermissionDO::getId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean assignPermissions(UserPermissionDTO userPermissionDTO, Long currentUserId) {
|
||||
|
||||
Reference in New Issue
Block a user