mirror of https://github.com/halo-dev/halo
Prevent null role while getting permissions (#6612)
#### What type of PR is this? /kind bug /area core /milestone 2.20.x #### What this PR does / why we need it: This PR filters blank role name while granting roles for an user to prevent null role in permissions. #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/6604 #### Does this PR introduce a user-facing change? ```release-note 修复取消用户角色后无法正常渲染用户列表的问题 ```pull/6622/head
parent
cf2837d744
commit
93ffb7d8ea
|
@ -771,7 +771,11 @@ public class UserEndpoint implements CustomEndpoint {
|
|||
.map(user -> {
|
||||
var username = user.getMetadata().getName();
|
||||
var roles = Optional.ofNullable(usernameRolesMap.get(username))
|
||||
.map(roleNames -> roleNames.stream().map(roleMap::get).toList())
|
||||
.map(roleNames -> roleNames.stream()
|
||||
.map(roleMap::get)
|
||||
.filter(Objects::nonNull)
|
||||
.toList()
|
||||
)
|
||||
.orElseGet(List::of);
|
||||
return new ListedUser(user, roles);
|
||||
})
|
||||
|
|
|
@ -133,6 +133,7 @@ public class UserServiceImpl implements UserService {
|
|||
var mutableRoles = new HashSet<>(roles);
|
||||
mutableRoles.removeAll(existingRoles);
|
||||
return mutableRoles.stream()
|
||||
.filter(StringUtils::hasText)
|
||||
.map(roleName -> RoleBinding.create(username, roleName));
|
||||
}).flatMap(client::create))
|
||||
.then(Mono.defer(() -> {
|
||||
|
|
Loading…
Reference in New Issue