Skip to content

Commit 8c79bd9

Browse files
author
Naman Munet
committed
mgr/dashboard: rgw users link user with account e2e failure
Fixes: https://tracker.ceph.com/issues/73835 Changes Include: Previously, users were initialized without their associated account data, causing issues in table display and row expansion. This change ensures that users are initialized only after fetching accounts and mapping them to each user. If the account API fails, users are still initialized with a default empty account to prevent errors. Signed-off-by: Naman Munet <[email protected]>
1 parent fb29ffe commit 8c79bd9

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ import { TableActionsComponent } from '~/app/shared/datatable/table-actions/tabl
1111
import { SharedModule } from '~/app/shared/shared.module';
1212
import { configureTestBed, PermissionHelper } from '~/testing/unit-test-helper';
1313
import { RgwUserListComponent } from './rgw-user-list.component';
14+
import { RgwUserAccountsService } from '~/app/shared/api/rgw-user-accounts.service';
1415

1516
describe('RgwUserListComponent', () => {
1617
let component: RgwUserListComponent;
1718
let fixture: ComponentFixture<RgwUserListComponent>;
1819
let rgwUserService: RgwUserService;
1920
let rgwUserServiceListSpy: jasmine.Spy;
21+
let rgwUserAccountService: RgwUserAccountsService;
22+
let rgwUserAccountServiceListSpy: jasmine.Spy;
2023

2124
configureTestBed({
2225
declarations: [RgwUserListComponent],
@@ -26,8 +29,11 @@ describe('RgwUserListComponent', () => {
2629

2730
beforeEach(() => {
2831
rgwUserService = TestBed.inject(RgwUserService);
32+
rgwUserAccountService = TestBed.inject(RgwUserAccountsService);
2933
rgwUserServiceListSpy = spyOn(rgwUserService, 'list');
34+
rgwUserAccountServiceListSpy = spyOn(rgwUserAccountService, 'list');
3035
rgwUserServiceListSpy.and.returnValue(of([]));
36+
rgwUserAccountServiceListSpy.and.returnValue(of([]));
3137
fixture = TestBed.createComponent(RgwUserListComponent);
3238
component = fixture.componentInstance;
3339
spyOn(component, 'setTableRefreshTimeout').and.stub();
@@ -142,6 +148,7 @@ describe('RgwUserListComponent', () => {
142148
expect(rgwUserServiceListSpy).toHaveBeenCalledTimes(2);
143149
expect(component.users).toEqual([
144150
{
151+
account: { name: '' },
145152
user_id: 'testid',
146153
stats: {
147154
size_actual: 6,

src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, NgZone, OnInit, TemplateRef, ViewChild } from '@angular/core';
22

3-
import { forkJoin as observableForkJoin, Observable, Subscriber, Subject } from 'rxjs';
3+
import { forkJoin as observableForkJoin, Observable, Subscriber, Subject, of } from 'rxjs';
44
import { RgwUserAccountsService } from '~/app/shared/api/rgw-user-accounts.service';
55

66
import { RgwUserService } from '~/app/shared/api/rgw-user.service';
@@ -20,7 +20,7 @@ import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
2020
import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
2121
import { URLBuilderService } from '~/app/shared/services/url-builder.service';
2222
import { Account } from '../models/rgw-user-accounts';
23-
import { switchMap } from 'rxjs/operators';
23+
import { catchError, map, switchMap } from 'rxjs/operators';
2424
import { RgwUser } from '../models/rgw-user';
2525

2626
const BASE_URL = 'rgw/user';
@@ -43,7 +43,7 @@ export class RgwUserListComponent extends ListWithDetails implements OnInit {
4343
permission: Permission;
4444
tableActions: CdTableAction[];
4545
columns: CdTableColumn[] = [];
46-
users: object[] = [];
46+
users: RgwUser[] = [];
4747
userAccounts: Account[];
4848
selection: CdTableSelection = new CdTableSelection();
4949
userDataSubject = new Subject();
@@ -121,15 +121,19 @@ export class RgwUserListComponent extends ListWithDetails implements OnInit {
121121
flexGrow: 0.8
122122
}
123123
];
124+
124125
this.userDataSubject
125126
.pipe(
126-
switchMap((_: object[]) => {
127-
return this.rgwUserAccountService.list(true);
128-
})
127+
switchMap((users: RgwUser[]) =>
128+
this.rgwUserAccountService.list(true).pipe(
129+
map((accounts: Account[]) => ({ users, accounts })),
130+
catchError(() => of({ users, accounts: [] }))
131+
)
132+
)
129133
)
130-
.subscribe((accounts: Account[]) => {
134+
.subscribe(({ users, accounts }) => {
131135
this.userAccounts = accounts;
132-
this.mapUsersWithAccount();
136+
this.users = this.mapUsersWithAccount(users);
133137
});
134138

135139
const getUserUri = () =>
@@ -161,8 +165,7 @@ export class RgwUserListComponent extends ListWithDetails implements OnInit {
161165
getUserList(context: CdTableFetchDataContext) {
162166
this.setTableRefreshTimeout();
163167
this.rgwUserService.list().subscribe(
164-
(resp: object[]) => {
165-
this.users = resp;
168+
(resp: RgwUser[]) => {
166169
this.userDataSubject.next(resp);
167170
},
168171
() => {
@@ -171,9 +174,9 @@ export class RgwUserListComponent extends ListWithDetails implements OnInit {
171174
);
172175
}
173176

174-
mapUsersWithAccount() {
175-
this.users = this.users.map((user: RgwUser) => {
176-
const account: Account = this.userAccounts.find((acc) => acc.id === user.account_id);
177+
mapUsersWithAccount(users: RgwUser[]): RgwUser[] {
178+
return users.map((user: RgwUser) => {
179+
const account: Account = this.userAccounts.find((acc: Account) => acc.id === user.account_id);
177180
return {
178181
account: account ? account : { name: '' }, // adding {name: ''} for sorting account name in user list to work
179182
...user

0 commit comments

Comments
 (0)