Add user_is_admin flag to app store, plus logic to set/clear it

This commit is contained in:
Lance Edgar 2020-02-11 13:33:54 -06:00
parent a80a42fb56
commit 3c4e9567a9
4 changed files with 24 additions and 2 deletions

View file

@ -43,6 +43,7 @@ export default {
// let all of app know who the user is(n't)
this.$store.commit('SET_USER', response.data.user)
this.$store.commit('SET_USER_IS_ADMIN', response.data.user ? response.data.user.is_admin : false)
this.$store.commit('SET_USER_IS_ROOT', response.data.user ? response.data.user.is_root : false)
// also keep track of user's permissions

View file

@ -15,7 +15,7 @@
<slot></slot>
<b-dropdown-item v-if="user.is_admin && !user_is_root"
<b-dropdown-item v-if="$store.state.user_is_admin && !user_is_root"
aria-role="listitem"
has-link
class="root-user">
@ -124,7 +124,7 @@ export default {
},
methods: {
becomeRoot() {
if (this.user_is_root || !this.user.is_admin) {
if (this.user_is_root || !this.$store.state.user_is_admin) {
return
}
this.$http.post(this.becomeRootUrl).then(response => {

View file

@ -3,6 +3,23 @@ export function ByjovePlugin(Vue) {
Vue.mixin({
methods: {
$loginUser(user) {
// put user info in app store
this.$store.commit('SET_USER', user)
this.$store.commit('SET_USER_IS_ADMIN', user.is_admin)
// note, this should already be false
// this.$store.commit('SET_USER_IS_ROOT', false)
},
$logoutUser() {
// remove user info from app store
this.$store.commit('SET_USER', null)
this.$store.commit('SET_USER_IS_ADMIN', false)
this.$store.commit('SET_USER_IS_ROOT', false)
},
$hasPerm(name) {
// if user is root then assume permission

View file

@ -3,6 +3,7 @@ export let ByjoveStoreConfig = {
state: {
session_established: false,
user: null,
user_is_admin: false,
user_is_root: false,
permissions: [],
},
@ -13,6 +14,9 @@ export let ByjoveStoreConfig = {
SET_USER(state, user) {
state.user = user
},
SET_USER_IS_ADMIN(state, is_admin) {
state.user_is_admin = is_admin
},
SET_USER_IS_ROOT(state, is_root) {
state.user_is_root = is_root
},