Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix RoleBinding with multiple subjects
- Loading branch information
Showing
7 changed files
with
104 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
...es/dev-console/src/components/project-access/__tests__/project-access-form-utils.spec.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 18 additions & 15 deletions
33
frontend/packages/dev-console/src/components/project-access/project-access-form-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
import * as _ from 'lodash'; | ||
import { UserRoleBinding, UserRole } from './project-access-form-utils-types'; | ||
import { UserRoleBinding, RoleBinding } from './project-access-form-utils-types'; | ||
|
||
export const filterRoleBindings = (roleBindings, roles) => { | ||
return _.filter(roleBindings.data, (user: UserRole) => _.keys(roles).includes(user.roleRef.name)); | ||
export const filterRoleBindings = (roleBindings: RoleBinding[], roles) => { | ||
return _.filter(roleBindings, (user: RoleBinding) => _.keys(roles).includes(user.roleRef.name)); | ||
}; | ||
|
||
export const getUserRoleBindings = (roleBindings) => { | ||
export const getUsersFromSubject = (user: RoleBinding) => { | ||
const users: UserRoleBinding[] = user.subjects?.reduce((acc, obj) => { | ||
acc.push({ | ||
roleBindingName: user.metadata.name, | ||
user: obj.name, | ||
role: user.roleRef.name, | ||
}); | ||
return acc; | ||
}, []); | ||
|
||
return users; | ||
}; | ||
|
||
export const getUserRoleBindings = (roleBindings: RoleBinding[]) => { | ||
let userRoleBindings: UserRoleBinding[] = []; | ||
roleBindings.map( | ||
(user: UserRole) => | ||
(userRoleBindings = [ | ||
...userRoleBindings, | ||
...[ | ||
{ | ||
roleBindingName: user.metadata.name, | ||
user: user.subjects[0].name, | ||
role: user.roleRef.name, | ||
}, | ||
], | ||
]), | ||
(user: RoleBinding) => (userRoleBindings = [...userRoleBindings, ...getUsersFromSubject(user)]), | ||
); | ||
return userRoleBindings; | ||
}; |