Skip to content

Commit 731683a

Browse files
committed
[DSC-2059] Fix unintentional changes
1 parent a8421de commit 731683a

7 files changed

Lines changed: 26 additions & 20 deletions

File tree

src/app/shared/context-menu/audit-item/audit-item-menu.component.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ import {
1010
import { RouterLink } from '@angular/router';
1111
import { TranslateModule } from '@ngx-translate/core';
1212
import {
13+
BehaviorSubject,
1314
combineLatest,
14-
Observable,
1515
} from 'rxjs';
16-
import {
17-
map,
18-
take,
19-
} from 'rxjs/operators';
16+
import { take } from 'rxjs/operators';
2017

2118
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
2219
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
@@ -41,7 +38,7 @@ import { ContextMenuEntryType } from '../context-menu-entry-type';
4138
})
4239
export class AuditItemMenuComponent extends ContextMenuEntryComponent implements OnInit {
4340

44-
public isAuthorized$: Observable<boolean>;
41+
public isAuthorized$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
4542

4643
constructor(
4744
@Inject('contextMenuObjectProvider') protected injectedContextMenuObject: DSpaceObject,
@@ -52,15 +49,16 @@ export class AuditItemMenuComponent extends ContextMenuEntryComponent implements
5249
}
5350

5451
ngOnInit(): void {
55-
this.isAuthorized$ = combineLatest(
52+
combineLatest(
5653
[
5754
this.authorizationService.isAuthorized(FeatureID.AdministratorOf),
5855
this.authorizationService.isAuthorized(FeatureID.IsCollectionAdmin),
5956
this.authorizationService.isAuthorized(FeatureID.IsCommunityAdmin),
6057
],
6158
).pipe(
6259
take(1),
63-
map(([isAdmin, isCollectionAdmin, isCommunityAdmin]) => isAdmin || isCollectionAdmin || isCommunityAdmin),
64-
);
60+
).subscribe(([isAdmin, isCollectionAdmin, isCommunityAdmin]) => {
61+
this.isAuthorized$.next(isAdmin || isCommunityAdmin || isCollectionAdmin);
62+
});
6563
}
6664
}

src/app/shared/context-menu/bulk-import/bulk-import-menu.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { RouterLink } from '@angular/router';
1111
import { TranslateModule } from '@ngx-translate/core';
1212
import { Observable } from 'rxjs';
13+
import { switchMap } from 'rxjs/operators';
1314

1415
import { getBulkImportRoute } from '../../../app-routing-paths';
1516
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
@@ -56,7 +57,9 @@ export class BulkImportMenuComponent extends ContextMenuEntryComponent implement
5657
super(injectedContextMenuObject, injectedContextMenuObjectType, ContextMenuEntryType.BulkImport);
5758
}
5859
ngOnInit() {
59-
this.isCollectionAdmin$ = this.isCollectionAdmin(false);
60+
this.isCollectionAdmin$ = this.notificationService.claimedProfile.pipe(
61+
switchMap(() => this.isCollectionAdmin(false)),
62+
);
6063
}
6164

6265
/**

src/app/shared/context-menu/export-collection/export-collection-menu.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
TranslateService,
1414
} from '@ngx-translate/core';
1515
import { Observable } from 'rxjs';
16+
import { switchMap } from 'rxjs/operators';
1617

1718
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
1819
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
@@ -74,7 +75,9 @@ export class ExportCollectionMenuComponent extends ContextMenuEntryComponent imp
7475
}
7576

7677
ngOnInit() {
77-
this.isCollectionAdmin$ = this.isCollectionAdmin(false);
78+
this.isCollectionAdmin$ = this.notificationService.claimedProfile.pipe(
79+
switchMap(() => this.isCollectionAdmin(false)),
80+
);
7881
}
7982

8083
/**
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<button class="btn btn-primary" *ngIf="(configuration | async)?.formats?.length > 0"
1+
<button class="btn btn-primary" *ngIf="(configuration$ | async)?.formats?.length > 0"
22
[innerHTML]="'context-menu.actions.export-item.btn' | translate"
33
(click)="$event.preventDefault();openExportModal();">
44
</button>

src/app/shared/context-menu/export-item/export-item-menu.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('ExportItemMenuComponent', () => {
9292
it('should render a button', () => {
9393
fixture.detectChanges();
9494
const testConfig = { ...configuration, formats: [{ type: null, id: '1', mimeType: '1', entityType: 'Patent', molteplicity: '1', _links: null }] };
95-
component.configuration = of(testConfig);
95+
component.configuration$.next(testConfig);
9696
fixture.detectChanges();
9797
const link = fixture.debugElement.query(By.css('button'));
9898
expect(link).not.toBeNull();

src/app/shared/context-menu/export-item/export-item-menu.component.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import {
99
} from '@angular/core';
1010
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
1111
import { TranslateModule } from '@ngx-translate/core';
12-
import {
13-
Observable,
14-
of,
15-
} from 'rxjs';
12+
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
1613
import { take } from 'rxjs/operators';
1714

1815
import { ItemExportFormatMolteplicity } from '../../../core/itemexportformat/item-export-format.service';
@@ -50,7 +47,8 @@ export class ExportItemMenuComponent extends ContextMenuEntryComponent implement
5047
/**
5148
* Type of configuration in current component
5249
*/
53-
configuration: Observable<ItemExportFormConfiguration> = of(null);
50+
configuration$: BehaviorSubject<ItemExportFormConfiguration> = new BehaviorSubject<ItemExportFormConfiguration>(null);
51+
5452
constructor(
5553
@Inject('contextMenuObjectProvider') protected injectedContextMenuObject: DSpaceObject,
5654
@Inject('contextMenuObjectTypeProvider') protected injectedContextMenuObjectType: DSpaceObjectType,
@@ -62,7 +60,8 @@ export class ExportItemMenuComponent extends ContextMenuEntryComponent implement
6260

6361
ngOnInit() {
6462
if (this.contextMenuObject) {
65-
this.configuration = this.itemExportService.initialItemExportFormConfiguration(this.contextMenuObject as Item).pipe(take(1));
63+
this.itemExportService.initialItemExportFormConfiguration(this.contextMenuObject as Item).pipe(take(1))
64+
.subscribe((config: ItemExportFormConfiguration) => this.configuration$.next(config));
6665
}
6766
}
6867

src/app/shared/context-menu/request-correction/request-correction-menu.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
import { NotificationsService } from '../../notifications/notifications.service';
4242
import { ContextMenuEntryComponent } from '../context-menu-entry.component';
4343
import { ContextMenuEntryType } from '../context-menu-entry-type';
44+
import { switchMap } from 'rxjs/internal/operators/switchMap';
4445

4546
/**
4647
* This component renders a context menu option that provides the request a correction functionality.
@@ -134,7 +135,9 @@ export class RequestCorrectionMenuComponent extends ContextMenuEntryComponent im
134135
}
135136
});
136137

137-
this.canCreateCorrection$ = this.canCreateCorrection(false);
138+
this.canCreateCorrection$ = this.notificationService.claimedProfile.pipe(
139+
switchMap(() => this.canCreateCorrection(false))
140+
);
138141
}
139142

140143
/**

0 commit comments

Comments
 (0)