Project

General

Profile

« Previous | Next » 

Revision 54912

[Trunk|Library]: CanLoad does not work in connect guards, maybe it works in angular 6

View differences:

connectAdminLoginGuard.guard.ts
7 7
  ActivatedRoute,
8 8
  CanLoad, Route
9 9
} from '@angular/router';
10
import {Observable}       from 'rxjs/Observable';
10
import {Observable} from 'rxjs/Observable';
11 11
import {Session} from '../../login/utils/helper.class';
12 12
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
13 13
import {CommunityService} from '../community/community.service';
14 14
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
15
import { mergeMap } from 'rxjs/operators';
16 15

  
17 16
@Injectable()
18 17
export class ConnectAdminLoginGuard implements CanActivate, CanLoad{
19 18
  constructor(private router: Router,
20 19
              private communityService: CommunityService,
21
              private propertiesService:EnvironmentSpecificService,
22
              private route: ActivatedRoute) {}
20
              private propertiesService: EnvironmentSpecificService) {}
23 21

  
24
  check(path: string): Observable<boolean> | boolean {
22
  check(route: ActivatedRouteSnapshot, path: string): Observable<boolean> | boolean {
25 23
    let errorCode = LoginErrorCodes.NOT_LOGIN;
26
    let community = this.route.queryParams["communityId"];
24
    const community = route.queryParams['communityId'];
27 25
    if (Session.isLoggedIn()) {
28 26
      if (Session.isPortalAdministrator() || Session.isCommunityCurator()) {
29 27
        return true;
30 28
      } else {
31
        let obs = this.propertiesService.subscribeEnvironment().map(res => res).mergeMap(properties => {
32
          return this.communityService.iscommunityManager(properties, properties["communityAPI"] + community, Session.getUserEmail())
29
        const obs = this.propertiesService.subscribeEnvironment().map(res => res).mergeMap(properties => {
30
          return this.communityService.iscommunityManager(properties, properties['communityAPI'] + community, Session.getUserEmail());
33 31
        });
34 32
        obs.filter(enabled => !enabled)
35 33
            .subscribe(() => this.router.navigate(['/user-info'], {
36 34
              queryParams: {
37
                "errorCode": errorCode,
38
                "redirectUrl": path
35
                'errorCode': errorCode,
36
                'redirectUrl': path
39 37
              }
40 38
            }));
41 39
        return obs;
42 40
      }
43 41
    } else {
44 42
      errorCode = LoginErrorCodes.NOT_LOGIN;
45
      this.router.navigate(['/user-info'], {queryParams: {"errorCode": errorCode, "redirectUrl": path}});
43
      this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl': path}});
46 44

  
47 45
      return false;
48 46
    }
49 47
  }
50 48

  
51 49
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
52
    return this.check(state.url);
50
    return this.check(route, state.url);
53 51
  }
54 52

  
55 53
  canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
56
    return this.check('/' + route.path);
54
    return this.check(null, '/' + route.path);
57 55
  }
58 56
}

Also available in: Unified diff