From b568ef6ba4e3cbc6699a5eef8147cea1b9e5b400 Mon Sep 17 00:00:00 2001 From: Noah Date: Tue, 21 Oct 2025 20:55:58 -0400 Subject: [PATCH 1/5] added modal for viewing status from url params --- eac/static/actions.js | 2 +- eac/static/status.js | 20 ++++++++++++++++++++ eac/templates/home.html | 17 +++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 eac/static/status.js diff --git a/eac/static/actions.js b/eac/static/actions.js index c278f1c..e20a118 100644 --- a/eac/static/actions.js +++ b/eac/static/actions.js @@ -4,7 +4,7 @@ for (const control of controls) { const serviceName = control.dataset.service; - const endpoint = window.location + serviceName; + const endpoint = serviceName; const unlink = control.dataset.action === "unlink"; control.addEventListener('click', () => { diff --git a/eac/static/status.js b/eac/static/status.js new file mode 100644 index 0000000..0238d05 --- /dev/null +++ b/eac/static/status.js @@ -0,0 +1,20 @@ +const urlQuery = new URLSearchParams(window.location.search) +if (urlQuery.has('status')) { + const status = urlQuery.get('status') + const statusTitle = urlQuery.get('status-title') + + const modalEl = document.querySelector('#statusModal') + const modal = new bootstrap.Modal(modalEl) + + const modalCloseBtn = modalEl.querySelector('#statusCloseButton') + modalCloseBtn.addEventListener('click', () => modal.hide()) + + const modalTitle = modalEl.querySelector('.modal-title') + modalTitle.append(statusTitle) + + const modalBody = modalEl.querySelector('.modal-body') + modalBody.append(status) + + modal.show() +} + diff --git a/eac/templates/home.html b/eac/templates/home.html index 88446ab..f0ab0c3 100644 --- a/eac/templates/home.html +++ b/eac/templates/home.html @@ -94,9 +94,26 @@ {% endif %} + + + From 05211a303e31fc5bb2cf7afff688efd1a98e3bc8 Mon Sep 17 00:00:00 2001 From: Noah Date: Tue, 21 Oct 2025 21:34:49 -0400 Subject: [PATCH 2/5] status after clicking button --- eac/__init__.py | 7 ++++++- eac/static/actions.js | 38 +++++++++++++++++++++++++++++++------ eac/static/status.js | 20 ------------------- eac/templates/callback.html | 3 --- eac/templates/home.html | 1 - 5 files changed, 38 insertions(+), 31 deletions(-) delete mode 100644 eac/static/status.js diff --git a/eac/__init__.py b/eac/__init__.py index dd22928..f15e498 100644 --- a/eac/__init__.py +++ b/eac/__init__.py @@ -108,6 +108,11 @@ def _index() -> str: services=services) +@APP.route('/status') +@_AUTH.oidc_auth('default') +def _status() -> werkzeug.Response: + return render_template('callback.html'), 200 + @APP.route('/slack', methods=['GET']) @_AUTH.oidc_auth('default') def _auth_slack() -> werkzeug.Response: @@ -209,7 +214,7 @@ def _github_landing() -> tuple[str, int]: member = _LDAP.get_member(uid, uid=True) _link_github(github_username, github_id, member, user_token) - return render_template('callback.html'), 200 + return redirect('/status?status-title=Success&status=YIPPEE') def _get_github_jwt() -> str: diff --git a/eac/static/actions.js b/eac/static/actions.js index e20a118..63a5dda 100644 --- a/eac/static/actions.js +++ b/eac/static/actions.js @@ -1,5 +1,24 @@ -(function () { - const reload = () => window.location.reload(); +function showModal(statusTitle, status) { + const modalEl = document.querySelector('#statusModal') + const modal = new bootstrap.Modal(modalEl) + + const modalCloseBtn = modalEl.querySelector('#statusCloseButton') + modalCloseBtn.addEventListener('click', () => modal.hide()) + + const modalTitle = modalEl.querySelector('.modal-title') + modalTitle.append(statusTitle) + + const modalBody = modalEl.querySelector('.modal-body') + modalBody.append(status) + + modalEl.addEventListener('hidden.bs.modal', window.location.reload) + + modal.show() + + return modal; +} + +window.addEventListener('load', () => { const controls = document.querySelectorAll("button[data-service]"); for (const control of controls) { @@ -22,12 +41,19 @@ } else { const popup = window.open(endpoint, serviceName, "height=800,width=600"); const timer = setInterval(() => { - if (popup.closed) { - clearInterval(timer); - reload(); + if (popup.location.pathname == '/status') { + clearInterval(timer) + + const query = new URLSearchParams(popup.location.search) + popup.close() + + const statusTitle = query.get('status-title') + const status = query.get('status') + + showModal(statusTitle, status) } }, 500); } }); } -}()); +}); diff --git a/eac/static/status.js b/eac/static/status.js deleted file mode 100644 index 0238d05..0000000 --- a/eac/static/status.js +++ /dev/null @@ -1,20 +0,0 @@ -const urlQuery = new URLSearchParams(window.location.search) -if (urlQuery.has('status')) { - const status = urlQuery.get('status') - const statusTitle = urlQuery.get('status-title') - - const modalEl = document.querySelector('#statusModal') - const modal = new bootstrap.Modal(modalEl) - - const modalCloseBtn = modalEl.querySelector('#statusCloseButton') - modalCloseBtn.addEventListener('click', () => modal.hide()) - - const modalTitle = modalEl.querySelector('.modal-title') - modalTitle.append(statusTitle) - - const modalBody = modalEl.querySelector('.modal-body') - modalBody.append(status) - - modal.show() -} - diff --git a/eac/templates/callback.html b/eac/templates/callback.html index 80cfc54..d22b3db 100644 --- a/eac/templates/callback.html +++ b/eac/templates/callback.html @@ -2,9 +2,6 @@ Redirecting... - Success diff --git a/eac/templates/home.html b/eac/templates/home.html index f0ab0c3..5df4066 100644 --- a/eac/templates/home.html +++ b/eac/templates/home.html @@ -114,6 +114,5 @@

