<commit_before>import { Injectable } from '@angular/core';
import {
  ActivatedRouteSnapshot,
  CanActivate,
  CanActivateChild,
  Router, RouterStateSnapshot
} from '@angular/router';
import {Observable} from 'rxjs/Observable';

import {ProfileStorageService} from 'app/services/profile-storage.service';
import {ServerConfigService} from 'app/services/server-config.service';
import {hasRegisteredAccess} from 'app/utils';


@Injectable()
export class RegistrationGuard implements CanActivate, CanActivateChild {
  constructor(
    private serverConfigService: ServerConfigService,
    private profileStorageService: ProfileStorageService,
    private router: Router) {}

  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
    if (route.routeConfig.path === 'nih-callback' ||
        route.routeConfig.path === '' ||
        route.routeConfig.path.startsWith('admin/')) {
      // Leave /admin unguarded in order to allow bootstrapping of verified users.
      return Observable.from([true]);
    }
    return this.serverConfigService.getConfig()
      .flatMap((config) => {
        if (!config.enforceRegistered) {
          return Observable.from([true]);
        }
        return this.profileStorageService.profile$.flatMap((profile) => {
          if (hasRegisteredAccess(profile.dataAccessLevel)) {
            return Observable.from([true]);
          } else {
            this.router.navigate(['/']);
            return Observable.from([false]);
          }
        });
      });
  }

  canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
    return this.canActivate(route, state);
  }
}
<commit_msg>[RW-2627][Risk=low] Allow access to data use agreement when not registered (#2117)<commit_after>import { Injectable } from '@angular/core';
import {
  ActivatedRouteSnapshot,
  CanActivate,
  CanActivateChild,
  Router, RouterStateSnapshot
} from '@angular/router';
import {Observable} from 'rxjs/Observable';

import {ProfileStorageService} from 'app/services/profile-storage.service';
import {ServerConfigService} from 'app/services/server-config.service';
import {hasRegisteredAccess} from 'app/utils';


@Injectable()
export class RegistrationGuard implements CanActivate, CanActivateChild {
  constructor(
    private serverConfigService: ServerConfigService,
    private profileStorageService: ProfileStorageService,
    private router: Router) {}

  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
    if (route.routeConfig.path === 'nih-callback' ||
        route.routeConfig.path === '' ||
        route.routeConfig.path.startsWith('admin/') ||
        route.routeConfig.path.startsWith('data-use-agreement')) {
      // Leave /admin unguarded in order to allow bootstrapping of verified users.
      return Observable.from([true]);
    }
    return this.serverConfigService.getConfig()
      .flatMap((config) => {
        if (!config.enforceRegistered) {
          return Observable.from([true]);
        }
        return this.profileStorageService.profile$.flatMap((profile) => {
          if (hasRegisteredAccess(profile.dataAccessLevel)) {
            return Observable.from([true]);
          } else {
            this.router.navigate(['/']);
            return Observable.from([false]);
          }
        });
      });
  }

  canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
    return this.canActivate(route, state);
  }
}

{'fraction_non_alphanumeric': 0.11977401129943503, 'fraction_numerical': 0.0022598870056497176, 'mean_word_length': 3.690066225165563, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6073715', 'n_tokens_mistral': 967, 'n_tokens_neox': 952, 'n_words': 197}