User cannot change their own role

This commit is contained in:
narendra chandra 2021-02-06 17:12:24 -05:00
parent 0af45c0156
commit 4920a902c4

View File

@ -49,7 +49,7 @@
{{ scope.row.createdAt | dateTime }} {{ scope.row.createdAt | dateTime }}
</template> </template>
<template slot="role" slot-scope="scope"> <template slot="role" slot-scope="scope" v-if="scope.row.email != currentUser.email">
<ApolloQuery :query="FetchAllRoles"> <ApolloQuery :query="FetchAllRoles">
<template v-slot="{ result: { data } }"> <template v-slot="{ result: { data } }">
<template v-if="data"> <template v-if="data">
@ -75,6 +75,7 @@
</template> </template>
<script> <script>
import { mapGetters } from 'vuex'
import gql from 'graphql-tag' import gql from 'graphql-tag'
import { isEmail } from 'validator' import { isEmail } from 'validator'
import normalizeEmail from '~/components/utils/NormalizeEmail' import normalizeEmail from '~/components/utils/NormalizeEmail'
@ -107,6 +108,9 @@ export default {
hasPrevious() { hasPrevious() {
return this.offset > 0 return this.offset > 0
}, },
...mapGetters({
currentUser: 'auth/user',
}),
fields() { fields() {
return { return {
index: this.$t('admin.users.table.columns.number'), index: this.$t('admin.users.table.columns.number'),
@ -194,14 +198,16 @@ export default {
} }
}, },
changeUserRole(id, event) { changeUserRole(id, event) {
const newRole = event.target.value const newRole = event.target.value;
// this.role = '';
// const id = this.User[0].id;
this.$apollo this.$apollo
.mutate({ .mutate({
mutation: updateUserRole(newRole, id), mutation: updateUserRole(newRole, id),
}) })
.catch((error) => this.$toast.error(error.message)) .catch((error) => {
console.log(error.message);
this.$toast.error(error.message)
}
)
}, },
}, },
} }