Use team update route to update a team member's admin status
continuous-integration/drone/push Build is passing Details

This commit is contained in:
kolaente 2020-08-05 17:32:18 +02:00
parent b779500240
commit 903cdcc93a
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 16 additions and 9 deletions

View File

@ -7,7 +7,8 @@ export default class TeamMemberService extends AbstractService {
super({ super({
create: '/teams/{teamId}/members', create: '/teams/{teamId}/members',
delete: '/teams/{teamId}/members/{username}', delete: '/teams/{teamId}/members/{username}',
}); update: '/teams/{teamId}/members/{username}/admin',
})
} }
processModel(model) { processModel(model) {
@ -19,7 +20,7 @@ export default class TeamMemberService extends AbstractService {
modelFactory(data) { modelFactory(data) {
return new TeamMemberModel(data) return new TeamMemberModel(data)
} }
beforeCreate(model) { beforeCreate(model) {
model.userId = model.id // The api wants to get the user id as user_Id model.userId = model.id // The api wants to get the user id as user_Id
model.admin = model.admin === null ? false : model.admin model.admin = model.admin === null ? false : model.admin

View File

@ -129,6 +129,7 @@
</td> </td>
<td class="actions" v-if="userIsAdmin"> <td class="actions" v-if="userIsAdmin">
<button @click="toggleUserType(m)" class="button buttonright is-primary" <button @click="toggleUserType(m)" class="button buttonright is-primary"
:class="{'is-loading': teamMemberService.loading}"
v-if="m.id !== userInfo.id"> v-if="m.id !== userInfo.id">
Make Make
<template v-if="!m.admin"> <template v-if="!m.admin">
@ -139,6 +140,7 @@
</template> </template>
</button> </button>
<button @click="() => {member = m; showUserDeleteModal = true}" class="button is-danger" <button @click="() => {member = m; showUserDeleteModal = true}" class="button is-danger"
:class="{'is-loading': teamMemberService.loading}"
v-if="m.id !== userInfo.id"> v-if="m.id !== userInfo.id">
<span class="icon is-small"> <span class="icon is-small">
<icon icon="trash-alt"/> <icon icon="trash-alt"/>
@ -230,7 +232,7 @@
}, },
watch: { watch: {
// call again the method if the route changes // call again the method if the route changes
'$route': 'loadTeam' '$route': 'loadTeam',
}, },
computed: mapState({ computed: mapState({
userInfo: state => state.auth.info, userInfo: state => state.auth.info,
@ -309,11 +311,15 @@
}, },
toggleUserType(member) { toggleUserType(member) {
member.admin = !member.admin member.admin = !member.admin
this.teamMemberService.delete(member) this.teamMemberService.update(member)
.then(() => this.teamMemberService.create(member)) .then(r => {
.then(() => { for(const tm in this.team.members) {
this.loadTeam() if (this.team.members[tm].id === member.id) {
this.success({message: 'The team member was successfully made ' + (member.admin ? 'admin': 'member') + '.'}, this) this.$set(this.team.members[tm], 'admin', r.admin)
break
}
}
this.success({message: 'The team member was successfully made ' + (member.admin ? 'admin' : 'member') + '.'}, this)
}) })
.catch(e => { .catch(e => {
this.error(e, this) this.error(e, this)
@ -336,7 +342,7 @@
clearAll() { clearAll() {
this.$set(this, 'foundUsers', []) this.$set(this, 'foundUsers', [])
}, },
} },
} }
</script> </script>