mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Merge branch 'master' into resolvers-branch-angular6
Conflicts: package.json src/app/+search-page/search-filters/search-filters.component.ts src/app/core/auth/auth.effects.ts src/app/core/auth/auth.service.ts src/app/core/auth/server-auth.service.ts src/app/core/data/comcol-data.service.ts src/app/core/data/community-data.service.ts src/app/core/data/data.service.ts src/app/core/data/item-data.service.ts src/app/core/shared/dspace-object.model.ts src/app/header/header.component.spec.ts src/app/shared/auth-nav-menu/auth-nav-menu.component.ts src/app/shared/testing/auth-service-stub.ts yarn.lock
This commit is contained in:
@@ -16,8 +16,10 @@ import { REQUEST } from '@nguniversal/express-engine/tokens';
|
||||
import { RouterReducerState } from '@ngrx/router-store';
|
||||
import { select, Store } from '@ngrx/store';
|
||||
import { CookieAttributes } from 'js-cookie';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { map, switchMap, withLatestFrom } from 'rxjs/operators';
|
||||
|
||||
import { Eperson } from '../eperson/models/eperson.model';
|
||||
import { EPerson } from '../eperson/models/eperson.model';
|
||||
import { AuthRequestService } from './auth-request.service';
|
||||
|
||||
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
||||
@@ -35,6 +37,8 @@ import { AppState, routerStateSelector } from '../../app.reducer';
|
||||
import { ResetAuthenticationMessagesAction, SetRedirectUrlAction } from './auth.actions';
|
||||
import { NativeWindowRef, NativeWindowService } from '../../shared/services/window.service';
|
||||
import { Base64EncodeUrl } from '../../shared/utils/encode-decode.util';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { NormalizedEPerson } from '../eperson/models/normalized-eperson.model';
|
||||
|
||||
export const LOGIN_ROUTE = '/login';
|
||||
export const LOGOUT_ROUTE = '/logout';
|
||||
@@ -58,7 +62,9 @@ export class AuthService {
|
||||
protected authRequestService: AuthRequestService,
|
||||
protected router: Router,
|
||||
protected storage: CookieService,
|
||||
protected store: Store<AppState>) {
|
||||
protected store: Store<AppState>,
|
||||
protected rdbService: RemoteDataBuildService
|
||||
) {
|
||||
this.store.pipe(
|
||||
select(isAuthenticated),
|
||||
startWith(false)
|
||||
@@ -132,7 +138,7 @@ export class AuthService {
|
||||
* Returns the authenticated user
|
||||
* @returns {User}
|
||||
*/
|
||||
public authenticatedUser(token: AuthTokenInfo): Observable<Eperson> {
|
||||
public authenticatedUser(token: AuthTokenInfo): Observable<EPerson> {
|
||||
// Determine if the user has an existing auth session on the server
|
||||
const options: HttpOptions = Object.create({});
|
||||
let headers = new HttpHeaders();
|
||||
@@ -140,13 +146,18 @@ export class AuthService {
|
||||
headers = headers.append('Authorization', `Bearer ${token.accessToken}`);
|
||||
options.headers = headers;
|
||||
return this.authRequestService.getRequest('status', options).pipe(
|
||||
map((status: AuthStatus) => {
|
||||
switchMap((status: AuthStatus) => {
|
||||
|
||||
if (status.authenticated) {
|
||||
return status.eperson[0];
|
||||
// TODO this should be cleaned up, AuthStatus could be parsed by the RemoteDataService as a whole...
|
||||
// Review when https://jira.duraspace.org/browse/DS-4006 is fixed
|
||||
// See https://github.com/DSpace/dspace-angular/issues/292
|
||||
const person$ = this.rdbService.buildSingle<NormalizedEPerson, EPerson>(status.eperson.toString());
|
||||
return person$.pipe(map((eperson) => eperson.payload));
|
||||
} else {
|
||||
throw(new Error('Not authenticated'));
|
||||
}
|
||||
}));
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,7 +217,7 @@ export class AuthService {
|
||||
* Create a new user
|
||||
* @returns {User}
|
||||
*/
|
||||
public create(user: Eperson): Observable<Eperson> {
|
||||
public create(user: EPerson): Observable<EPerson> {
|
||||
// Normally you would do an HTTP request to POST the user
|
||||
// details and then return the new user object
|
||||
// but, let's just return the new user for this example.
|
||||
@@ -357,8 +368,12 @@ export class AuthService {
|
||||
this.router.navigated = false;
|
||||
const url = decodeURIComponent(redirectUrl);
|
||||
this.router.navigateByUrl(url);
|
||||
/* TODO Reenable hard redirect when REST API can handle x-forwarded-for, see https://github.com/DSpace/DSpace/pull/2207 */
|
||||
// this._window.nativeWindow.location.href = url;
|
||||
} else {
|
||||
this.router.navigate(['/']);
|
||||
/* TODO Reenable hard redirect when REST API can handle x-forwarded-for, see https://github.com/DSpace/DSpace/pull/2207 */
|
||||
// this._window.nativeWindow.location.href = '/';
|
||||
}
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user