added API link for drupal admins in menu
This commit is contained in:
parent
8efc6fd6f9
commit
6776b8f1d8
@ -9,7 +9,7 @@ export default {
|
|||||||
return { userStore }
|
return { userStore }
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(UserStore,['isloggedin', 'mail', 'name'])
|
...mapState(UserStore,['isloggedin', 'isAdmin', 'mail', 'name'])
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// ...mapActions({
|
// ...mapActions({
|
||||||
@ -30,10 +30,16 @@ export default {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div id="user-tools">
|
<div id="user-tools">
|
||||||
<a class="mdi mdi-account" href="/user">
|
<a class="mdi mdi-account" href="/api/user">
|
||||||
<span>{{ name }}</span>
|
<span>{{ name }}</span>
|
||||||
<!-- <span v-else>{{ mail }}</span> -->
|
<!-- <span v-else>{{ mail }}</span> -->
|
||||||
</a><br/>
|
</a><br/>
|
||||||
|
<a
|
||||||
|
v-if="isAdmin"
|
||||||
|
class="api"
|
||||||
|
href="/api/admin/content/concernements">
|
||||||
|
<span>API</span>
|
||||||
|
</a><br/>
|
||||||
<a href="/user/logout"
|
<a href="/user/logout"
|
||||||
@click.prevent="onLogout()"
|
@click.prevent="onLogout()"
|
||||||
class="mdi mdi-logout"
|
class="mdi mdi-logout"
|
||||||
|
@ -3,6 +3,10 @@ import REST from '@api/rest-axios'
|
|||||||
import JSONAPI from '@api/json-axios'
|
import JSONAPI from '@api/json-axios'
|
||||||
import qs from 'querystring-es3'
|
import qs from 'querystring-es3'
|
||||||
|
|
||||||
|
import { print } from 'graphql/language/printer'
|
||||||
|
import gql from 'graphql-tag'
|
||||||
|
import GQL from '@api/graphql-axios'
|
||||||
|
|
||||||
export const UserStore = defineStore({
|
export const UserStore = defineStore({
|
||||||
id: 'user',
|
id: 'user',
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@ -13,7 +17,8 @@ export const UserStore = defineStore({
|
|||||||
uuid: 0,
|
uuid: 0,
|
||||||
mail: '',
|
mail: '',
|
||||||
name: null,
|
name: null,
|
||||||
roles: null,
|
roles: [],
|
||||||
|
isAdmin: false,
|
||||||
logginMessage: null
|
logginMessage: null
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
@ -31,6 +36,17 @@ export const UserStore = defineStore({
|
|||||||
this.name = data.attributes.name
|
this.name = data.attributes.name
|
||||||
this.isloggedin = true //data.attributes.status
|
this.isloggedin = true //data.attributes.status
|
||||||
console.log('user store checkuser isloggedin', this.isloggedin);
|
console.log('user store checkuser isloggedin', this.isloggedin);
|
||||||
|
|
||||||
|
this.userGetRoles()
|
||||||
|
.then(({ data : { data : { user } } }) => {
|
||||||
|
console.log('graphql user loaded', user)
|
||||||
|
this.roles = user.roles
|
||||||
|
this.checkIsAdmin()
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.warn('Issue with graphql user loading', error)
|
||||||
|
Promise.reject(error)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -97,15 +113,24 @@ export const UserStore = defineStore({
|
|||||||
this.name = data.name[0].value
|
this.name = data.name[0].value
|
||||||
// with session_limit, only here we are certain that the user is logged
|
// with session_limit, only here we are certain that the user is logged
|
||||||
this.isloggedin = true
|
this.isloggedin = true
|
||||||
if (data.roles) {
|
|
||||||
this.roles = data.roles
|
|
||||||
}
|
|
||||||
// console.log('customer_profiles', data.customer_profiles.length)
|
// console.log('customer_profiles', data.customer_profiles.length)
|
||||||
// if (data.customer_profiles.length) {
|
// if (data.customer_profiles.length) {
|
||||||
// dispatch('getUserProfiles', data.customer_profiles[data.customer_profiles.length - 1].target_id)
|
// dispatch('getUserProfiles', data.customer_profiles[data.customer_profiles.length - 1].target_id)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
this.userGetRoles()
|
||||||
|
.then(({ data : { data : { user } } }) => {
|
||||||
|
console.log('graphql user loaded', user)
|
||||||
|
this.roles = user.roles
|
||||||
|
this.checkIsAdmin()
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.warn('Issue with graphql user loading', error)
|
||||||
|
Promise.reject(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.warn('Issue with getUser', error)
|
console.warn('Issue with getUser', error)
|
||||||
Promise.reject(error)
|
Promise.reject(error)
|
||||||
@ -113,6 +138,32 @@ export const UserStore = defineStore({
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
userGetRoles () {
|
||||||
|
// GRAPHQL USER QUERY (needed to get roles)
|
||||||
|
// https://stackoverflow.com/a/55401805
|
||||||
|
const body = {
|
||||||
|
query: `
|
||||||
|
query User($id: Int!){
|
||||||
|
user(id: $id) {
|
||||||
|
id
|
||||||
|
roles
|
||||||
|
username
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
variables: { id: parseInt(this.uid) }
|
||||||
|
}
|
||||||
|
|
||||||
|
return GQL.post('', body)
|
||||||
|
},
|
||||||
|
checkIsAdmin () {
|
||||||
|
const adminroles = ['admin', 'group_admin']
|
||||||
|
for (let r = 0; r < this.roles.length; r++) {
|
||||||
|
if (adminroles.indexOf(this.roles[r]) !== -1) {
|
||||||
|
this.isAdmin = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
userLogout () {
|
userLogout () {
|
||||||
const credentials = qs.stringify({
|
const credentials = qs.stringify({
|
||||||
token: this.csrf_token
|
token: this.csrf_token
|
||||||
@ -122,6 +173,7 @@ export const UserStore = defineStore({
|
|||||||
.then(resp => {
|
.then(resp => {
|
||||||
console.log('userStore userLogout resp', resp)
|
console.log('userStore userLogout resp', resp)
|
||||||
this.isloggedin = false
|
this.isloggedin = false
|
||||||
|
this.roles = []
|
||||||
// window.location.reload(true) ???
|
// window.location.reload(true) ???
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user