From 6fff141e4717fe44e739164304db585ddf6d2c91 Mon Sep 17 00:00:00 2001 From: Jake Kellas Date: Wed, 2 Nov 2022 09:39:46 -0700 Subject: [PATCH 1/2] feat: update how authentication works for online and offline stops --- UI/src/authentication/index.js | 28 ++++++++++++++----- .../components/features/RipaPageContainer.vue | 6 ++-- .../components/mixins/RipaApiStopJobMixin.vue | 3 ++ UI/src/components/molecules/RipaAppBar.vue | 20 +++++++++++++ .../components/molecules/RipaConfirmation.vue | 6 ++-- UI/src/components/molecules/RipaTemplate.vue | 21 +++++++++----- .../components/organisms/RipaFormWrapper.vue | 5 ++-- .../components/organisms/RipaPageWrapper.vue | 5 ++++ UI/src/store/index.js | 12 ++++++-- 9 files changed, 83 insertions(+), 23 deletions(-) diff --git a/UI/src/authentication/index.js b/UI/src/authentication/index.js index 859a94547..3a9dabc13 100644 --- a/UI/src/authentication/index.js +++ b/UI/src/authentication/index.js @@ -30,20 +30,22 @@ export default { apiSubscription: res.data.Configuration.Subscription, defaultCounty: res.data.Configuration.DefaultCounty, displayBeatInput: - res.data.Configuration.DisplayBeatsInput.toUpperCase() === 'TRUE', + res.data.Configuration.DisplayBeatsInput?.toUpperCase() === 'TRUE', displayDebugger: - res.data.Configuration.DisplayDebugger.toUpperCase() === 'TRUE', + res.data.Configuration.DisplayDebugger?.toUpperCase() === 'TRUE', agencyQuestions: res.data.AgencyQuestions || [], environmentName: environmentName.toUpperCase(), useOfficerUpn: - res.data.Configuration.UseOfficerUpn.toUpperCase() === 'TRUE', + res.data.Configuration.UseOfficerUpn?.toUpperCase() === 'TRUE', modifyBeatId: - res.data.Configuration.ModifyBeatId.toUpperCase() === 'TRUE', + res.data.Configuration.ModifyBeatId?.toUpperCase() === 'TRUE', beatIdNumberOfDigits: parseInt(res.data.Configuration.BeatIdNumberOfDigits) || 0, displayReportingEmail: - res.data.Configuration.DisplayReportingEmail.toUpperCase() === 'TRUE', - reportingEmailAddress: res.data.Configuration.ReportingEmailAddress, + res.data.Configuration.DisplayReportingEmail?.toUpperCase() === + 'TRUE', + reportingEmailAddress: + res.data.Configuration.ReportingEmailAddress ?? '', }) return new Promise((resolve, reject) => { @@ -67,6 +69,12 @@ export default { async acquireToken() { const account = this.authContext.getActiveAccount() + + if (!account) { + store.dispatch('setIsAuthenticated', false) + return + } + const silentRequest = { scopes: ['User.Read'], account: account, @@ -79,10 +87,16 @@ export default { isAuthenticated() { const account = this.authContext.getActiveAccount() + if (!account) { + store.dispatch('setIsAuthenticated', false) return false } - return new Date(account.idTokenClaims.exp * 1000) > Date.now() + + const isAuthenticated = + new Date(account.idTokenClaims.exp * 1000) > Date.now() + store.dispatch('setIsAuthenticated', isAuthenticated) + return isAuthenticated }, signIn() { diff --git a/UI/src/components/features/RipaPageContainer.vue b/UI/src/components/features/RipaPageContainer.vue index 0a7cb6f78..6d07ebc73 100644 --- a/UI/src/components/features/RipaPageContainer.vue +++ b/UI/src/components/features/RipaPageContainer.vue @@ -12,6 +12,7 @@ :on-update-user="handleUpdateUser" :on-view-stops-with-errors="handleViewStopsWithErrors" :stops-with-errors="mappedStopsWithErrors" + :api-stop-job-loading="apiStopJobLoading" @handleLogOut="handleLogOut" @handleLogIn="handleLogIn" > @@ -117,7 +118,7 @@ export default { isDark: this.getDarkFromLocalStorage(), isValidCache: true, stopIntervalMsApi: 5000, - stopIntervalMsAuth: 30000, + stopIntervalMsAuth: 5000, showInvalidUserDialog: false, showStopsWithErrorsDialog: false, showUserDialog: false, @@ -273,8 +274,9 @@ export default { checkAuthentication() { const token = authentication.acquireToken() + const authenticated = authentication.isAuthenticated() if (this.isOnlineAndAuthenticated) { - if (token === null || !authentication.isAuthenticated()) { + if (token === null || !authenticated) { this.handleLogIn() } } diff --git a/UI/src/components/mixins/RipaApiStopJobMixin.vue b/UI/src/components/mixins/RipaApiStopJobMixin.vue index 9f05c1cf5..56f61d3ee 100644 --- a/UI/src/components/mixins/RipaApiStopJobMixin.vue +++ b/UI/src/components/mixins/RipaApiStopJobMixin.vue @@ -11,6 +11,7 @@ export default { snackbarText: '', snackbarNoErrorsVisible: false, snackbarErrorsVisible: false, + apiStopJobLoading: false, } }, @@ -45,7 +46,9 @@ export default { this.isLocked = true const apiStops = this.getApiStopsFromLocalStorage() if (apiStops.length > 0) { + this.apiStopJobLoading = true await this.runApiStopsJob(apiStops) + this.apiStopJobLoading = false } const apiStopsWithErrors = this.getApiStopsWithErrorsFromLocalStorage() this.setStopsWithErrors(apiStopsWithErrors) diff --git a/UI/src/components/molecules/RipaAppBar.vue b/UI/src/components/molecules/RipaAppBar.vue index 54923a506..1f8ba27b7 100644 --- a/UI/src/components/molecules/RipaAppBar.vue +++ b/UI/src/components/molecules/RipaAppBar.vue @@ -195,6 +195,16 @@ + + You must log into RIPA to create new stops. diff --git a/UI/src/components/molecules/RipaConfirmation.vue b/UI/src/components/molecules/RipaConfirmation.vue index 409c27643..cdbd92e4d 100644 --- a/UI/src/components/molecules/RipaConfirmation.vue +++ b/UI/src/components/molecules/RipaConfirmation.vue @@ -9,7 +9,7 @@ RIPA Stops - +
Thank you for your submission.
My Stops @@ -20,7 +20,7 @@ -
You must be online and logged in to create more stops
+
You must be logged in to create more stops
Home
@@ -48,7 +48,7 @@ export default { type: Boolean, default: false, }, - isOnlineAndAuthenticated: { + isAuthenticated: { type: Boolean, default: false, }, diff --git a/UI/src/components/molecules/RipaTemplate.vue b/UI/src/components/molecules/RipaTemplate.vue index 9ddcbbaa7..ab82c4cbb 100644 --- a/UI/src/components/molecules/RipaTemplate.vue +++ b/UI/src/components/molecules/RipaTemplate.vue @@ -3,9 +3,12 @@
- - You are currently offline. Please connect to the internet to submit - stops. + + You are currently offline. You may create stops but MUST log in to + submit them. + + + You are currently offline. You must log in to create stops. @@ -68,10 +71,10 @@ AG's Website .

-

If you experience issues please contact us at - {{ reportingEmailAddress }}

+

+ If you experience issues please contact us at + {{ reportingEmailAddress }} +

@@ -132,6 +135,10 @@ export default { type: Boolean, default: false, }, + isAuthenticated: { + type: Boolean, + default: false, + }, }, } diff --git a/UI/src/components/organisms/RipaFormWrapper.vue b/UI/src/components/organisms/RipaFormWrapper.vue index 862b655ff..4fe8d3f82 100644 --- a/UI/src/components/organisms/RipaFormWrapper.vue +++ b/UI/src/components/organisms/RipaFormWrapper.vue @@ -26,6 +26,7 @@ @@ -287,7 +288,7 @@ diff --git a/UI/src/components/organisms/RipaPageWrapper.vue b/UI/src/components/organisms/RipaPageWrapper.vue index 4a77546c3..01d851d2e 100644 --- a/UI/src/components/organisms/RipaPageWrapper.vue +++ b/UI/src/components/organisms/RipaPageWrapper.vue @@ -12,6 +12,7 @@ :on-update-user="onUpdateUser" :on-view-stops-with-errors="onViewStopsWithErrors" :stops-with-errors="stopsWithErrors" + :api-stop-job-loading="apiStopJobLoading" @handleLogOut="handleLogOut" @handleLogIn="handleLogIn" > @@ -120,6 +121,10 @@ export default { type: Array, default: () => [], }, + apiStopJobLoading: { + type: Boolean, + default: false, + }, }, } diff --git a/UI/src/store/index.js b/UI/src/store/index.js index a29588354..aebdfad00 100644 --- a/UI/src/store/index.js +++ b/UI/src/store/index.js @@ -30,6 +30,7 @@ export default new Vuex.Store({ state: { isDark: true, isOnline: false, + isAuthenticated: false, adminBeats: [], adminCities: [], adminSchools: [], @@ -83,8 +84,8 @@ export default new Vuex.Store({ isAdmin: state => { return state.user.isAdmin }, - isAuthenticated: () => { - return authentication.isAuthenticated() + isAuthenticated: state => { + return state.isAuthenticated }, isOnline: state => { return state.isOnline @@ -563,6 +564,9 @@ export default new Vuex.Store({ updateResetPagination(state, value) { state.resetPagination = value }, + updateIsAuthenticated(state, value) { + state.isAuthenticated = value + }, }, actions: { @@ -1778,6 +1782,10 @@ export default new Vuex.Store({ setStopsWithErrors({ commit }, value) { commit('updateStopsWithErrors', value) }, + + setIsAuthenticated({ commit }, value) { + commit('updateIsAuthenticated', value) + }, }, modules: {}, From a2f9737eb81cc0dce13590eace597222f8efc179 Mon Sep 17 00:00:00 2001 From: Jake Kellas Date: Wed, 2 Nov 2022 09:40:46 -0700 Subject: [PATCH 2/2] test: update snapshots --- .../features/__snapshots__/RipaPageContainer.spec.js.snap | 1 + .../molecules/__snapshots__/RipaAppBar.spec.js.snap | 1 + .../molecules/__snapshots__/RipaTemplate.spec.js.snap | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/UI/tests/unit/components/features/__snapshots__/RipaPageContainer.spec.js.snap b/UI/tests/unit/components/features/__snapshots__/RipaPageContainer.spec.js.snap index a0cdb834e..39764a94b 100644 --- a/UI/tests/unit/components/features/__snapshots__/RipaPageContainer.spec.js.snap +++ b/UI/tests/unit/components/features/__snapshots__/RipaPageContainer.spec.js.snap @@ -22,6 +22,7 @@ exports[`Ripa Page Container should match snapshot 1`] = `
+
diff --git a/UI/tests/unit/components/molecules/__snapshots__/RipaAppBar.spec.js.snap b/UI/tests/unit/components/molecules/__snapshots__/RipaAppBar.spec.js.snap index 8033ff960..ff4bcafe3 100644 --- a/UI/tests/unit/components/molecules/__snapshots__/RipaAppBar.spec.js.snap +++ b/UI/tests/unit/components/molecules/__snapshots__/RipaAppBar.spec.js.snap @@ -21,5 +21,6 @@ exports[`Ripa App Bar should match snapshot 1`] = `
+ `; diff --git a/UI/tests/unit/components/molecules/__snapshots__/RipaTemplate.spec.js.snap b/UI/tests/unit/components/molecules/__snapshots__/RipaTemplate.spec.js.snap index ae02b0792..cce39c163 100644 --- a/UI/tests/unit/components/molecules/__snapshots__/RipaTemplate.spec.js.snap +++ b/UI/tests/unit/components/molecules/__snapshots__/RipaTemplate.spec.js.snap @@ -5,11 +5,11 @@ exports[`Ripa Template should match snapshot 1`] = `
+