Skip to content

Commit

Permalink
Merge pull request #3399 from cloudfoundry-incubator/fix-visible-spac…
Browse files Browse the repository at this point in the history
…e-roles

Fix issue where org level user lists shows space roles from other orgs
  • Loading branch information
KlapTrap authored Feb 19, 2019
2 parents 7eabb7d + bf11dc4 commit 6345314
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class CfSpacePermissionCellComponent extends CfPermissionCell<SpaceUserRo
isOrgLevel$
).pipe(
switchMap(([user, org, spaces, isOrgLevel]: [APIResource<CfUser>, APIResource<IOrganization>, APIResource<ISpace>[], boolean]) => {
const permissionList = this.createPermissions(user, isOrgLevel, spaces && spaces.length ? spaces : null);
const permissionList = this.createPermissions(user, isOrgLevel, spaces);
// If we're showing spaces from multiple orgs prefix the org name to the space name
return org ? observableOf(this.getChipConfig(permissionList)) : this.prefixOrgName(permissionList);
})
Expand Down Expand Up @@ -99,8 +99,8 @@ export class CfSpacePermissionCellComponent extends CfPermissionCell<SpaceUserRo
);
}

private createPermissions(row: APIResource<CfUser>, isOrgLevel = true, spaces?:
APIResource<ISpace>[]): ICellPermissionList<SpaceUserRoleNames>[] {
private createPermissions(row: APIResource<CfUser>, isOrgLevel = true, spaces?: APIResource<ISpace>[])
: ICellPermissionList<SpaceUserRoleNames>[] {
const userRoles = this.cfUserService.getSpaceRolesFromUser(row.entity, spaces);
return arrayHelper.flatten<ICellPermissionList<SpaceUserRoleNames>>(
userRoles.map(spacePerms => this.getSpacePermissions(spacePerms, row, isOrgLevel))
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/app/shared/data-services/cf-user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ export class CfUserService {
});
}

/**
* Get the space roles for a user
* @param user
* @param spaces Only fetch roles for these specific spaces. If missing fetch roles for all spaces
*/
getSpaceRolesFromUser(user: CfUser, spaces?: APIResource<ISpace>[]): IUserPermissionInSpace[] {
const res: IUserPermissionInSpace[] = [];
const spaceGuids = new Set<string>();
Expand Down

0 comments on commit 6345314

Please sign in to comment.