Skip to content
Snippets Groups Projects
Commit a10ea438 authored by thomas.blanc.2@etu.univ-amu.fr's avatar thomas.blanc.2@etu.univ-amu.fr
Browse files

Users role change support

parent bc2ec90d
No related branches found
No related tags found
No related merge requests found
......@@ -33,7 +33,7 @@ export const api = {
},
async getUser () {
const token = await localStorage.getItem('token')
const url = serverurl + 'user'
const url = serverurl + 'users'
try {
const response = await fetch(url, { headers: { Authorization: 'Bearer ' + token } })
return await response.json()
......@@ -88,7 +88,7 @@ export const api = {
},
async getUserList () {
const token = await localStorage.getItem('token')
const url = serverurl + 'user/list'
const url = serverurl + 'users/list'
try {
const response = await fetch(url, { headers: { Authorization: 'Bearer ' + token } })
return await response.json()
......@@ -187,7 +187,7 @@ export const api = {
},
async removeUser (id) {
const token = await localStorage.getItem('token')
const url = serverurl + 'user' + '?id=' + id
const url = serverurl + 'users' + '?id=' + id
try {
await fetch(url, {
method: 'DELETE',
......@@ -222,7 +222,7 @@ export const api = {
}
},
async register (username, email, password) {
const url = serverurl + 'user/signup'
const url = serverurl + 'users/signup'
try {
const response = await fetch(
url, {
......@@ -376,5 +376,19 @@ export const api = {
} catch (error) {
return false
}
},
async setAdmin (id) {
const url = serverurl + 'users/setAdmin' + '?id=' + id
const token = await localStorage.getItem('token')
const response = await fetch(url, {
headers: {
Authorization: 'Bearer ' + token
}
})
try {
return await response.json()
} catch (error) {
return null
}
}
}
......@@ -48,7 +48,7 @@ export default {
const userRole = await localStorage.getItem('user_role')
if (userRole) this.isLoggedIn = true
if (userRole === 'ROLE_ADMIN') this.isAdmin = true
if (userRole === 'ADMIN') this.isAdmin = true
},
methods: {
async postComment () {
......
......@@ -21,7 +21,7 @@
</b-button>
<b-button
v-if="account.role == 'ROLE_ADMIN'"
v-if="account.role == 'ADMIN'"
icon-left="cctv"
type="is-info"
tag="router-link"
......
......@@ -78,7 +78,12 @@
{{ props.row.email }}
</b-table-column>
<b-table-column field="role" label="Role" sortable>
{{ props.row.role }}
</b-table-column>
<b-table-column label="" centered>
<b-button class="actionButton" icon-left="cctv" type="is-success" @click="setAdminPrompt(props.row.id, props.row.username)" outlined/>
<b-button class="actionButton" icon-left="delete" type="is-danger" @click="removePrompt(props.row.id, props.row.username, 'user')" outlined/>
</b-table-column>
</template>
......@@ -195,6 +200,20 @@ export default {
this.modelList = await api.getModelList()
}
})
},
setAdminPrompt (id, name) {
this.$buefy.dialog.confirm({
message: 'Set admin role for ' + name + ' ?',
cancelText: 'Abort',
confirmText: 'Set',
type: 'is-success',
hasIcon: true,
onConfirm: async () => {
await api.setAdmin(id)
this.$buefy.toast.open(name + ' role has been changed')
this.userList = await api.getUserList()
}
})
}
}
}
......
......@@ -105,7 +105,7 @@ export default {
if (parseInt(userId) === this.model.author.id) this.isAuthor = true
const userRole = await localStorage.getItem('user_role')
if (userRole === 'ROLE_ADMIN') this.isAuthor = true
if (userRole === 'ADMIN') this.isAuthor = true
this.downloadUrl = this.$serverurl + 'models/download?id=' + this.model.id
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment