You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by bo...@apache.org on 2023/01/02 18:18:55 UTC
[streampipes] 02/03: add linting to enums guards (#877)
This is an automated email from the ASF dual-hosted git repository.
bossenti pushed a commit to branch chore/ui-linting
in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit c2e0811c062c29ffcd6c0be074accf80abe98907
Author: bossenti <bo...@posteo.de>
AuthorDate: Mon Jan 2 19:17:48 2023 +0100
add linting to enums guards (#877)
---
ui/.eslintignore | 1 -
ui/.prettierignore | 1 -
.../already-configured.can-activate.guard.ts | 20 ++++----
.../_guards/auth.can-activate-children.guard.ts | 33 +++++++------
.../_guards/base-configured.can-activate.guard.ts | 54 +++++++++++++---------
.../app/_guards/configured.can-activate.guard.ts | 21 ++++-----
ui/src/app/_guards/page-auth.can-active.guard.ts | 18 ++++----
.../registration-allowed.can-activate.guard.ts | 37 +++++++++------
.../restore-password-allowed.can-activate.guard.ts | 37 +++++++++------
9 files changed, 122 insertions(+), 100 deletions(-)
diff --git a/ui/.eslintignore b/ui/.eslintignore
index 4f9dc56c8..877a18339 100644
--- a/ui/.eslintignore
+++ b/ui/.eslintignore
@@ -19,7 +19,6 @@ dist
# Remove these in the future to lint additional modules
# Please also see .prettierignore
projects
-src/app/_guards
src/app/_models
src/app/add
src/app/apidocs
diff --git a/ui/.prettierignore b/ui/.prettierignore
index f5743c083..dd6aaaa7d 100644
--- a/ui/.prettierignore
+++ b/ui/.prettierignore
@@ -19,7 +19,6 @@ dist
# Remove these in the future to format additional modules
# Please also see .eslintignore
projects
-src/app/_guards
src/app/_models
src/app/add
src/app/apidocs
diff --git a/ui/src/app/_guards/already-configured.can-activate.guard.ts b/ui/src/app/_guards/already-configured.can-activate.guard.ts
index 5d51100d8..49cdd2830 100644
--- a/ui/src/app/_guards/already-configured.can-activate.guard.ts
+++ b/ui/src/app/_guards/already-configured.can-activate.guard.ts
@@ -23,17 +23,15 @@ import { BaseConfiguredCanActivateGuard } from './base-configured.can-activate.g
@Injectable()
export class AlreadyConfiguredCanActivateGuard extends BaseConfiguredCanActivateGuard {
+ constructor(router: Router, authService: AuthService) {
+ super(router, authService);
+ }
- constructor(router: Router,
- authService: AuthService) {
- super(router, authService);
- }
+ onIsConfigured(): boolean | UrlTree {
+ return this.router.parseUrl('login');
+ }
- onIsConfigured(): boolean | UrlTree {
- return this.router.parseUrl('login');
- }
-
- onIsUnconfigured(): boolean | UrlTree {
- return true;
- }
+ onIsUnconfigured(): boolean | UrlTree {
+ return true;
+ }
}
diff --git a/ui/src/app/_guards/auth.can-activate-children.guard.ts b/ui/src/app/_guards/auth.can-activate-children.guard.ts
index 7677ed570..cad3cf7ac 100644
--- a/ui/src/app/_guards/auth.can-activate-children.guard.ts
+++ b/ui/src/app/_guards/auth.can-activate-children.guard.ts
@@ -18,28 +18,27 @@
import { Injectable } from '@angular/core';
import {
- ActivatedRouteSnapshot,
- CanActivateChild,
- Router,
- RouterStateSnapshot
+ ActivatedRouteSnapshot,
+ CanActivateChild,
+ Router,
+ RouterStateSnapshot,
} from '@angular/router';
import { AuthService } from '../services/auth.service';
@Injectable()
export class AuthCanActivateChildrenGuard implements CanActivateChild {
+ constructor(private authService: AuthService, private router: Router) {}
- constructor(private authService: AuthService,
- private router: Router) {
- }
+ canActivateChild(
+ childRoute: ActivatedRouteSnapshot,
+ state: RouterStateSnapshot,
+ ): boolean {
+ if (this.authService.authenticated()) {
+ return true;
+ }
+ this.authService.logout();
+ this.router.navigate(['/login']);
- canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
- if (this.authService.authenticated()) {
- return true;
- }
- this.authService.logout();
- this.router.navigate(['/login']);
-
- return false;
-
- }
+ return false;
+ }
}
diff --git a/ui/src/app/_guards/base-configured.can-activate.guard.ts b/ui/src/app/_guards/base-configured.can-activate.guard.ts
index 4b28598b7..4310328b6 100644
--- a/ui/src/app/_guards/base-configured.can-activate.guard.ts
+++ b/ui/src/app/_guards/base-configured.can-activate.guard.ts
@@ -17,34 +17,44 @@
*/
import {
- ActivatedRouteSnapshot,
- CanActivate,
- Router,
- RouterStateSnapshot,
- UrlTree
+ ActivatedRouteSnapshot,
+ CanActivate,
+ Router,
+ RouterStateSnapshot,
+ UrlTree,
} from '@angular/router';
import { Observable } from 'rxjs';
import { AuthService } from '../services/auth.service';
export abstract class BaseConfiguredCanActivateGuard implements CanActivate {
+ constructor(protected router: Router, protected authService: AuthService) {}
- constructor(protected router: Router,
- protected authService: AuthService) { }
+ canActivate(
+ route: ActivatedRouteSnapshot,
+ state: RouterStateSnapshot,
+ ):
+ | Observable<boolean | UrlTree>
+ | Promise<boolean | UrlTree>
+ | boolean
+ | UrlTree {
+ return new Promise(resolve =>
+ this.authService.checkConfiguration().subscribe(
+ configured => {
+ if (!configured) {
+ resolve(this.onIsUnconfigured());
+ } else {
+ resolve(this.onIsConfigured());
+ }
+ },
+ error => {
+ const url = this.router.parseUrl('startup');
+ resolve(url);
+ },
+ ),
+ );
+ }
- canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
- return new Promise((resolve) => this.authService.checkConfiguration().subscribe((configured) => {
- if (!configured) {
- resolve(this.onIsUnconfigured());
- } else {
- resolve(this.onIsConfigured());
- }
- }, error => {
- const url = this.router.parseUrl('startup');
- resolve(url);
- }));
- }
+ abstract onIsConfigured(): boolean | UrlTree;
- abstract onIsConfigured(): boolean | UrlTree;
-
- abstract onIsUnconfigured(): boolean | UrlTree;
+ abstract onIsUnconfigured(): boolean | UrlTree;
}
diff --git a/ui/src/app/_guards/configured.can-activate.guard.ts b/ui/src/app/_guards/configured.can-activate.guard.ts
index c787a6001..fc1e47cb6 100644
--- a/ui/src/app/_guards/configured.can-activate.guard.ts
+++ b/ui/src/app/_guards/configured.can-activate.guard.ts
@@ -23,18 +23,15 @@ import { BaseConfiguredCanActivateGuard } from './base-configured.can-activate.g
@Injectable()
export class ConfiguredCanActivateGuard extends BaseConfiguredCanActivateGuard {
+ constructor(router: Router, authService: AuthService) {
+ super(router, authService);
+ }
- constructor(router: Router,
- authService: AuthService) {
- super(router, authService);
- }
-
- onIsConfigured(): boolean | UrlTree {
- return true;
- }
-
- onIsUnconfigured(): boolean | UrlTree {
- return this.router.parseUrl('setup');
- }
+ onIsConfigured(): boolean | UrlTree {
+ return true;
+ }
+ onIsUnconfigured(): boolean | UrlTree {
+ return this.router.parseUrl('setup');
+ }
}
diff --git a/ui/src/app/_guards/page-auth.can-active.guard.ts b/ui/src/app/_guards/page-auth.can-active.guard.ts
index 2370ebba3..f1acc2320 100644
--- a/ui/src/app/_guards/page-auth.can-active.guard.ts
+++ b/ui/src/app/_guards/page-auth.can-active.guard.ts
@@ -16,20 +16,22 @@
*
*/
-import { ActivatedRouteSnapshot, CanActivateChild, Router } from '@angular/router';
+import {
+ ActivatedRouteSnapshot,
+ CanActivateChild,
+ Router,
+} from '@angular/router';
import { AuthService } from '../services/auth.service';
import { PageName } from '../_enums/page-name.enum';
import { Injectable } from '@angular/core';
@Injectable()
export class PageAuthGuard implements CanActivateChild {
+ constructor(private router: Router, private authService: AuthService) {}
- constructor(private router: Router,
- private authService: AuthService) {}
+ canActivateChild(activatedRouteSnapshot: ActivatedRouteSnapshot): boolean {
+ const pageNames: PageName[] = activatedRouteSnapshot.data.authPageNames;
- canActivateChild(activatedRouteSnapshot: ActivatedRouteSnapshot): boolean {
- const pageNames: PageName[] = activatedRouteSnapshot.data.authPageNames;
-
- return this.authService.isAnyAccessGranted(pageNames, true);
- }
+ return this.authService.isAnyAccessGranted(pageNames, true);
+ }
}
diff --git a/ui/src/app/_guards/registration-allowed.can-activate.guard.ts b/ui/src/app/_guards/registration-allowed.can-activate.guard.ts
index dbd48679e..61b91438f 100644
--- a/ui/src/app/_guards/registration-allowed.can-activate.guard.ts
+++ b/ui/src/app/_guards/registration-allowed.can-activate.guard.ts
@@ -18,11 +18,11 @@
import { Injectable } from '@angular/core';
import {
- ActivatedRouteSnapshot,
- CanActivate,
- Router,
- RouterStateSnapshot,
- UrlTree
+ ActivatedRouteSnapshot,
+ CanActivate,
+ Router,
+ RouterStateSnapshot,
+ UrlTree,
} from '@angular/router';
import { LoginService } from '../login/services/login.service';
import { Observable } from 'rxjs';
@@ -30,15 +30,22 @@ import { map } from 'rxjs/operators';
@Injectable()
export class RegistrationAllowedCanActivateGuard implements CanActivate {
+ constructor(private router: Router, private loginService: LoginService) {}
- constructor(private router: Router,
- private loginService: LoginService) {
- }
-
- canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
- return this.loginService.fetchLoginSettings().pipe(map(config => {
- return config.allowSelfRegistration ? true : this.router.parseUrl('register');
- }));
- }
-
+ canActivate(
+ route: ActivatedRouteSnapshot,
+ state: RouterStateSnapshot,
+ ):
+ | Observable<boolean | UrlTree>
+ | Promise<boolean | UrlTree>
+ | boolean
+ | UrlTree {
+ return this.loginService.fetchLoginSettings().pipe(
+ map(config => {
+ return config.allowSelfRegistration
+ ? true
+ : this.router.parseUrl('register');
+ }),
+ );
+ }
}
diff --git a/ui/src/app/_guards/restore-password-allowed.can-activate.guard.ts b/ui/src/app/_guards/restore-password-allowed.can-activate.guard.ts
index 8be421ba8..0499d21fa 100644
--- a/ui/src/app/_guards/restore-password-allowed.can-activate.guard.ts
+++ b/ui/src/app/_guards/restore-password-allowed.can-activate.guard.ts
@@ -18,11 +18,11 @@
import { Injectable } from '@angular/core';
import {
- ActivatedRouteSnapshot,
- CanActivate,
- Router,
- RouterStateSnapshot,
- UrlTree
+ ActivatedRouteSnapshot,
+ CanActivate,
+ Router,
+ RouterStateSnapshot,
+ UrlTree,
} from '@angular/router';
import { LoginService } from '../login/services/login.service';
import { Observable } from 'rxjs';
@@ -30,13 +30,24 @@ import { map } from 'rxjs/operators';
@Injectable()
export class RestorePasswordAllowedCanActivateGuard implements CanActivate {
+ constructor(private router: Router, private loginService: LoginService) {}
- constructor(private router: Router,
- private loginService: LoginService) {
- }
-
- canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
- return this.loginService.fetchLoginSettings().pipe(map(config => config.allowPasswordRecovery ? true : this.router.parseUrl('login')));
- }
-
+ canActivate(
+ route: ActivatedRouteSnapshot,
+ state: RouterStateSnapshot,
+ ):
+ | Observable<boolean | UrlTree>
+ | Promise<boolean | UrlTree>
+ | boolean
+ | UrlTree {
+ return this.loginService
+ .fetchLoginSettings()
+ .pipe(
+ map(config =>
+ config.allowPasswordRecovery
+ ? true
+ : this.router.parseUrl('login'),
+ ),
+ );
+ }
}