- From a3ae6135b616f9e6e1227a3a45ff623193b6cea3 Mon Sep 17 00:00:00 2001 From: Noah Date: Tue, 21 Oct 2025 23:12:07 -0400 Subject: [PATCH 3/5] status to display from api route --- eac/__init__.py | 15 +++++++++++---- eac/static/actions.js | 19 ++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/eac/__init__.py b/eac/__init__.py index f15e498..97ba7a4 100644 --- a/eac/__init__.py +++ b/eac/__init__.py @@ -9,7 +9,7 @@ import hmac from hashlib import sha1 import base64 -from typing import Any +from typing import Any, Union import jwt from requests.models import HTTPError @@ -110,9 +110,10 @@ def _index() -> str: @APP.route('/status') @_AUTH.oidc_auth('default') -def _status() -> werkzeug.Response: +def _status() -> tuple[str, int]: return render_template('callback.html'), 200 + @APP.route('/slack', methods=['GET']) @_AUTH.oidc_auth('default') def _auth_slack() -> werkzeug.Response: @@ -164,7 +165,7 @@ def _auth_github() -> werkzeug.Response: @APP.route('/github/return', methods=['GET']) @_AUTH.oidc_auth('default') -def _github_landing() -> tuple[str, int]: +def _github_landing() -> Union[werkzeug.Response, tuple[str, int]]: # Determine if we have a valid reason to do things state = request.args.get('state') if state != APP.config['STATE']: @@ -214,7 +215,13 @@ def _github_landing() -> tuple[str, int]: member = _LDAP.get_member(uid, uid=True) _link_github(github_username, github_id, member, user_token) - return redirect('/status?status-title=Success&status=YIPPEE') + status_title = 'Linked Github!' + status = f'Added {github_username} to CSH Github org, you do not have to accept the email invite' + + status_title_encoded = urllib.parse.quote(status_title, safe='') + status_encoded = urllib.parse.quote(status, safe='') + return redirect( + f'/status?status-title={status_title_encoded}&status={status_encoded}') def _get_github_jwt() -> str: diff --git a/eac/static/actions.js b/eac/static/actions.js index 63a5dda..34984d6 100644 --- a/eac/static/actions.js +++ b/eac/static/actions.js @@ -20,6 +20,7 @@ function showModal(statusTitle, status) { window.addEventListener('load', () => { const controls = document.querySelectorAll("button[data-service]"); + const reload = () => window.location.reload(); for (const control of controls) { const serviceName = control.dataset.service; @@ -41,16 +42,20 @@ window.addEventListener('load', () => { } else { const popup = window.open(endpoint, serviceName, "height=800,width=600"); const timer = setInterval(() => { - if (popup.location.pathname == '/status') { - clearInterval(timer) + try { + if (popup.location.pathname == '/status') { + clearInterval(timer) - const query = new URLSearchParams(popup.location.search) - popup.close() + const query = new URLSearchParams(popup.location.search) + popup.close() - const statusTitle = query.get('status-title') - const status = query.get('status') + const statusTitle = query.get('status-title') + const status = query.get('status') - showModal(statusTitle, status) + showModal(statusTitle, status) + } + } catch { + // do this because every time you try and access the location of a window with a different origin it errors } }, 500); } From 78e887e3e488f3f439fdfa42ae9a0075092edd17 Mon Sep 17 00:00:00 2001 From: Noah Date: Tue, 21 Oct 2025 23:47:37 -0400 Subject: [PATCH 4/5] fixed reloading when modal closes --- eac/static/actions.js | 9 ++++++++- eac/templates/home.html | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/eac/static/actions.js b/eac/static/actions.js index 34984d6..0bd3b51 100644 --- a/eac/static/actions.js +++ b/eac/static/actions.js @@ -11,7 +11,9 @@ function showModal(statusTitle, status) { const modalBody = modalEl.querySelector('.modal-body') modalBody.append(status) - modalEl.addEventListener('hidden.bs.modal', window.location.reload) + $("#statusModal").on("hidden.bs.modal", () => { + window.location.reload() + }) modal.show() @@ -42,6 +44,11 @@ window.addEventListener('load', () => { } else { const popup = window.open(endpoint, serviceName, "height=800,width=600"); const timer = setInterval(() => { + if (popup.closed) { + clearInterval(timer) + + reload() + } try { if (popup.location.pathname == '/status') { clearInterval(timer) diff --git a/eac/templates/home.html b/eac/templates/home.html index 5df4066..a99aee0 100644 --- a/eac/templates/home.html +++ b/eac/templates/home.html @@ -94,8 +94,8 @@ {% endif %} -