Skip to content

Commit

Permalink
feat: do not show login page if only one provider enabled (#415)
Browse files Browse the repository at this point in the history
* feat: return to the last page visited before logout

* feat: if only one login provider, then do not show login page on logout

* feat: do not show error message if status is 401 or 403

* fix: check if version is defined on top menu

* chore: update web-ui to 8.2.0
  • Loading branch information
omar-chahbouni-decathlon authored Mar 23, 2021
1 parent 342d987 commit 86751a7
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 12 deletions.
2 changes: 1 addition & 1 deletion code/web-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion code/web-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ara-client",
"version": "8.1.0",
"version": "8.2.0",
"description": "Agile Regression Analyzer front app",
"author": "Decathlon <developers@decathlon.com>",
"private": true,
Expand Down
15 changes: 11 additions & 4 deletions code/web-ui/src/components/top-menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,25 @@
return AuthenticationService.getDetails()
},

extractVersion (data, property) {
if (data?.hasOwnProperty(property)) {
return data[property].version
}
},

logout () {
AuthenticationService.logout()
AuthenticationService.logout(true)
}
},

mounted () {
Vue.http
.get(api.paths.info(), api.REQUEST_OPTIONS)
.then((response) => {
this.appVersion = response.data.app.version
this.webUIVersion = response.data['web-ui'].version
this.apiVersion = response.data.api.version
const data = response?.data
this.appVersion = this.extractVersion(data, 'app')
this.webUIVersion = this.extractVersion(data, 'web-ui')
this.apiVersion = this.extractVersion(data, 'api')
// If it is the first time the user opens ARA, make sure to remember the current version for future notification badge
if (!this.latestChangelogVersion) {
this.setLatestChangelogVersion()
Expand Down
6 changes: 6 additions & 0 deletions code/web-ui/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const config = {
}
}
}
},
getProviderUrls: function () {
if (this.isComplete) {
return _(this.authentication.providers).filter('enabled').map('uri').value()
}
return []
}
}

Expand Down
7 changes: 7 additions & 0 deletions code/web-ui/src/libs/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import util from './util'

let api = {}

const IGNORED_ERROR_STATUS_CODE = [401, 403]

const API_PATH = '/api'
const PROJECT_API_PATH = API_PATH + '/projects'

Expand Down Expand Up @@ -71,6 +73,11 @@ api.handleError = function (response, callBack) {
// TODO 404 is sent back by Spring as:
// {"timestamp":"2017-12-08T13:21:53.465Z","status":404,"error":"Not Found","message":"No message available","path":"/api/errors/distinct-properties"}

const accessDenied = IGNORED_ERROR_STATUS_CODE.includes(response?.status)
if (accessDenied) {
return
}

let message = response.headers.map['x-ara-message']
if (message) {
title = 'Error'
Expand Down
17 changes: 13 additions & 4 deletions code/web-ui/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Vue.http.interceptors.push(function (request, next) {
desc: 'It seems that your session has expired. Please login again to ARA',
duration: 0
})
AuthenticationService.logout()
AuthenticationService.logout(false)
}
})
})
Expand Down Expand Up @@ -112,9 +112,7 @@ const manageLoginRedirection = async function (to, from, next) {
title: 'Access denied',
desc: 'You need to login first if you want to access this page.'
})
return next({
path: '/login'
})
return goToLogin(next)
}

const loggedInButTryingToReachALoggedOutPage = loggedIn && onlyWhenLoggedOut
Expand All @@ -138,6 +136,17 @@ const manageLoginRedirection = async function (to, from, next) {
}
}

const goToLogin = function (next) {
const providersUrls = config.getProviderUrls()
const onlyOneProvider = providersUrls.length === 1
if (onlyOneProvider) {
window.location.href = providersUrls[0]
}
return next({
path: '/login'
})
}

router.beforeEach(async (to, from, next) => {
await manageLoginRedirection(to, from, next)

Expand Down
24 changes: 22 additions & 2 deletions code/web-ui/src/service/authentication.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,45 @@ import router from '../main'
import Vue from 'vue'
import iView from 'iview'
import api from '../libs/api'
import { config } from '../config'

const AUTHENTICATION_DETAILS = 'authentication_details'

const LAST_URL_BEFORE_LOGOUT = 'last_url'

const AuthenticationService = {

login (authenticationDetails) {
this.saveDetails(authenticationDetails)
router.push('/')
const url = this.getLastUrlBeforeLogout()
router.push(url)
},

isAlreadyLoggedIn () {
return !!this.getDetails()
},

logout () {
logout (manual) {
this.saveUrl()
this.clearDetails()
const providersUrls = config.getProviderUrls()
if (!manual && providersUrls.length === 1) {
window.location.href = providersUrls[0]
return
}
router.push('/login')
},

saveUrl () {
const currentUrl = window.location.pathname
localStorage.setItem(LAST_URL_BEFORE_LOGOUT, currentUrl)
},

getLastUrlBeforeLogout () {
const url = localStorage.getItem(LAST_URL_BEFORE_LOGOUT)
return url || '/'
},

deleteAuthenticationCookie () {
const url = api.paths.logout()
Vue.http
Expand Down

0 comments on commit 86751a7

Please sign in to comment.