mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge pull request #1276 from atmire/remove-unused-config-params
Remove unused config params
This commit is contained in:
@@ -74,7 +74,7 @@ describe('MetadataService', () => {
|
||||
}
|
||||
} as any as Router;
|
||||
hardRedirectService = jasmine.createSpyObj( {
|
||||
getRequestOrigin: 'https://request.org',
|
||||
getCurrentOrigin: 'https://request.org',
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
|
@@ -272,7 +272,7 @@ export class MetadataService {
|
||||
if (this.currentObject.value instanceof Item) {
|
||||
let url = this.getMetaTagValue('dc.identifier.uri');
|
||||
if (hasNoValue(url)) {
|
||||
url = new URLCombiner(this.hardRedirectService.getRequestOrigin(), this.router.url).toString();
|
||||
url = new URLCombiner(this.hardRedirectService.getCurrentOrigin(), this.router.url).toString();
|
||||
}
|
||||
this.addMetaTag('citation_abstract_html_url', url);
|
||||
}
|
||||
@@ -336,7 +336,7 @@ export class MetadataService {
|
||||
// Use the found link to set the <meta> tag
|
||||
this.addMetaTag(
|
||||
'citation_pdf_url',
|
||||
new URLCombiner(this.hardRedirectService.getRequestOrigin(), link).toString()
|
||||
new URLCombiner(this.hardRedirectService.getCurrentOrigin(), link).toString()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ import { TestBed } from '@angular/core/testing';
|
||||
import { BrowserHardRedirectService } from './browser-hard-redirect.service';
|
||||
|
||||
describe('BrowserHardRedirectService', () => {
|
||||
const origin = 'test origin';
|
||||
const origin = 'https://test-host.com:4000';
|
||||
const mockLocation = {
|
||||
href: undefined,
|
||||
pathname: '/pathname',
|
||||
@@ -43,7 +43,7 @@ describe('BrowserHardRedirectService', () => {
|
||||
describe('when requesting the origin', () => {
|
||||
|
||||
it('should return the location origin', () => {
|
||||
expect(service.getRequestOrigin()).toEqual(origin);
|
||||
expect(service.getCurrentOrigin()).toEqual(origin);
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -28,16 +28,20 @@ export class BrowserHardRedirectService extends HardRedirectService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the origin of a request
|
||||
* Get the current route, with query params included
|
||||
* e.g. /search?page=1&query=open%20access&f.dateIssued.min=1980&f.dateIssued.max=2020
|
||||
*/
|
||||
getCurrentRoute() {
|
||||
getCurrentRoute(): string {
|
||||
return this.location.pathname + this.location.search;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hostname of the request
|
||||
* Get the origin of the current URL
|
||||
* i.e. <scheme> "://" <hostname> [ ":" <port> ]
|
||||
* e.g. if the URL is https://demo7.dspace.org/search?query=test,
|
||||
* the origin would be https://demo7.dspace.org
|
||||
*/
|
||||
getRequestOrigin() {
|
||||
getCurrentOrigin(): string {
|
||||
return this.location.origin;
|
||||
}
|
||||
}
|
||||
|
@@ -1,57 +0,0 @@
|
||||
import { HardRedirectService } from './hard-redirect.service';
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
const requestOrigin = 'http://dspace-angular-ui.dspace.com';
|
||||
|
||||
describe('HardRedirectService', () => {
|
||||
let service: TestHardRedirectService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({ providers: [TestHardRedirectService] });
|
||||
service = TestBed.inject(TestHardRedirectService);
|
||||
});
|
||||
|
||||
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 + environment.rest.nameSpace + relativePath);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
environment.rewriteDownloadUrls = originalValue;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@Injectable()
|
||||
class TestHardRedirectService extends HardRedirectService {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
redirect(url: string) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getCurrentRoute() {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getRequestOrigin() {
|
||||
return requestOrigin;
|
||||
}
|
||||
}
|
@@ -1,6 +1,4 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { URLCombiner } from '../url-combiner/url-combiner';
|
||||
|
||||
/**
|
||||
* Service to take care of hard redirects
|
||||
@@ -20,21 +18,13 @@ export abstract class HardRedirectService {
|
||||
* Get the current route, with query params included
|
||||
* e.g. /search?page=1&query=open%20access&f.dateIssued.min=1980&f.dateIssued.max=2020
|
||||
*/
|
||||
abstract getCurrentRoute();
|
||||
abstract getCurrentRoute(): string;
|
||||
|
||||
/**
|
||||
* Get the hostname of the request
|
||||
* Get the origin of the current URL
|
||||
* i.e. <scheme> "://" <hostname> [ ":" <port> ]
|
||||
* e.g. if the URL is https://demo7.dspace.org/search?query=test,
|
||||
* the origin would be https://demo7.dspace.org
|
||||
*/
|
||||
abstract getRequestOrigin();
|
||||
|
||||
public rewriteDownloadURL(originalUrl: string): string {
|
||||
if (environment.rewriteDownloadUrls) {
|
||||
const hostName = this.getRequestOrigin();
|
||||
const namespace = environment.rest.nameSpace;
|
||||
const rewrittenUrl = new URLCombiner(hostName, namespace).toString();
|
||||
return originalUrl.replace(environment.rest.baseUrl, rewrittenUrl);
|
||||
} else {
|
||||
return originalUrl;
|
||||
}
|
||||
}
|
||||
abstract getCurrentOrigin(): string;
|
||||
}
|
||||
|
@@ -7,11 +7,12 @@ describe('ServerHardRedirectService', () => {
|
||||
const mockResponse = jasmine.createSpyObj(['redirect', 'end']);
|
||||
|
||||
const service: ServerHardRedirectService = new ServerHardRedirectService(mockRequest, mockResponse);
|
||||
const origin = 'test-host';
|
||||
const origin = 'https://test-host.com:4000';
|
||||
|
||||
beforeEach(() => {
|
||||
mockRequest.protocol = 'https';
|
||||
mockRequest.headers = {
|
||||
host: 'test-host',
|
||||
host: 'test-host.com:4000',
|
||||
};
|
||||
|
||||
TestBed.configureTestingModule({});
|
||||
@@ -49,7 +50,7 @@ describe('ServerHardRedirectService', () => {
|
||||
describe('when requesting the origin', () => {
|
||||
|
||||
it('should return the location origin', () => {
|
||||
expect(service.getRequestOrigin()).toEqual(origin);
|
||||
expect(service.getCurrentOrigin()).toEqual(origin);
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -55,16 +55,19 @@ export class ServerHardRedirectService extends HardRedirectService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the origin of a request
|
||||
* Get the URL of the current route
|
||||
*/
|
||||
getCurrentRoute() {
|
||||
getCurrentRoute(): string {
|
||||
return this.req.originalUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hostname of the request
|
||||
* Get the origin of the current URL
|
||||
* i.e. <scheme> "://" <hostname> [ ":" <port> ]
|
||||
* e.g. if the URL is https://demo7.dspace.org/search?query=test,
|
||||
* the origin would be https://demo7.dspace.org
|
||||
*/
|
||||
getRequestOrigin() {
|
||||
return this.req.headers.host;
|
||||
getCurrentOrigin(): string {
|
||||
return this.req.protocol + '://' + this.req.headers.host;
|
||||
}
|
||||
}
|
||||
|
@@ -24,7 +24,6 @@ export interface GlobalConfig extends Config {
|
||||
notifications: INotificationBoardOptions;
|
||||
submission: SubmissionConfig;
|
||||
universal: UniversalConfig;
|
||||
logDirectory: string;
|
||||
debug: boolean;
|
||||
defaultLanguage: string;
|
||||
languages: LangConfig[];
|
||||
@@ -32,6 +31,5 @@ export interface GlobalConfig extends Config {
|
||||
item: ItemPageConfig;
|
||||
collection: CollectionPageConfig;
|
||||
themes: ThemeConfig[];
|
||||
rewriteDownloadUrls: boolean;
|
||||
mediaViewer: MediaViewerConfig;
|
||||
}
|
||||
|
@@ -148,8 +148,6 @@ export const environment: GlobalConfig = {
|
||||
async: true,
|
||||
time: false
|
||||
},
|
||||
// Log directory
|
||||
logDirectory: '.',
|
||||
// NOTE: will log all redux actions and transfers in console
|
||||
debug: false,
|
||||
// Default Language in which the UI will be rendered if the user's browser language is not an active language
|
||||
@@ -280,8 +278,6 @@ export const environment: GlobalConfig = {
|
||||
name: 'dspace'
|
||||
},
|
||||
],
|
||||
// Whether the UI should rewrite file download URLs to match its domain. Only necessary to enable when running UI and REST API on separate domains
|
||||
rewriteDownloadUrls: false,
|
||||
// Whether to enable media viewer for image and/or video Bitstreams (i.e. Bitstreams whose MIME type starts with "image" or "video").
|
||||
// For images, this enables a gallery viewer where you can zoom or page through images.
|
||||
// For videos, this enables embedded video streaming
|
||||
|
@@ -126,8 +126,6 @@ export const environment: Partial<GlobalConfig> = {
|
||||
async: true,
|
||||
time: false
|
||||
},
|
||||
// Log directory
|
||||
logDirectory: '.',
|
||||
// NOTE: will log all redux actions and transfers in console
|
||||
debug: false,
|
||||
// Default Language in which the UI will be rendered if the user's browser language is not an active language
|
||||
|
Reference in New Issue
Block a user