refactor, adapt breadcrumbs for non admin users, fix translations

This commit is contained in:
FrancescoMolinaro
2024-01-26 11:47:18 +01:00
parent 80174817fd
commit dfaaf298b1
8 changed files with 30 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ import { Breadcrumb } from '../../breadcrumbs/breadcrumb/breadcrumb.model';
import { getTestScheduler } from 'jasmine-marbles'; import { getTestScheduler } from 'jasmine-marbles';
import { PublicationClaimBreadcrumbService } from './publication-claim-breadcrumb.service'; import { PublicationClaimBreadcrumbService } from './publication-claim-breadcrumb.service';
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils'; import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
import { of } from 'rxjs';
describe('PublicationClaimBreadcrumbService', () => { describe('PublicationClaimBreadcrumbService', () => {
let service: PublicationClaimBreadcrumbService; let service: PublicationClaimBreadcrumbService;
@@ -17,6 +18,10 @@ describe('PublicationClaimBreadcrumbService', () => {
findById: (str) => createSuccessfulRemoteDataObject$(str), findById: (str) => createSuccessfulRemoteDataObject$(str),
}; };
let authorizationService: any = {
isAuthorized: (str) => of(true),
};
let exampleKey; let exampleKey;
const ADMIN_PUBLICATION_CLAIMS_PATH = 'admin/notifications/publication-claim'; const ADMIN_PUBLICATION_CLAIMS_PATH = 'admin/notifications/publication-claim';
@@ -32,7 +37,7 @@ describe('PublicationClaimBreadcrumbService', () => {
})); }));
beforeEach(() => { beforeEach(() => {
service = new PublicationClaimBreadcrumbService(dataService,dsoNameService,translateService); service = new PublicationClaimBreadcrumbService(dataService,dsoNameService,translateService, authorizationService);
}); });
describe('getBreadcrumbs', () => { describe('getBreadcrumbs', () => {

View File

@@ -1,12 +1,14 @@
import { Breadcrumb } from '../../breadcrumbs/breadcrumb/breadcrumb.model'; import { Breadcrumb } from '../../breadcrumbs/breadcrumb/breadcrumb.model';
import { BreadcrumbsProviderService } from './breadcrumbsProviderService'; import { BreadcrumbsProviderService } from './breadcrumbsProviderService';
import { Observable } from 'rxjs'; import { combineLatest, Observable } from 'rxjs';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { ItemDataService } from '../data/item-data.service'; import { ItemDataService } from '../data/item-data.service';
import { getFirstCompletedRemoteData } from '../shared/operators'; import { getFirstCompletedRemoteData } from '../shared/operators';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { DSONameService } from './dso-name.service'; import { DSONameService } from './dso-name.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service';
import { FeatureID } from '../data/feature-authorization/feature-id';
@@ -22,7 +24,8 @@ export class PublicationClaimBreadcrumbService implements BreadcrumbsProviderSer
constructor(private dataService: ItemDataService, constructor(private dataService: ItemDataService,
private dsoNameService: DSONameService, private dsoNameService: DSONameService,
private tranlsateService: TranslateService) { private tranlsateService: TranslateService,
protected authorizationService: AuthorizationDataService) {
} }
@@ -31,11 +34,11 @@ export class PublicationClaimBreadcrumbService implements BreadcrumbsProviderSer
* @param key The key used to resolve the breadcrumb * @param key The key used to resolve the breadcrumb
*/ */
getBreadcrumbs(key: string): Observable<Breadcrumb[]> { getBreadcrumbs(key: string): Observable<Breadcrumb[]> {
return this.dataService.findById(key).pipe( return combineLatest([this.dataService.findById(key).pipe(getFirstCompletedRemoteData()),this.authorizationService.isAuthorized(FeatureID.AdministratorOf)]).pipe(
getFirstCompletedRemoteData(), map(([item, isAdmin]) => {
map((item) => { const itemName = this.dsoNameService.getName(item.payload);
return [new Breadcrumb(this.tranlsateService.instant(this.ADMIN_PUBLICATION_CLAIMS_BREADCRUMB_KEY), this.ADMIN_PUBLICATION_CLAIMS_PATH), return isAdmin ? [new Breadcrumb(this.tranlsateService.instant(this.ADMIN_PUBLICATION_CLAIMS_BREADCRUMB_KEY), this.ADMIN_PUBLICATION_CLAIMS_PATH),
new Breadcrumb(this.dsoNameService.getName(item.payload), undefined)]; new Breadcrumb(itemName, undefined)] : [new Breadcrumb(itemName, undefined)];
}) })
); );
} }

View File

@@ -75,7 +75,8 @@ export class SuggestionTargetsEffects {
}), }),
catchError((errors) => of(errors)) catchError((errors) => of(errors))
); );
})), { dispatch: false }); }))
);
/** /**
* Initialize the effect class variables. * Initialize the effect class variables.

View File

@@ -1,7 +1,7 @@
<ng-container *ngIf="(suggestionsRD$ | async) as suggestions"> <ng-container *ngIf="(suggestionsRD$ | async) as suggestions">
<ng-container *ngFor="let suggestion of suggestions" class="alert alert-info"> <ng-container *ngFor="let suggestion of suggestions" class="alert alert-info">
<div class="alert alert-success d-block" *ngIf="suggestion.total > 0"> <div class="alert alert-success d-block" *ngIf="suggestion.total > 0">
<div [innerHTML]="'mydspace.notification.suggestion.page' | translate: getNotificationSuggestionInterpolation(suggestion)"> <div [innerHTML]="'notification.suggestion.page' | translate: getNotificationSuggestionInterpolation(suggestion)">
</div> </div>
</div> </div>
</ng-container> </ng-container>

View File

@@ -12,10 +12,10 @@
</h1> </h1>
<div class="mb-3 mt-3"> <div class="mb-3 mt-3">
<button class="btn btn-light" (click)="onToggleSelectAll(suggestionsRD.page)">Select / Deselect All</button> <button class="btn mr-2 btn-light" (click)="onToggleSelectAll(suggestionsRD.page)">Select / Deselect All</button>
<em>({{ getSelectedSuggestionsCount() }})</em> <em>({{ getSelectedSuggestionsCount() }})</em>
<ds-suggestion-actions *ngIf="getSelectedSuggestionsCount() > 0" <ds-suggestion-actions *ngIf="getSelectedSuggestionsCount() > 0"
class="mt-2 ml-2" class="m-2"
[isBulk]="true" [isBulk]="true"
[isCollectionFixed]="isCollectionFixed(suggestionsRD.page)" [isCollectionFixed]="isCollectionFixed(suggestionsRD.page)"
(approveAndImport)="approveAndImportAllSelected($event)" (approveAndImport)="approveAndImportAllSelected($event)"
@@ -42,6 +42,7 @@
</ul> </ul>
</ds-pagination> </ds-pagination>
</div> </div>
<div *ngIf="suggestionsRD?.pageInfo?.totalElements === 0">{{ 'suggestion.count.missing' | translate }}</div>
</ng-container> </ng-container>
</div> </div>
</div> </div>

View File

@@ -172,12 +172,12 @@ export class SuggestionsPageComponent implements OnInit {
this.selectedSuggestions = {}; this.selectedSuggestions = {};
if (results.success > 0) { if (results.success > 0) {
this.notificationService.success( this.notificationService.success(
this.translateService.get('suggestion.notMine.bulk.success', this.translateService.get('suggestion.ignoreSuggestion.bulk.success',
{count: results.success})); {count: results.success}));
} }
if (results.fails > 0) { if (results.fails > 0) {
this.notificationService.error( this.notificationService.error(
this.translateService.get('suggestion.notMine.bulk.error', this.translateService.get('suggestion.ignoreSuggestion.bulk.error',
{count: results.fails})); {count: results.fails}));
} }
}); });

View File

@@ -3596,7 +3596,7 @@
"suggestion.approveAndImport.bulk": "Approve & import Selected", "suggestion.approveAndImport.bulk": "Approve & import Selected",
".suggestion.approveAndImport.bulk.success": "{{ count }} suggestions have been imported successfully ", "suggestion.approveAndImport.bulk.success": "{{ count }} suggestions have been imported successfully ",
"suggestion.approveAndImport.bulk.error": "{{ count }} suggestions haven't been imported due to unexpected server errors", "suggestion.approveAndImport.bulk.error": "{{ count }} suggestions haven't been imported due to unexpected server errors",
@@ -3620,6 +3620,8 @@
"suggestion.from.source": "from the ", "suggestion.from.source": "from the ",
"suggestion.count.missing": "You have no publication claims left",
"suggestion.totalScore": "Total Score", "suggestion.totalScore": "Total Score",
"suggestion.type.openaire": "OpenAIRE", "suggestion.type.openaire": "OpenAIRE",

View File

@@ -304,8 +304,9 @@ export class DefaultAppConfig implements AppConfig {
// source: 'suggestionSource', // source: 'suggestionSource',
// collectionId: 'collectionUUID' // collectionId: 'collectionUUID'
// } // }
// If not mapped the suggestion service won't be able to approve and import the related suggestion // This is used as a default fallback in case there aren't collections where to import the suggestion
// or load the fixed suggestions collections that can be configured here adding the source and the UUID of the collection // If not mapped the user will be allowed to import the suggestions only in the provided options, shown clicking the button "Approve and import"
// If not mapped and no options available for import the user won't be able to import the suggestions.
]; ];
// Theme Config // Theme Config