mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
fixed google scholar links, todo: fix tests
This commit is contained in:
@@ -57,8 +57,8 @@ function generateEnvironmentFile(file: GlobalConfig): void {
|
|||||||
|
|
||||||
// TODO remove workaround in beta 5
|
// TODO remove workaround in beta 5
|
||||||
if (file.rest.nameSpace.match("(.*)/api/?$") !== null) {
|
if (file.rest.nameSpace.match("(.*)/api/?$") !== null) {
|
||||||
const newValue = getNameSpace(file.rest.nameSpace);
|
file.rest.nameSpace = getNameSpace(file.rest.nameSpace);
|
||||||
console.log(colors.white.bgMagenta.bold(`The rest.nameSpace property in your environment file or in your DSPACE_REST_NAMESPACE environment variable ends with '/api'.\nThis is deprecated. As '/api' isn't configurable on the rest side, it shouldn't be repeated in every environment file.\nPlease change the rest nameSpace to '${newValue}'`));
|
console.log(colors.white.bgMagenta.bold(`The rest.nameSpace property in your environment file or in your DSPACE_REST_NAMESPACE environment variable ends with '/api'.\nThis is deprecated. As '/api' isn't configurable on the rest side, it shouldn't be repeated in every environment file.\nPlease change the rest nameSpace to '${file.rest.nameSpace}'`));
|
||||||
}
|
}
|
||||||
|
|
||||||
const contents = `export const environment = ` + JSON.stringify(file);
|
const contents = `export const environment = ` + JSON.stringify(file);
|
||||||
|
@@ -52,6 +52,7 @@ import { UUIDService } from '../shared/uuid.service';
|
|||||||
import { MetadataService } from './metadata.service';
|
import { MetadataService } from './metadata.service';
|
||||||
import { environment } from '../../../environments/environment';
|
import { environment } from '../../../environments/environment';
|
||||||
import { storeModuleConfig } from '../../app.reducer';
|
import { storeModuleConfig } from '../../app.reducer';
|
||||||
|
import { HardRedirectService } from '../services/hard-redirect.service';
|
||||||
|
|
||||||
/* tslint:disable:max-classes-per-file */
|
/* tslint:disable:max-classes-per-file */
|
||||||
@Component({
|
@Component({
|
||||||
@@ -170,6 +171,7 @@ describe('MetadataService', () => {
|
|||||||
Title,
|
Title,
|
||||||
// tslint:disable-next-line:no-empty
|
// tslint:disable-next-line:no-empty
|
||||||
{ provide: ItemDataService, useValue: { findById: () => {} } },
|
{ provide: ItemDataService, useValue: { findById: () => {} } },
|
||||||
|
{ provide: HardRedirectService, useValue: { rewriteDownloadURL: (a) => a }, getRequestOrigin: () => environment.ui.baseUrl },
|
||||||
BrowseService,
|
BrowseService,
|
||||||
MetadataService
|
MetadataService
|
||||||
],
|
],
|
||||||
|
@@ -21,6 +21,7 @@ import { DSpaceObject } from '../shared/dspace-object.model';
|
|||||||
import { Item } from '../shared/item.model';
|
import { Item } from '../shared/item.model';
|
||||||
import { getFirstSucceededRemoteDataPayload, getFirstSucceededRemoteListPayload } from '../shared/operators';
|
import { getFirstSucceededRemoteDataPayload, getFirstSucceededRemoteListPayload } from '../shared/operators';
|
||||||
import { environment } from '../../../environments/environment';
|
import { environment } from '../../../environments/environment';
|
||||||
|
import { HardRedirectService } from '../services/hard-redirect.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MetadataService {
|
export class MetadataService {
|
||||||
@@ -39,6 +40,7 @@ export class MetadataService {
|
|||||||
private dsoNameService: DSONameService,
|
private dsoNameService: DSONameService,
|
||||||
private bitstreamDataService: BitstreamDataService,
|
private bitstreamDataService: BitstreamDataService,
|
||||||
private bitstreamFormatDataService: BitstreamFormatDataService,
|
private bitstreamFormatDataService: BitstreamFormatDataService,
|
||||||
|
private redirectService: HardRedirectService
|
||||||
) {
|
) {
|
||||||
// TODO: determine what open graph meta tags are needed and whether
|
// TODO: determine what open graph meta tags are needed and whether
|
||||||
// the differ per route. potentially add image based on DSpaceObject
|
// the differ per route. potentially add image based on DSpaceObject
|
||||||
@@ -254,7 +256,7 @@ export class MetadataService {
|
|||||||
*/
|
*/
|
||||||
private setCitationAbstractUrlTag(): void {
|
private setCitationAbstractUrlTag(): void {
|
||||||
if (this.currentObject.value instanceof Item) {
|
if (this.currentObject.value instanceof Item) {
|
||||||
const value = [environment.ui.baseUrl, this.router.url].join('');
|
const value = [this.redirectService.getRequestOrigin(), this.router.url].join('');
|
||||||
this.addMetaTag('citation_abstract_html_url', value);
|
this.addMetaTag('citation_abstract_html_url', value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,7 +281,8 @@ export class MetadataService {
|
|||||||
getFirstSucceededRemoteDataPayload()
|
getFirstSucceededRemoteDataPayload()
|
||||||
).subscribe((format: BitstreamFormat) => {
|
).subscribe((format: BitstreamFormat) => {
|
||||||
if (format.mimetype === 'application/pdf') {
|
if (format.mimetype === 'application/pdf') {
|
||||||
this.addMetaTag('citation_pdf_url', bitstream._links.content.href);
|
const rewrittenURL= this.redirectService.rewriteDownloadURL(bitstream._links.content.href);
|
||||||
|
this.addMetaTag('citation_pdf_url', rewrittenURL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -2,11 +2,12 @@ import {TestBed} from '@angular/core/testing';
|
|||||||
import {BrowserHardRedirectService} from './browser-hard-redirect.service';
|
import {BrowserHardRedirectService} from './browser-hard-redirect.service';
|
||||||
|
|
||||||
describe('BrowserHardRedirectService', () => {
|
describe('BrowserHardRedirectService', () => {
|
||||||
|
const origin = 'test origin';
|
||||||
const mockLocation = {
|
const mockLocation = {
|
||||||
href: undefined,
|
href: undefined,
|
||||||
pathname: '/pathname',
|
pathname: '/pathname',
|
||||||
search: '/search',
|
search: '/search',
|
||||||
|
origin
|
||||||
} as Location;
|
} as Location;
|
||||||
|
|
||||||
const service: BrowserHardRedirectService = new BrowserHardRedirectService(mockLocation);
|
const service: BrowserHardRedirectService = new BrowserHardRedirectService(mockLocation);
|
||||||
@@ -38,4 +39,12 @@ describe('BrowserHardRedirectService', () => {
|
|||||||
expect(service.getCurrentRoute()).toEqual(mockLocation.pathname + mockLocation.search);
|
expect(service.getCurrentRoute()).toEqual(mockLocation.pathname + mockLocation.search);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when requesting the origin', () => {
|
||||||
|
|
||||||
|
it('should return the location origin', () => {
|
||||||
|
expect(service.getRequestOrigin()).toEqual(origin);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -11,11 +11,12 @@ export function locationProvider(): Location {
|
|||||||
* Service for performing hard redirects within the browser app module
|
* Service for performing hard redirects within the browser app module
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BrowserHardRedirectService implements HardRedirectService {
|
export class BrowserHardRedirectService extends HardRedirectService {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(LocationToken) protected location: Location,
|
@Inject(LocationToken) protected location: Location,
|
||||||
) {
|
) {
|
||||||
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,4 +33,11 @@ export class BrowserHardRedirectService implements HardRedirectService {
|
|||||||
getCurrentRoute() {
|
getCurrentRoute() {
|
||||||
return this.location.pathname + this.location.search;
|
return this.location.pathname + this.location.search;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the hostname of the request
|
||||||
|
*/
|
||||||
|
getRequestOrigin() {
|
||||||
|
return this.location.origin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
53
src/app/core/services/hard-redirect.service.spec.ts
Normal file
53
src/app/core/services/hard-redirect.service.spec.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import { HardRedirectService } from './hard-redirect.service';
|
||||||
|
import { environment } from '../../../environments/environment';
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
const requestOrigin = 'http://dspace-angular-ui.dspace.com';
|
||||||
|
|
||||||
|
fdescribe('HardRedirectService', () => {
|
||||||
|
const service: TestHardRedirectService = new TestHardRedirectService();
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when calling rewriteDownloadURL', () => {
|
||||||
|
let originalValue;
|
||||||
|
const relativePath = '/test/url/path';
|
||||||
|
const testURL = environment.rest.baseUrl + relativePath;
|
||||||
|
beforeEach(() => {
|
||||||
|
originalValue = environment.rewriteDownloadUrls;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('it should return the same url when rewriteDownloadURL is false', () => {
|
||||||
|
environment.rewriteDownloadUrls = false;
|
||||||
|
expect(service.rewriteDownloadURL(testURL)).toEqual(testURL);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('it should replace part of the url when rewriteDownloadURL is true', () => {
|
||||||
|
environment.rewriteDownloadUrls = true;
|
||||||
|
expect(service.rewriteDownloadURL(testURL)).toEqual(requestOrigin + relativePath);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
environment.rewriteDownloadUrls = originalValue;
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
class TestHardRedirectService extends HardRedirectService {
|
||||||
|
constructor() {
|
||||||
|
|
||||||
|
}
|
||||||
|
redirect(url: string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
getCurrentRoute() {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
getRequestOrigin() {
|
||||||
|
return requestOrigin;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,4 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { environment } from '../../../environments/environment';
|
||||||
|
import { URLCombiner } from '../url-combiner/url-combiner';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to take care of hard redirects
|
* Service to take care of hard redirects
|
||||||
@@ -19,4 +21,20 @@ export abstract class HardRedirectService {
|
|||||||
* e.g. /search?page=1&query=open%20access&f.dateIssued.min=1980&f.dateIssued.max=2020
|
* e.g. /search?page=1&query=open%20access&f.dateIssued.min=1980&f.dateIssued.max=2020
|
||||||
*/
|
*/
|
||||||
abstract getCurrentRoute();
|
abstract getCurrentRoute();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the hostname of the request
|
||||||
|
*/
|
||||||
|
abstract getRequestOrigin();
|
||||||
|
|
||||||
|
public rewriteDownloadURL(originalUrl: string): string {
|
||||||
|
if (environment.rewriteDownloadUrls) {
|
||||||
|
let hostName = this.getRequestOrigin();
|
||||||
|
let namespace = environment.rest.nameSpace;
|
||||||
|
let rewrittenUrl = new URLCombiner(hostName, namespace).toString();
|
||||||
|
return originalUrl.replace(environment.rest.baseUrl, rewrittenUrl);
|
||||||
|
} else {
|
||||||
|
return originalUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,8 +7,13 @@ describe('ServerHardRedirectService', () => {
|
|||||||
const mockResponse = jasmine.createSpyObj(['redirect', 'end']);
|
const mockResponse = jasmine.createSpyObj(['redirect', 'end']);
|
||||||
|
|
||||||
const service: ServerHardRedirectService = new ServerHardRedirectService(mockRequest, mockResponse);
|
const service: ServerHardRedirectService = new ServerHardRedirectService(mockRequest, mockResponse);
|
||||||
|
const origin = 'test-host';
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
mockRequest.headers = {
|
||||||
|
origin: 'test-host',
|
||||||
|
};
|
||||||
|
|
||||||
TestBed.configureTestingModule({});
|
TestBed.configureTestingModule({});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -40,4 +45,12 @@ describe('ServerHardRedirectService', () => {
|
|||||||
expect(service.getCurrentRoute()).toEqual(mockRequest.originalUrl);
|
expect(service.getCurrentRoute()).toEqual(mockRequest.originalUrl);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when requesting the origin', () => {
|
||||||
|
|
||||||
|
it('should return the location origin', () => {
|
||||||
|
expect(service.getRequestOrigin()).toEqual(origin);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -7,12 +7,13 @@ import { HardRedirectService } from './hard-redirect.service';
|
|||||||
* Service for performing hard redirects within the server app module
|
* Service for performing hard redirects within the server app module
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ServerHardRedirectService implements HardRedirectService {
|
export class ServerHardRedirectService extends HardRedirectService {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(REQUEST) protected req: Request,
|
@Inject(REQUEST) protected req: Request,
|
||||||
@Inject(RESPONSE) protected res: Response,
|
@Inject(RESPONSE) protected res: Response,
|
||||||
) {
|
) {
|
||||||
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,4 +60,11 @@ export class ServerHardRedirectService implements HardRedirectService {
|
|||||||
getCurrentRoute() {
|
getCurrentRoute() {
|
||||||
return this.req.originalUrl;
|
return this.req.originalUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the hostname of the request
|
||||||
|
*/
|
||||||
|
getRequestOrigin() {
|
||||||
|
return this.req.headers.origin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ import { FileDownloadLinkComponent } from './file-download-link.component';
|
|||||||
import { AuthService } from '../../core/auth/auth.service';
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
import { FileService } from '../../core/shared/file.service';
|
import { FileService } from '../../core/shared/file.service';
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
|
import { HardRedirectService } from '../../core/services/hard-redirect.service';
|
||||||
|
|
||||||
describe('FileDownloadLinkComponent', () => {
|
describe('FileDownloadLinkComponent', () => {
|
||||||
let component: FileDownloadLinkComponent;
|
let component: FileDownloadLinkComponent;
|
||||||
@@ -23,13 +24,14 @@ describe('FileDownloadLinkComponent', () => {
|
|||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
init();
|
init();
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [ FileDownloadLinkComponent ],
|
declarations: [FileDownloadLinkComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: AuthService, useValue: authService },
|
{ provide: AuthService, useValue: authService },
|
||||||
{ provide: FileService, useValue: fileService }
|
{ provide: FileService, useValue: fileService },
|
||||||
|
{ provide: HardRedirectService, useValue: { rewriteDownloadURL: (a) => a } },
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -2,6 +2,10 @@ import { Component, Input, OnInit } from '@angular/core';
|
|||||||
import { FileService } from '../../core/shared/file.service';
|
import { FileService } from '../../core/shared/file.service';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import { AuthService } from '../../core/auth/auth.service';
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
|
import { environment } from '../../../environments/environment';
|
||||||
|
import { hasValue } from '../empty.util';
|
||||||
|
import { URLCombiner } from '../../core/url-combiner/url-combiner';
|
||||||
|
import { HardRedirectService } from '../../core/services/hard-redirect.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-file-download-link',
|
selector: 'ds-file-download-link',
|
||||||
@@ -30,10 +34,13 @@ export class FileDownloadLinkComponent implements OnInit {
|
|||||||
isAuthenticated$: Observable<boolean>;
|
isAuthenticated$: Observable<boolean>;
|
||||||
|
|
||||||
constructor(private fileService: FileService,
|
constructor(private fileService: FileService,
|
||||||
private authService: AuthService) { }
|
private authService: AuthService,
|
||||||
|
private redirectService: HardRedirectService) {
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.isAuthenticated$ = this.authService.isAuthenticated();
|
this.isAuthenticated$ = this.authService.isAuthenticated();
|
||||||
|
this.href = this.redirectService.rewriteDownloadURL(this.href);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,5 +51,4 @@ export class FileDownloadLinkComponent implements OnInit {
|
|||||||
this.fileService.downloadFile(this.href);
|
this.fileService.downloadFile(this.href);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -31,4 +31,5 @@ export interface GlobalConfig extends Config {
|
|||||||
item: ItemPageConfig;
|
item: ItemPageConfig;
|
||||||
collection: CollectionPageConfig;
|
collection: CollectionPageConfig;
|
||||||
theme: Theme;
|
theme: Theme;
|
||||||
|
rewriteDownloadUrls: boolean;
|
||||||
}
|
}
|
||||||
|
@@ -216,4 +216,5 @@ export const environment: GlobalConfig = {
|
|||||||
theme: {
|
theme: {
|
||||||
name: 'default',
|
name: 'default',
|
||||||
},
|
},
|
||||||
|
rewriteDownloadUrls: false,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user