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