mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge pull request #3711 from tdonohue/port_3693_to_8x
[Port dspace-8_x] Removed unauthorized metadata-export-search request on search page
This commit is contained in:
@@ -13,7 +13,6 @@ import { AuthorizationDataService } from '../../../core/data/feature-authorizati
|
|||||||
import { ScriptDataService } from '../../../core/data/processes/script-data.service';
|
import { ScriptDataService } from '../../../core/data/processes/script-data.service';
|
||||||
import { getProcessDetailRoute } from '../../../process-page/process-page-routing.paths';
|
import { getProcessDetailRoute } from '../../../process-page/process-page-routing.paths';
|
||||||
import { Process } from '../../../process-page/processes/process.model';
|
import { Process } from '../../../process-page/processes/process.model';
|
||||||
import { Script } from '../../../process-page/scripts/script.model';
|
|
||||||
import { NotificationsService } from '../../notifications/notifications.service';
|
import { NotificationsService } from '../../notifications/notifications.service';
|
||||||
import {
|
import {
|
||||||
createFailedRemoteDataObject$,
|
createFailedRemoteDataObject$,
|
||||||
@@ -33,7 +32,6 @@ describe('SearchExportCsvComponent', () => {
|
|||||||
let notificationsService;
|
let notificationsService;
|
||||||
let router;
|
let router;
|
||||||
|
|
||||||
const script = Object.assign(new Script(), { id: 'metadata-export-search', name: 'metadata-export-search' });
|
|
||||||
const process = Object.assign(new Process(), { processId: 5, scriptName: 'metadata-export-search' });
|
const process = Object.assign(new Process(), { processId: 5, scriptName: 'metadata-export-search' });
|
||||||
|
|
||||||
const searchConfig = new PaginatedSearchOptions({
|
const searchConfig = new PaginatedSearchOptions({
|
||||||
@@ -49,7 +47,7 @@ describe('SearchExportCsvComponent', () => {
|
|||||||
|
|
||||||
function initBeforeEachAsync() {
|
function initBeforeEachAsync() {
|
||||||
scriptDataService = jasmine.createSpyObj('scriptDataService', {
|
scriptDataService = jasmine.createSpyObj('scriptDataService', {
|
||||||
findById: createSuccessfulRemoteDataObject$(script),
|
scriptWithNameExistsAndCanExecute: observableOf(true),
|
||||||
invoke: createSuccessfulRemoteDataObject$(process),
|
invoke: createSuccessfulRemoteDataObject$(process),
|
||||||
});
|
});
|
||||||
authorizationDataService = jasmine.createSpyObj('authorizationService', {
|
authorizationDataService = jasmine.createSpyObj('authorizationService', {
|
||||||
@@ -117,15 +115,22 @@ describe('SearchExportCsvComponent', () => {
|
|||||||
describe('when the metadata-export-search script is not present', () => {
|
describe('when the metadata-export-search script is not present', () => {
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
initBeforeEachAsync();
|
initBeforeEachAsync();
|
||||||
(scriptDataService.findById as jasmine.Spy).and.returnValue(createFailedRemoteDataObject$('Not found', 404));
|
(scriptDataService.scriptWithNameExistsAndCanExecute as jasmine.Spy).and.returnValue(observableOf(false));
|
||||||
}));
|
}));
|
||||||
beforeEach(() => {
|
|
||||||
initBeforeEach();
|
|
||||||
});
|
|
||||||
it('should should not add the button', () => {
|
it('should should not add the button', () => {
|
||||||
|
initBeforeEach();
|
||||||
|
|
||||||
const debugElement = fixture.debugElement.query(By.css('button.export-button'));
|
const debugElement = fixture.debugElement.query(By.css('button.export-button'));
|
||||||
expect(debugElement).toBeNull();
|
expect(debugElement).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not call scriptWithNameExistsAndCanExecute when unauthorized', () => {
|
||||||
|
(authorizationDataService.isAuthorized as jasmine.Spy).and.returnValue(observableOf(false));
|
||||||
|
initBeforeEach();
|
||||||
|
|
||||||
|
expect(scriptDataService.scriptWithNameExistsAndCanExecute).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('export', () => {
|
describe('export', () => {
|
||||||
|
@@ -13,11 +13,13 @@ import {
|
|||||||
TranslateModule,
|
TranslateModule,
|
||||||
TranslateService,
|
TranslateService,
|
||||||
} from '@ngx-translate/core';
|
} from '@ngx-translate/core';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
import {
|
import {
|
||||||
combineLatest as observableCombineLatest,
|
filter,
|
||||||
Observable,
|
map,
|
||||||
} from 'rxjs';
|
startWith,
|
||||||
import { map } from 'rxjs/operators';
|
switchMap,
|
||||||
|
} from 'rxjs/operators';
|
||||||
|
|
||||||
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
||||||
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
|
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
|
||||||
@@ -32,6 +34,7 @@ import {
|
|||||||
} from '../../empty.util';
|
} from '../../empty.util';
|
||||||
import { NotificationsService } from '../../notifications/notifications.service';
|
import { NotificationsService } from '../../notifications/notifications.service';
|
||||||
import { PaginatedSearchOptions } from '../models/paginated-search-options.model';
|
import { PaginatedSearchOptions } from '../models/paginated-search-options.model';
|
||||||
|
import { SearchFilter } from '../models/search-filter.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-search-export-csv',
|
selector: 'ds-search-export-csv',
|
||||||
@@ -69,15 +72,11 @@ export class SearchExportCsvComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
const scriptExists$ = this.scriptDataService.findById('metadata-export-search').pipe(
|
this.shouldShowButton$ = this.authorizationDataService.isAuthorized(FeatureID.AdministratorOf).pipe(
|
||||||
getFirstCompletedRemoteData(),
|
filter((isAuthorized: boolean) => isAuthorized),
|
||||||
map((rd) => rd.isSuccess && hasValue(rd.payload)),
|
switchMap(() => this.scriptDataService.scriptWithNameExistsAndCanExecute('metadata-export-search')),
|
||||||
);
|
map((canExecute: boolean) => canExecute),
|
||||||
|
startWith(false),
|
||||||
const isAuthorized$ = this.authorizationDataService.isAuthorized(FeatureID.AdministratorOf);
|
|
||||||
|
|
||||||
this.shouldShowButton$ = observableCombineLatest([scriptExists$, isAuthorized$]).pipe(
|
|
||||||
map(([scriptExists, isAuthorized]: [boolean, boolean]) => scriptExists && isAuthorized),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,19 +96,19 @@ export class SearchExportCsvComponent implements OnInit {
|
|||||||
parameters.push({ name: '-c', value: this.searchConfig.configuration });
|
parameters.push({ name: '-c', value: this.searchConfig.configuration });
|
||||||
}
|
}
|
||||||
if (isNotEmpty(this.searchConfig.filters)) {
|
if (isNotEmpty(this.searchConfig.filters)) {
|
||||||
this.searchConfig.filters.forEach((filter) => {
|
this.searchConfig.filters.forEach((searchFilter: SearchFilter) => {
|
||||||
if (hasValue(filter.values)) {
|
if (hasValue(searchFilter.values)) {
|
||||||
filter.values.forEach((value) => {
|
searchFilter.values.forEach((value: string) => {
|
||||||
let operator;
|
let operator;
|
||||||
let filterValue;
|
let filterValue;
|
||||||
if (hasValue(filter.operator)) {
|
if (hasValue(searchFilter.operator)) {
|
||||||
operator = filter.operator;
|
operator = searchFilter.operator;
|
||||||
filterValue = value;
|
filterValue = value;
|
||||||
} else {
|
} else {
|
||||||
operator = value.substring(value.lastIndexOf(',') + 1);
|
operator = value.substring(value.lastIndexOf(',') + 1);
|
||||||
filterValue = value.substring(0, value.lastIndexOf(','));
|
filterValue = value.substring(0, value.lastIndexOf(','));
|
||||||
}
|
}
|
||||||
const valueToAdd = `${filter.key.substring(2)},${operator}=${filterValue}`;
|
const valueToAdd = `${searchFilter.key.substring(2)},${operator}=${filterValue}`;
|
||||||
parameters.push({ name: '-f', value: valueToAdd });
|
parameters.push({ name: '-f', value: valueToAdd });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -160,7 +160,7 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
|
|||||||
this.currentUrl = this.router.url;
|
this.currentUrl = this.router.url;
|
||||||
this.currentPage = this.getCurrentPage().pipe(distinctUntilChanged());
|
this.currentPage = this.getCurrentPage().pipe(distinctUntilChanged());
|
||||||
this.searchOptions$ = this.searchConfigService.searchOptions.pipe(
|
this.searchOptions$ = this.searchConfigService.searchOptions.pipe(
|
||||||
map((options: SearchOptions) => hasNoValue(this.scope) ? options : Object.assign({}, options, {
|
map((options: SearchOptions) => hasNoValue(this.scope) ? options : Object.assign(new SearchOptions(options), {
|
||||||
scope: this.scope,
|
scope: this.scope,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user