Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
Blacklist rename disabled->blacklisted
Browse files Browse the repository at this point in the history
  • Loading branch information
Haelle committed May 8, 2019
1 parent aaa164d commit 83b4314
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
22 changes: 11 additions & 11 deletions src/components/resource/jwt_api_entreprise/Show.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-bind:class="{ disabled_token: !jwt.enabled }">
<div v-bind:class="{ blacklisted_token: jwt.blacklisted }">
<div class="panel__header">
<h3 class="token__name">Organisme utilisateur final : {{ jwt.payload.sub }}</h3>
<small class="panel__header-extra">Délivré le {{ formatDate(jwt.payload.iat) }}</small>
Expand Down Expand Up @@ -36,15 +36,15 @@
<svg class="icon icon-copy" viewBox="0 0 32 32"><use xlink:href="#icon-copy"></use></svg>
</button>

<button class="button warning" v-if="jwt.enabled && isAdmin" @click="dialogDisableJwt = true">
<button class="button warning" v-if="!jwt.blacklisted && isAdmin" @click="dialogBlacklistJwt = true">
Blacklister
</button>
<div class="dialog-backdrop" v-if="dialogDisableJwt">
<div class="dialog-backdrop" v-if="dialogBlacklistJwt">
<div class="dialog panel">
<p>Êtes-vous certains de vouloir désactiver ce token ?</p>
<p>Êtes-vous certains de vouloir blacklister ce token ?</p>
<div class="action-buttons">
<button class="button small" @click="dialogDisableJwt = false">Annuler</button>
<button class="button small warning" @click="disableJwt">Désactiver</button>
<button class="button small" @click="dialogBlacklistJwt = false">Annuler</button>
<button class="button small warning" @click="blacklistJwt">Blacklister</button>
</div>
</div>
</div>
Expand All @@ -63,7 +63,7 @@ export default {
return {
showClipboardSuccessMsg: false,
showClipboardErrorMsg: false,
dialogDisableJwt: false
dialogBlacklistJwt: false
}
},
Expand All @@ -89,9 +89,9 @@ export default {
clipboardError (e) { this.showClipboardErrorMsg = true },
disableJwt () {
this.$store.dispatch('user/disableToken', { id: this.jwt.payload.jti })
.finally(this.dialogDisableJwt = false)
blacklistJwt () {
this.$store.dispatch('user/blacklistToken', { id: this.jwt.payload.jti })
.finally(this.dialogBlacklistJwt = false)
}
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ export default {
display: inline-block;
}
.disabled_token, .disabled_token input, .disabled_token label {
.blacklisted_token, .blacklisted_token input, .blacklisted_token label {
color: #c9d3df;
}
</style>
10 changes: 5 additions & 5 deletions src/components/resource/user/UserTokens.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
h2 Tokens de l'utilisateur
jwt-api-entreprise-new(v-if="isAdmin || allowedToCreateToken")

div(v-if="tokens.length > 0 || disabledTokens.length > 0")
div(v-if="tokens.length > 0 || blacklistedTokens.length > 0")
jwt-api-entreprise-index(:jwtList="tokens" v-if="tokens.length > 0")
div(v-if="isAdmin && disabledTokens.length > 0")
h2 Tokens désactivés
jwt-api-entreprise-index(:jwtList="disabledTokens")
div(v-if="isAdmin && blacklistedTokens.length > 0")
h2 Tokens blacklistés
jwt-api-entreprise-index(:jwtList="blacklistedTokens")
p(v-else) Aucun token attribué

</template>
Expand All @@ -23,7 +23,7 @@ export default {
computed: {
...mapGetters({
tokens: 'user/tokens',
disabledTokens: 'user/disabledTokens',
blacklistedTokens: 'user/blacklistedTokens',
allowedToCreateToken: 'user/allowedToCreateToken',
isAdmin: 'auth/isAdmin'
})
Expand Down
28 changes: 14 additions & 14 deletions src/store/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const state = {
contacts: [],
allowed_roles: [],
tokens: [],
disabledTokens: []
blacklistedTokens: []
}
}

Expand All @@ -32,9 +32,9 @@ const getters = {
return tokens.sort((token1, token2) => new Date(token2.payload.iat) - new Date(token1.payload.iat))
},

disabledTokens (state) {
let disabledTokens = cloneDeep(state.user.disabledTokens)
return disabledTokens.sort((token1, token2) => new Date(token2.payload.iat) - new Date(token1.payload.iat))
blacklistedTokens (state) {
let blacklistedTokens = cloneDeep(state.user.blacklistedTokens)
return blacklistedTokens.sort((token1, token2) => new Date(token2.payload.iat) - new Date(token1.payload.iat))
},

allowedRoles (state, getters, rootState, rootGetters) {
Expand All @@ -52,11 +52,11 @@ const getters = {
}
}

const formatJwt = (jwt, enabled) => {
const formatJwt = (jwt, blacklisted) => {
const payload = JwtDecode(jwt)

return {
enabled: enabled,
blacklisted: blacklisted,
value: jwt,
payload
}
Expand All @@ -72,23 +72,23 @@ const mutations = {
},

setTokens (state, tokens) {
const decodedTokens = tokens.map(e => formatJwt(e, true))
const decodedTokens = tokens.map(e => formatJwt(e, false))

state.user.tokens = decodedTokens
},

setDisabledTokens (state, disabledTokens) {
const decodedTokens = disabledTokens.map(e => formatJwt(e, false))
setBlacklistedTokens (state, blacklistedTokens) {
const decodedTokens = blacklistedTokens.map(e => formatJwt(e, true))

state.user.disabledTokens = decodedTokens
state.user.blacklistedTokens = decodedTokens
},

setAllowedRoles (state, roles) {
state.user.allowed_roles = roles
},

addToken (state, token) {
state.user.tokens.push(formatJwt(token, true))
state.user.tokens.push(formatJwt(token, false))
}
}

Expand Down Expand Up @@ -116,7 +116,7 @@ const actions = {

commit('setContacts', data.contacts)
commit('setTokens', data.tokens)
commit('setDisabledTokens', data.disabled_tokens)
commit('setBlacklistedTokens', data.blacklisted_tokens)
commit('setAllowedRoles', data.allowed_roles)
},

Expand All @@ -133,9 +133,9 @@ const actions = {
.then(data => commit('addToken', data.new_token))
},

disableToken ({ dispatch, commit, getters, rootGetters }, payload) {
blacklistToken ({ dispatch, commit, getters, rootGetters }, payload) {
const userId = getters.userDetails.id
let url = `users/${userId}/jwt_api_entreprise/disable`
let url = `users/${userId}/jwt_api_entreprise/blacklist`
dispatch('api/admin/post', { url: url, params: payload }, { root: true })
.then(data => dispatch('get', { userId }))
},
Expand Down

0 comments on commit 83b4314

Please sign in to comment.