From 1cc302df0ad02ddf0dfafff88e1bf79ce01f1de0 Mon Sep 17 00:00:00 2001 From: Ludek <13610612+ludeknovy@users.noreply.github.com> Date: Sat, 20 Feb 2021 20:29:03 +0100 Subject: [PATCH] share test run (#95) --- src/app/_interceptors/error-interceptor.ts | 7 +- src/app/app.module.ts | 8 ++- src/app/auth.guard.ts | 5 ++ .../item-detail/item-detail.component.html | 9 +-- src/app/item-detail/item-detail.component.ts | 17 ++++- .../create-new-share-link.component.css | 3 + .../create-new-share-link.component.html | 33 +++++++++ .../create-new-share-link.component.spec.ts | 32 +++++++++ .../create-new-share-link.component.ts | 67 +++++++++++++++++ .../delete-share-link.component.css | 3 + .../delete-share-link.component.html | 35 +++++++++ .../delete-share-link.component.spec.ts | 32 +++++++++ .../delete-share-link.component.ts | 72 +++++++++++++++++++ src/app/item-detail/share/share.component.css | 10 +++ .../item-detail/share/share.component.html | 63 ++++++++++++++++ .../item-detail/share/share.component.spec.ts | 40 +++++++++++ src/app/item-detail/share/share.component.ts | 50 +++++++++++++ src/app/items-api.service.ts | 22 +++++- src/app/items.service.ts | 7 ++ src/app/notification/notification-messages.ts | 8 +++ .../external-notification.component.ts | 6 +- 21 files changed, 513 insertions(+), 16 deletions(-) create mode 100644 src/app/item-detail/share/create-new-share-link/create-new-share-link.component.css create mode 100644 src/app/item-detail/share/create-new-share-link/create-new-share-link.component.html create mode 100644 src/app/item-detail/share/create-new-share-link/create-new-share-link.component.spec.ts create mode 100644 src/app/item-detail/share/create-new-share-link/create-new-share-link.component.ts create mode 100644 src/app/item-detail/share/delete-share-link/delete-share-link.component.css create mode 100644 src/app/item-detail/share/delete-share-link/delete-share-link.component.html create mode 100644 src/app/item-detail/share/delete-share-link/delete-share-link.component.spec.ts create mode 100644 src/app/item-detail/share/delete-share-link/delete-share-link.component.ts create mode 100644 src/app/item-detail/share/share.component.css create mode 100644 src/app/item-detail/share/share.component.html create mode 100644 src/app/item-detail/share/share.component.spec.ts create mode 100644 src/app/item-detail/share/share.component.ts diff --git a/src/app/_interceptors/error-interceptor.ts b/src/app/_interceptors/error-interceptor.ts index f0f00f0d..8564e701 100644 --- a/src/app/_interceptors/error-interceptor.ts +++ b/src/app/_interceptors/error-interceptor.ts @@ -3,18 +3,21 @@ import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/c import { Observable, throwError } from 'rxjs'; import { catchError } from 'rxjs/operators'; import { AuthenticationService } from '../_services/authentication.service'; +import {Router} from '@angular/router'; @Injectable() export class ErrorInterceptor implements HttpInterceptor { - constructor(private authenticationService: AuthenticationService) { } + constructor( + private authenticationService: AuthenticationService, + private router: Router) { } intercept(request: HttpRequest, next: HttpHandler): Observable> { return next.handle(request).pipe(catchError(err => { if (err.status === 401) { // auto logout if 401 response returned from api this.authenticationService.logout(); - // location.reload(true); + this.router.navigate(['login']); } const error = err.error.message || err.statusText; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 526106ec..7f98ea7b 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -56,6 +56,9 @@ import { AddNewExternalNotificationComponent } from './scenario/external-notific // tslint:disable-next-line:max-line-length import { DeleteExternalNotificationComponent } from './scenario/external-notification/delete-external-notification/delete-external-notification.component'; import { ItemControlsComponent } from './scenario/item-controls/item-controls.component'; +import { ShareComponent } from './item-detail/share/share.component'; +import { CreateNewShareLinkComponent } from './item-detail/share/create-new-share-link/create-new-share-link.component'; +import { DeleteShareLinkComponent } from './item-detail/share/delete-share-link/delete-share-link.component'; const appRoutes: Routes = [ { path: 'dashboard', component: DashboardComponent, canActivate: [AuthGuard] }, @@ -78,7 +81,7 @@ const appRoutes: Routes = [ }, { path: 'project/:projectName/scenario/:scenarioName/item/:id', component: ItemDetailComponent, - runGuardsAndResolvers: 'always', canActivate: [AuthGuard] + runGuardsAndResolvers: 'always', canActivate: [AuthGuard], }, { path: 'project/:projectName/scenarios', component: ScenariosComponent, @@ -132,6 +135,9 @@ const appRoutes: Routes = [ AddNewExternalNotificationComponent, DeleteExternalNotificationComponent, ItemControlsComponent, + ShareComponent, + CreateNewShareLinkComponent, + DeleteShareLinkComponent, ], imports: [ RouterModule.forRoot( diff --git a/src/app/auth.guard.ts b/src/app/auth.guard.ts index af54acc6..efa7873a 100644 --- a/src/app/auth.guard.ts +++ b/src/app/auth.guard.ts @@ -11,6 +11,11 @@ export class AuthGuard implements CanActivate { ) { } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { + + const { token } = route.queryParams; + if (token) { + return true; + } if (localStorage.getItem('currentUser')) { // logged in so return true this.authService.setLogin(true); diff --git a/src/app/item-detail/item-detail.component.html b/src/app/item-detail/item-detail.component.html index 94a0da51..8bac28cb 100644 --- a/src/app/item-detail/item-detail.component.html +++ b/src/app/item-detail/item-detail.component.html @@ -1,4 +1,4 @@ - +