mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Set providedIn root for services using inject tokens
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';
|
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';
|
||||||
import { Inject, Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { DSpaceObjectDataService } from '../core/data/dspace-object-data.service';
|
import { DSpaceObjectDataService } from '../core/data/dspace-object-data.service';
|
||||||
import { hasNoValue, hasValue } from '../shared/empty.util';
|
import { hasNoValue, hasValue } from '../shared/empty.util';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
|
@@ -14,13 +14,13 @@ import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
|||||||
import { AuthStatus } from './models/auth-status.model';
|
import { AuthStatus } from './models/auth-status.model';
|
||||||
import { AuthTokenInfo, TOKENITEM } from './models/auth-token-info.model';
|
import { AuthTokenInfo, TOKENITEM } from './models/auth-token-info.model';
|
||||||
import {
|
import {
|
||||||
|
hasNoValue,
|
||||||
hasValue,
|
hasValue,
|
||||||
hasValueOperator,
|
hasValueOperator,
|
||||||
isEmpty,
|
isEmpty,
|
||||||
isNotEmpty,
|
isNotEmpty,
|
||||||
isNotNull,
|
isNotNull,
|
||||||
isNotUndefined,
|
isNotUndefined
|
||||||
hasNoValue
|
|
||||||
} from '../../shared/empty.util';
|
} from '../../shared/empty.util';
|
||||||
import { CookieService } from '../services/cookie.service';
|
import { CookieService } from '../services/cookie.service';
|
||||||
import {
|
import {
|
||||||
@@ -28,8 +28,8 @@ import {
|
|||||||
getAuthenticationToken,
|
getAuthenticationToken,
|
||||||
getRedirectUrl,
|
getRedirectUrl,
|
||||||
isAuthenticated,
|
isAuthenticated,
|
||||||
isTokenRefreshing,
|
isAuthenticatedLoaded,
|
||||||
isAuthenticatedLoaded
|
isTokenRefreshing
|
||||||
} from './selectors';
|
} from './selectors';
|
||||||
import { AppState } from '../../app.reducer';
|
import { AppState } from '../../app.reducer';
|
||||||
import {
|
import {
|
||||||
@@ -53,7 +53,7 @@ export const IMPERSONATING_COOKIE = 'dsImpersonatingEPerson';
|
|||||||
/**
|
/**
|
||||||
* The auth service.
|
* The auth service.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({providedIn: 'root'})
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,7 +100,7 @@ export class AuthService {
|
|||||||
} else {
|
} else {
|
||||||
throw(new Error('Invalid email or password'));
|
throw(new Error('Invalid email or password'));
|
||||||
}
|
}
|
||||||
}))
|
}));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ export class AuthService {
|
|||||||
} else {
|
} else {
|
||||||
throw(new Error('Not authenticated'));
|
throw(new Error('Not authenticated'));
|
||||||
}
|
}
|
||||||
}))
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,7 +163,7 @@ export class AuthService {
|
|||||||
public retrieveAuthenticatedUserByHref(userHref: string): Observable<EPerson> {
|
public retrieveAuthenticatedUserByHref(userHref: string): Observable<EPerson> {
|
||||||
return this.epersonService.findByHref(userHref).pipe(
|
return this.epersonService.findByHref(userHref).pipe(
|
||||||
getAllSucceededRemoteDataPayload()
|
getAllSucceededRemoteDataPayload()
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,7 +173,7 @@ export class AuthService {
|
|||||||
public retrieveAuthenticatedUserById(userId: string): Observable<EPerson> {
|
public retrieveAuthenticatedUserById(userId: string): Observable<EPerson> {
|
||||||
return this.epersonService.findById(userId).pipe(
|
return this.epersonService.findById(userId).pipe(
|
||||||
getAllSucceededRemoteDataPayload()
|
getAllSucceededRemoteDataPayload()
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -186,7 +186,7 @@ export class AuthService {
|
|||||||
hasValueOperator(),
|
hasValueOperator(),
|
||||||
switchMap((id: string) => this.epersonService.findById(id) ),
|
switchMap((id: string) => this.epersonService.findById(id) ),
|
||||||
getAllSucceededRemoteDataPayload()
|
getAllSucceededRemoteDataPayload()
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -273,7 +273,7 @@ export class AuthService {
|
|||||||
} else {
|
} else {
|
||||||
throw(new Error('auth.errors.invalid-user'));
|
throw(new Error('auth.errors.invalid-user'));
|
||||||
}
|
}
|
||||||
}))
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -317,7 +317,7 @@ export class AuthService {
|
|||||||
return token.expires - (60 * 5 * 1000) < Date.now();
|
return token.expires - (60 * 5 * 1000) < Date.now();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -446,7 +446,7 @@ export class AuthService {
|
|||||||
if (hasNoValue(currentRedirectUrl)) {
|
if (hasNoValue(currentRedirectUrl)) {
|
||||||
this.setRedirectUrl(newRedirectUrl);
|
this.setRedirectUrl(newRedirectUrl);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -13,7 +13,7 @@ import { AuthTokenInfo } from './models/auth-token-info.model';
|
|||||||
/**
|
/**
|
||||||
* The auth service.
|
* The auth service.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({providedIn: 'root'})
|
||||||
export class ServerAuthService extends AuthService {
|
export class ServerAuthService extends AuthService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -101,7 +101,6 @@ import { Community } from './shared/community.model';
|
|||||||
import { DSpaceObject } from './shared/dspace-object.model';
|
import { DSpaceObject } from './shared/dspace-object.model';
|
||||||
import { ExternalSourceEntry } from './shared/external-source-entry.model';
|
import { ExternalSourceEntry } from './shared/external-source-entry.model';
|
||||||
import { ExternalSource } from './shared/external-source.model';
|
import { ExternalSource } from './shared/external-source.model';
|
||||||
import { FileService } from './shared/file.service';
|
|
||||||
import { HALEndpointService } from './shared/hal-endpoint.service';
|
import { HALEndpointService } from './shared/hal-endpoint.service';
|
||||||
import { ItemType } from './shared/item-relationships/item-type.model';
|
import { ItemType } from './shared/item-relationships/item-type.model';
|
||||||
import { RelationshipType } from './shared/item-relationships/relationship-type.model';
|
import { RelationshipType } from './shared/item-relationships/relationship-type.model';
|
||||||
@@ -253,7 +252,6 @@ const PROVIDERS = [
|
|||||||
WorkspaceitemDataService,
|
WorkspaceitemDataService,
|
||||||
WorkflowItemDataService,
|
WorkflowItemDataService,
|
||||||
UploaderService,
|
UploaderService,
|
||||||
FileService,
|
|
||||||
DSpaceObjectDataService,
|
DSpaceObjectDataService,
|
||||||
ConfigurationDataService,
|
ConfigurationDataService,
|
||||||
DSOChangeAnalyzer,
|
DSOChangeAnalyzer,
|
||||||
|
@@ -3,7 +3,7 @@ import { Inject, Injectable } from '@angular/core';
|
|||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { REQUEST } from '@nguniversal/express-engine/tokens';
|
import { REQUEST } from '@nguniversal/express-engine/tokens';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable({providedIn: 'root'})
|
||||||
/**
|
/**
|
||||||
* Http Interceptor intercepting Http Requests, adding the client's IP to their X-Forwarded-For header
|
* Http Interceptor intercepting Http Requests, adding the client's IP to their X-Forwarded-For header
|
||||||
*/
|
*/
|
||||||
|
@@ -2,9 +2,9 @@ import { LANG_ORIGIN, LocaleService } from './locale.service';
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { combineLatest, Observable, of as observableOf } from 'rxjs';
|
import { combineLatest, Observable, of as observableOf } from 'rxjs';
|
||||||
import { map, mergeMap, take } from 'rxjs/operators';
|
import { map, mergeMap, take } from 'rxjs/operators';
|
||||||
import { isEmpty, isNotEmpty } from 'src/app/shared/empty.util';
|
import { isEmpty, isNotEmpty } from '../../shared/empty.util';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable({providedIn: 'root'})
|
||||||
export class ServerLocaleService extends LocaleService {
|
export class ServerLocaleService extends LocaleService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,7 +52,7 @@ export class ServerLocaleService extends LocaleService {
|
|||||||
}
|
}
|
||||||
return languages;
|
return languages;
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ 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({providedIn: 'root'})
|
||||||
export class BrowserHardRedirectService extends HardRedirectService {
|
export class BrowserHardRedirectService extends HardRedirectService {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@@ -1,23 +1,23 @@
|
|||||||
import { Inject, Injectable } from '@angular/core'
|
import { Inject, Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { REQUEST } from '@nguniversal/express-engine/tokens'
|
import { REQUEST } from '@nguniversal/express-engine/tokens';
|
||||||
|
|
||||||
import { Subject , Observable } from 'rxjs'
|
import { Subject , Observable } from 'rxjs';
|
||||||
import { CookieAttributes } from 'js-cookie'
|
import { CookieAttributes } from 'js-cookie';
|
||||||
|
|
||||||
export interface ICookieService {
|
export interface ICookieService {
|
||||||
readonly cookies$: Observable<{ readonly [key: string]: any }>
|
readonly cookies$: Observable<{ readonly [key: string]: any }>;
|
||||||
|
|
||||||
getAll(): any
|
getAll(): any;
|
||||||
|
|
||||||
get(name: string): any
|
get(name: string): any;
|
||||||
|
|
||||||
set(name: string, value: any, options?: CookieAttributes): void
|
set(name: string, value: any, options?: CookieAttributes): void;
|
||||||
|
|
||||||
remove(name: string, options?: CookieAttributes): void
|
remove(name: string, options?: CookieAttributes): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable({providedIn: 'root'})
|
||||||
export abstract class CookieService implements ICookieService {
|
export abstract class CookieService implements ICookieService {
|
||||||
protected readonly cookieSource = new Subject<{ readonly [key: string]: any }>();
|
protected readonly cookieSource = new Subject<{ readonly [key: string]: any }>();
|
||||||
public readonly cookies$ = this.cookieSource.asObservable();
|
public readonly cookies$ = this.cookieSource.asObservable();
|
||||||
@@ -25,13 +25,13 @@ export abstract class CookieService implements ICookieService {
|
|||||||
constructor(@Inject(REQUEST) protected req: any) {
|
constructor(@Inject(REQUEST) protected req: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract set(name: string, value: any, options?: CookieAttributes): void
|
public abstract set(name: string, value: any, options?: CookieAttributes): void;
|
||||||
|
|
||||||
public abstract remove(name: string, options?: CookieAttributes): void
|
public abstract remove(name: string, options?: CookieAttributes): void;
|
||||||
|
|
||||||
public abstract get(name: string): any
|
public abstract get(name: string): any;
|
||||||
|
|
||||||
public abstract getAll(): any
|
public abstract getAll(): any;
|
||||||
|
|
||||||
protected updateSource() {
|
protected updateSource() {
|
||||||
this.cookieSource.next(this.getAll());
|
this.cookieSource.next(this.getAll());
|
||||||
|
@@ -5,7 +5,7 @@ import { URLCombiner } from '../url-combiner/url-combiner';
|
|||||||
/**
|
/**
|
||||||
* Service to take care of hard redirects
|
* Service to take care of hard redirects
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({providedIn: 'root'})
|
||||||
export abstract class HardRedirectService {
|
export abstract class HardRedirectService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,29 +1,29 @@
|
|||||||
import { Injectable } from '@angular/core'
|
import { Injectable } from '@angular/core';
|
||||||
import { CookieAttributes } from 'js-cookie'
|
import { CookieAttributes } from 'js-cookie';
|
||||||
import { CookieService, ICookieService } from './cookie.service';
|
import { CookieService, ICookieService } from './cookie.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable({providedIn: 'root'})
|
||||||
export class ServerCookieService extends CookieService implements ICookieService {
|
export class ServerCookieService extends CookieService implements ICookieService {
|
||||||
|
|
||||||
public set(name: string, value: any, options?: CookieAttributes): void {
|
public set(name: string, value: any, options?: CookieAttributes): void {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public remove(name: string, options?: CookieAttributes): void {
|
public remove(name: string, options?: CookieAttributes): void {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get(name: string): any {
|
public get(name: string): any {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(this.req.cookies[name])
|
return JSON.parse(this.req.cookies[name]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return this.req ? this.req.cookies[name] : undefined
|
return this.req ? this.req.cookies[name] : undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAll(): any {
|
public getAll(): any {
|
||||||
if (this.req) {
|
if (this.req) {
|
||||||
return this.req.cookies
|
return this.req.cookies;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,7 @@ 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({providedIn: 'root'})
|
||||||
export class ServerHardRedirectService extends HardRedirectService {
|
export class ServerHardRedirectService extends HardRedirectService {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@@ -9,7 +9,7 @@ import { hasValue } from '../../shared/empty.util';
|
|||||||
/**
|
/**
|
||||||
* Provides utility methods to save files on the client-side.
|
* Provides utility methods to save files on the client-side.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({providedIn: 'root'})
|
||||||
export class FileService {
|
export class FileService {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(NativeWindowService) protected _window: NativeWindowRef,
|
@Inject(NativeWindowService) protected _window: NativeWindowRef,
|
||||||
@@ -40,5 +40,5 @@ export class FileService {
|
|||||||
const contentDisposition = res.headers.get('content-disposition') || '';
|
const contentDisposition = res.headers.get('content-disposition') || '';
|
||||||
const matches = /filename="([^;]+)"/ig.exec(contentDisposition) || [];
|
const matches = /filename="([^;]+)"/ig.exec(contentDisposition) || [];
|
||||||
return (matches[1] || 'untitled').trim().replace(/\.[^/.]+$/, '');
|
return (matches[1] || 'untitled').trim().replace(/\.[^/.]+$/, '');
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import { Injectable } from "@angular/core";
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
/* tslint:disable:no-empty */
|
/* tslint:disable:no-empty */
|
||||||
@Injectable()
|
@Injectable({providedIn: 'root'})
|
||||||
export class AngularticsMock {
|
export class AngularticsMock {
|
||||||
public eventTrack(action, properties) { }
|
public eventTrack(action, properties) { }
|
||||||
public startTracking(): void {}
|
public startTracking(): void {}
|
||||||
|
@@ -11,7 +11,7 @@ import { SearchOptions } from '../shared/search/search-options.model';
|
|||||||
/**
|
/**
|
||||||
* The statistics service
|
* The statistics service
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({providedIn: 'root'})
|
||||||
export class StatisticsService {
|
export class StatisticsService {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
Reference in New Issue
Block a user