From a1245fdc67e4d3a97b4aa7fabad6b6a87e967dfe Mon Sep 17 00:00:00 2001 From: Travis Date: Mon, 9 Sep 2024 12:11:52 -0700 Subject: [PATCH 1/4] start by checking referrer --- ui/src/app/app.component.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/src/app/app.component.ts b/ui/src/app/app.component.ts index 6c60493..c17fbc8 100644 --- a/ui/src/app/app.component.ts +++ b/ui/src/app/app.component.ts @@ -37,6 +37,7 @@ export class AppComponent implements OnInit { ngOnInit(): void { this.admin_url = `${environment.local_service_endpoint}/admin/`; this.config = this.userConfig.config; + console.log('referrer', document.referrer); } logout() { From 72323443449cde7c48156e76b5ae23bfd581145c Mon Sep 17 00:00:00 2001 From: Travis Date: Mon, 9 Sep 2024 14:49:36 -0700 Subject: [PATCH 2/4] add redirect notifications to UI and admin --- AGOLAccountRequestor/settings.py | 1 + AGOLAccountRequestor/views.py | 27 +++++++++++++++++++++++++++ ui/src/app/app.component.ts | 19 ++++++++++++++++--- ui/src/styles.css | 3 +++ 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/AGOLAccountRequestor/settings.py b/AGOLAccountRequestor/settings.py index 840685f..84c97bc 100644 --- a/AGOLAccountRequestor/settings.py +++ b/AGOLAccountRequestor/settings.py @@ -59,6 +59,7 @@ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'AGOLAccountRequestor.views.redirect_middleware' ] ROOT_URLCONF = 'AGOLAccountRequestor.urls' diff --git a/AGOLAccountRequestor/views.py b/AGOLAccountRequestor/views.py index c1c388c..7f2114c 100644 --- a/AGOLAccountRequestor/views.py +++ b/AGOLAccountRequestor/views.py @@ -9,6 +9,8 @@ from rest_framework.response import Response from django.conf import settings from django.views.decorators.csrf import ensure_csrf_cookie +from django.contrib import messages +from django.shortcuts import redirect logger = logging.getLogger('django') @@ -81,3 +83,28 @@ def email_field_coordinator_request(request): def error_test(request): raise Exception("this should log") + + + +def redirect_middleware(get_response): + # One-time configuration and initialization. + + def middleware(request): + # Code to be executed for each request before + # the view (and later middleware) are called. + if 'redirect' in request.GET: + query_string = request.GET.copy() + del query_string['redirect'] + + messages.add_message(request, messages.WARNING, "The Account Request Tool has a new home. Please update your bookmarks to https://gpdashboard.epa.gov/request/") + path = f'{request.path}?{query_string.urlencode()}' if query_string else request.path + response = redirect(path) + else: + response = get_response(request) + + # Code to be executed for each request/response after + # the view is called. + + return response + + return middleware diff --git a/ui/src/app/app.component.ts b/ui/src/app/app.component.ts index c17fbc8..c11bdbd 100644 --- a/ui/src/app/app.component.ts +++ b/ui/src/app/app.component.ts @@ -4,7 +4,8 @@ import {BehaviorSubject, Observable, ReplaySubject, Subject} from 'rxjs'; import {NavigationEnd, Router, ActivatedRoute} from '@angular/router'; import {UserConfig, UserConfigService} from './auth/user-config.service'; import {environment} from '../environments/environment'; -import {filter} from 'rxjs/operators'; +import {filter, tap} from 'rxjs/operators'; +import {MatLegacySnackBar as MatSnackBar} from '@angular/material/legacy-snack-bar'; declare var gtag; @@ -21,7 +22,8 @@ export class AppComponent implements OnInit { public loginService: LoginService, public router: Router, public route: ActivatedRoute, - public userConfig: UserConfigService + public userConfig: UserConfigService, + public snackBar: MatSnackBar ) { const navEndEvent$ = router.events.pipe( filter(e => e instanceof NavigationEnd) @@ -37,7 +39,10 @@ export class AppComponent implements OnInit { ngOnInit(): void { this.admin_url = `${environment.local_service_endpoint}/admin/`; this.config = this.userConfig.config; - console.log('referrer', document.referrer); + this.route.queryParams.pipe( + filter(q => 'redirect' in q), + tap(() => this.open_redirect_message()) + ).subscribe() } logout() { @@ -50,4 +55,12 @@ export class AppComponent implements OnInit { close_warning() { this.router.navigate([]); } + + open_redirect_message() { + // this.router.navigate([], {queryParams: {redirect: null}, queryParamsHandling: 'merge'}) + this.snackBar.open( + 'The Account Request Tool has a new home. Please update your bookmarks to https://gpdashboard.epa.gov/request/', + 'Dismiss', + {verticalPosition: 'top', panelClass: ['snackbar-error']}) + } } diff --git a/ui/src/styles.css b/ui/src/styles.css index 3619670..a7851c7 100644 --- a/ui/src/styles.css +++ b/ui/src/styles.css @@ -114,6 +114,9 @@ mat-list-item.filter-btn div { .snackbar-error { background-color: darkorange !important; color: black !important; + .mat-simple-snackbar-action { + color: black; + } } div.mat-dialog-actions { From 82a491c37ecb8b19ad4efd41fe5346aa60c9e903 Mon Sep 17 00:00:00 2001 From: Travis Date: Mon, 9 Sep 2024 14:53:25 -0700 Subject: [PATCH 3/4] fix broken test --- ui/src/app/app.component.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/src/app/app.component.spec.ts b/ui/src/app/app.component.spec.ts index 73214d9..bfab3f4 100644 --- a/ui/src/app/app.component.spec.ts +++ b/ui/src/app/app.component.spec.ts @@ -6,6 +6,7 @@ import {LoginService} from './auth/login.service'; import {HttpClientTestingModule} from '@angular/common/http/testing'; import {MatToolbarModule} from '@angular/material/toolbar'; import {MatIconModule} from '@angular/material/icon'; +import {MatLegacySnackBarModule} from '@angular/material/legacy-snack-bar'; describe('AppComponent', () => { beforeEach(async(() => { @@ -14,7 +15,8 @@ describe('AppComponent', () => { RouterTestingModule, HttpClientTestingModule, MatToolbarModule, - MatIconModule + MatIconModule, + MatLegacySnackBarModule ], declarations: [ AppComponent From 8f61a104fe36f869c5dd72093a099a13e93d187b Mon Sep 17 00:00:00 2001 From: Travis Date: Mon, 9 Sep 2024 15:06:34 -0700 Subject: [PATCH 4/4] needed that --- ui/src/app/app.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/app/app.component.ts b/ui/src/app/app.component.ts index c11bdbd..9081a3e 100644 --- a/ui/src/app/app.component.ts +++ b/ui/src/app/app.component.ts @@ -57,7 +57,7 @@ export class AppComponent implements OnInit { } open_redirect_message() { - // this.router.navigate([], {queryParams: {redirect: null}, queryParamsHandling: 'merge'}) + this.router.navigate([], {queryParams: {redirect: null}, queryParamsHandling: 'merge'}) this.snackBar.open( 'The Account Request Tool has a new home. Please update your bookmarks to https://gpdashboard.epa.gov/request/', 'Dismiss',