Skip to content

Commit

Permalink
Prevent null role while getting permissions (#6612)
Browse files Browse the repository at this point in the history
#### 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 #6604

#### Does this PR introduce a user-facing change?

```release-note
修复取消用户角色后无法正常渲染用户列表的问题
```
  • Loading branch information
JohnNiang authored Sep 6, 2024
1 parent cf2837d commit 93ffb7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,11 @@ private Mono<ListResult<ListedUser>> toListedUser(ListResult<User> listResult) {
.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);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public Mono<User> grantRoles(String username, Set<String> roles) {
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(() -> {
Expand Down

0 comments on commit 93ffb7d

Please sign in to comment.