mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
deprecate profile resolver (#686)
* resolve profile at startup * remove profile resolver, load profile on app ready * dispose subscriptions
This commit is contained in:
@@ -31,7 +31,7 @@ import {
|
|||||||
PageTitleService,
|
PageTitleService,
|
||||||
UploadService
|
UploadService
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||||
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { AppExtensionService } from './extensions/extension.service';
|
import { AppExtensionService } from './extensions/extension.service';
|
||||||
@@ -40,24 +40,28 @@ import {
|
|||||||
SetCurrentUrlAction,
|
SetCurrentUrlAction,
|
||||||
SetInitialStateAction,
|
SetInitialStateAction,
|
||||||
CloseModalDialogsAction,
|
CloseModalDialogsAction,
|
||||||
SetRepositoryStatusAction
|
SetRepositoryStatusAction,
|
||||||
|
SetUserProfileAction
|
||||||
} from './store/actions';
|
} from './store/actions';
|
||||||
import {
|
import {
|
||||||
AppStore,
|
AppStore,
|
||||||
AppState,
|
AppState,
|
||||||
INITIAL_APP_STATE
|
INITIAL_APP_STATE
|
||||||
} from './store/states/app.state';
|
} from './store/states/app.state';
|
||||||
import { filter } from 'rxjs/operators';
|
import { filter, takeUntil } from 'rxjs/operators';
|
||||||
import { ContentApiService } from './services/content-api.service';
|
import { ContentApiService } from './services/content-api.service';
|
||||||
import { DiscoveryEntry } from 'alfresco-js-api';
|
import { DiscoveryEntry } from 'alfresco-js-api';
|
||||||
import { AppService } from './services/app.service';
|
import { AppService } from './services/app.service';
|
||||||
|
import { Subject } from 'rxjs';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
templateUrl: './app.component.html',
|
templateUrl: './app.component.html',
|
||||||
styleUrls: ['./app.component.scss']
|
styleUrls: ['./app.component.scss']
|
||||||
})
|
})
|
||||||
export class AppComponent implements OnInit {
|
export class AppComponent implements OnInit, OnDestroy {
|
||||||
|
onDestroy$: Subject<boolean> = new Subject<boolean>();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
@@ -83,11 +87,6 @@ export class AppComponent implements OnInit {
|
|||||||
|
|
||||||
this.store.dispatch(new CloseModalDialogsAction());
|
this.store.dispatch(new CloseModalDialogsAction());
|
||||||
this.router.navigate(['/login']);
|
this.router.navigate(['/login']);
|
||||||
|
|
||||||
this.appService.waitForAuth().subscribe(() => {
|
|
||||||
this.loadRepositoryStatus();
|
|
||||||
// todo: load external auth-enabled plugins here
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -119,12 +118,18 @@ export class AppComponent implements OnInit {
|
|||||||
this.onFileUploadedError(error)
|
this.onFileUploadedError(error)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.appService.waitForAuth().subscribe(() => {
|
this.appService.ready$.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
|
||||||
this.loadRepositoryStatus();
|
this.loadRepositoryStatus();
|
||||||
|
this.loadUserProfile();
|
||||||
// todo: load external auth-enabled plugins here
|
// todo: load external auth-enabled plugins here
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.onDestroy$.next(true);
|
||||||
|
this.onDestroy$.complete();
|
||||||
|
}
|
||||||
|
|
||||||
private loadRepositoryStatus() {
|
private loadRepositoryStatus() {
|
||||||
this.contentApi
|
this.contentApi
|
||||||
.getRepositoryInformation()
|
.getRepositoryInformation()
|
||||||
@@ -135,6 +140,12 @@ export class AppComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private loadUserProfile() {
|
||||||
|
this.contentApi.getPerson('-me-').subscribe(person => {
|
||||||
|
this.store.dispatch(new SetUserProfileAction(person.entry));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private loadAppSettings() {
|
private loadAppSettings() {
|
||||||
const baseShareUrl =
|
const baseShareUrl =
|
||||||
this.config.get<string>('baseShareUrl') ||
|
this.config.get<string>('baseShareUrl') ||
|
||||||
|
@@ -29,7 +29,6 @@ import { FilesComponent } from './components/files/files.component';
|
|||||||
import { LibrariesComponent } from './components/libraries/libraries.component';
|
import { LibrariesComponent } from './components/libraries/libraries.component';
|
||||||
import { GenericErrorComponent } from './components/common/generic-error/generic-error.component';
|
import { GenericErrorComponent } from './components/common/generic-error/generic-error.component';
|
||||||
import { SearchResultsComponent } from './components/search/search-results/search-results.component';
|
import { SearchResultsComponent } from './components/search/search-results/search-results.component';
|
||||||
import { ProfileResolver } from './services/profile.resolver';
|
|
||||||
import { LoginComponent } from './components/login/login.component';
|
import { LoginComponent } from './components/login/login.component';
|
||||||
import { AppAuthGuard } from './guards/auth.guard';
|
import { AppAuthGuard } from './guards/auth.guard';
|
||||||
import { AppSharedRuleGuard } from './guards/shared.guard';
|
import { AppSharedRuleGuard } from './guards/shared.guard';
|
||||||
@@ -55,9 +54,6 @@ export const APP_ROUTES: Routes = [
|
|||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
component: LayoutComponent,
|
component: LayoutComponent,
|
||||||
resolve: {
|
|
||||||
profile: ProfileResolver
|
|
||||||
},
|
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
|
@@ -29,7 +29,6 @@ import { Route } from '@angular/router';
|
|||||||
import { AppStore, RepositoryState } from '../store/states';
|
import { AppStore, RepositoryState } from '../store/states';
|
||||||
import { ruleContext } from '../store/selectors/app.selectors';
|
import { ruleContext } from '../store/selectors/app.selectors';
|
||||||
import { NodePermissionService } from '../services/node-permission.service';
|
import { NodePermissionService } from '../services/node-permission.service';
|
||||||
import { ProfileResolver } from '../services/profile.resolver';
|
|
||||||
import {
|
import {
|
||||||
SelectionState,
|
SelectionState,
|
||||||
NavigationState,
|
NavigationState,
|
||||||
@@ -224,7 +223,6 @@ export class AppExtensionService implements RuleContext {
|
|||||||
component: this.getComponentById(route.layout || this.defaults.layout),
|
component: this.getComponentById(route.layout || this.defaults.layout),
|
||||||
canActivateChild: guards,
|
canActivateChild: guards,
|
||||||
canActivate: guards,
|
canActivate: guards,
|
||||||
resolve: { profile: ProfileResolver },
|
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: '',
|
path: '',
|
||||||
|
@@ -25,21 +25,21 @@
|
|||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { AuthenticationService } from '@alfresco/adf-core';
|
import { AuthenticationService } from '@alfresco/adf-core';
|
||||||
import { Observable, of } from 'rxjs';
|
import { Observable, BehaviorSubject } from 'rxjs';
|
||||||
import { take } from 'rxjs/operators';
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class AppService {
|
export class AppService {
|
||||||
constructor(private auth: AuthenticationService) {}
|
private ready: BehaviorSubject<boolean>;
|
||||||
|
ready$: Observable<boolean>;
|
||||||
|
|
||||||
waitForAuth(): Observable<any> {
|
constructor(auth: AuthenticationService) {
|
||||||
const isLoggedIn = this.auth.isLoggedIn();
|
this.ready = new BehaviorSubject(auth.isLoggedIn());
|
||||||
if (isLoggedIn) {
|
this.ready$ = this.ready.asObservable();
|
||||||
return of(true);
|
|
||||||
} else {
|
auth.onLogin.subscribe(e => {
|
||||||
return this.auth.onLogin.pipe(take(1));
|
this.ready.next(true);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,32 +0,0 @@
|
|||||||
/*!
|
|
||||||
* @license
|
|
||||||
* Alfresco Example Content Application
|
|
||||||
*
|
|
||||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
|
||||||
*
|
|
||||||
* This file is part of the Alfresco Example Content Application.
|
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
|
||||||
* provided under the following open source license terms:
|
|
||||||
*
|
|
||||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { ProfileResolver } from './profile.resolver';
|
|
||||||
|
|
||||||
describe('ProfileResolver', () => {
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(ProfileResolver).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,63 +0,0 @@
|
|||||||
/*!
|
|
||||||
* @license
|
|
||||||
* Alfresco Example Content Application
|
|
||||||
*
|
|
||||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
|
||||||
*
|
|
||||||
* This file is part of the Alfresco Example Content Application.
|
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
|
||||||
* provided under the following open source license terms:
|
|
||||||
*
|
|
||||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Store } from '@ngrx/store';
|
|
||||||
import { Injectable } from '@angular/core';
|
|
||||||
import { Resolve, Router } from '@angular/router';
|
|
||||||
import { Person } from 'alfresco-js-api';
|
|
||||||
import { Observable } from 'rxjs';
|
|
||||||
import { AppStore } from '../store/states/app.state';
|
|
||||||
import { SetUserProfileAction } from '../store/actions';
|
|
||||||
import { ContentApiService } from './content-api.service';
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class ProfileResolver implements Resolve<Person> {
|
|
||||||
constructor(
|
|
||||||
private store: Store<AppStore>,
|
|
||||||
private contentApi: ContentApiService,
|
|
||||||
private router: Router
|
|
||||||
) {}
|
|
||||||
|
|
||||||
resolve(): Observable<Person> {
|
|
||||||
return new Observable(observer => {
|
|
||||||
this.contentApi.getPerson('-me-').subscribe(
|
|
||||||
person => {
|
|
||||||
this.store.dispatch(new SetUserProfileAction(person.entry));
|
|
||||||
observer.next(person.entry);
|
|
||||||
observer.complete();
|
|
||||||
},
|
|
||||||
err => {
|
|
||||||
if (err && err.status === 401) {
|
|
||||||
observer.next(null);
|
|
||||||
observer.complete();
|
|
||||||
this.router.navigate(['login']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user