From 77285ccce064e2071b6abc8f3ee27b2276d58705 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 18 Sep 2018 08:10:16 +0200 Subject: [PATCH] Added methods to manage users and teams in a namespace --- src/App.vue | 33 ++ src/components/namespaces/EditNamespace.vue | 341 ++++++++++++++++++-- 2 files changed, 342 insertions(+), 32 deletions(-) diff --git a/src/App.vue b/src/App.vue index e05134cf..9e2a09de 100644 --- a/src/App.vue +++ b/src/App.vue @@ -183,4 +183,37 @@ color: rgb(74, 74, 74); } } + + .bigbuttons{ + margin-top: 0.5rem; + } + + .card{ + margin-bottom: 1rem; + + .add-user-form, .add-team-form { + margin: 1rem; + } + + .table{ + border-top: 1px solid darken(#fff, 15%); + + td{ + vertical-align: middle; + } + + td.type, td.actions{ + width: 200px; + } + + td.actions{ + text-align: right; + } + } + } + + .users-list, .teams-list, + .users-namespace, .teams-namespace{ + padding: 0 !important; + } diff --git a/src/components/namespaces/EditNamespace.vue b/src/components/namespaces/EditNamespace.vue index e806b1b8..55326b13 100644 --- a/src/components/namespaces/EditNamespace.vue +++ b/src/components/namespaces/EditNamespace.vue @@ -1,44 +1,193 @@ @@ -64,6 +233,18 @@ error: '', loading: false, showDeleteModal: false, + user: auth.user, + userIsAdmin: false, + + namespaceUsers: [], + newUser: {user_id: 0}, + showUserDeleteModal: false, + userToDelete: 0, + + namespaceTeams: [], + newTeam: {team_id: 0}, + showTeamDeleteModal: false, + teamToDelete: 0, } }, beforeMount() { @@ -86,6 +267,11 @@ HTTP.get(`namespaces/` + this.$route.params.id, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}}) .then(response => { this.$set(this, 'namespace', response.data) + if (response.data.owner.id === this.user.infos.id) { + this.userIsAdmin = true + } + this.loadUsers() + this.loadTeams() this.loading = false }) .catch(e => { @@ -120,6 +306,97 @@ this.handleError(e) }) }, + loadUsers() { + HTTP.get(`namespaces/` + this.$route.params.id + `/users`, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}}) + .then(response => { + response.data.push(this.namespace.owner) + this.$set(this, 'namespaceUsers', response.data) + this.loading = false + }) + .catch(e => { + this.handleError(e) + }) + }, + deleteUser() { + HTTP.delete(`namespaces/` + this.$route.params.id + `/users/` + this.userToDelete, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}}) + .then(() => { + this.showUserDeleteModal = false; + this.handleSuccess({message: 'The user was successfully deleted from the namespace.'}) + this.loadUsers() + }) + .catch(e => { + this.handleError(e) + }) + }, + addUser(admin) { + if(admin === null) { + admin = false + } + this.newUser.right = 0 + if (admin) { + this.newUser.right = 2 + } + + HTTP.put(`namespaces/` + this.$route.params.id + `/users`, this.newUser, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}}) + .then(() => { + this.loadUsers() + this.handleSuccess({message: 'The user was successfully added.'}) + }) + .catch(e => { + this.handleError(e) + }) + }, + toggleUserType(userid, current) { + this.userToDelete = userid + this.newUser.user_id = userid + this.deleteUser() + this.addUser(!current) + }, + loadTeams() { + HTTP.get(`namespaces/` + this.$route.params.id + `/teams`, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}}) + .then(response => { + this.$set(this, 'namespaceTeams', response.data) + this.loading = false + }) + .catch(e => { + this.handleError(e) + }) + }, + deleteTeam() { + HTTP.delete(`namespaces/` + this.$route.params.id + `/teams/` + this.teamToDelete, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}}) + .then(() => { + this.showTeamDeleteModal = false; + this.handleSuccess({message: 'The team was successfully deleted from the namespace.'}) + this.loadTeams() + }) + .catch(e => { + this.handleError(e) + }) + }, + addTeam(admin) { + if(admin === null) { + admin = false + } + this.newTeam.right = 0 + if (admin) { + this.newTeam.right = 2 + } + + HTTP.put(`namespaces/` + this.$route.params.id + `/teams`, this.newTeam, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}}) + .then(() => { + this.loadTeams() + this.handleSuccess({message: 'The team was successfully added.'}) + }) + .catch(e => { + this.handleError(e) + }) + }, + toggleTeamType(teamid, current) { + this.teamToDelete = teamid + this.newTeam.team_id = teamid + this.deleteTeam() + this.addTeam(!current) + }, handleError(e) { this.loading = false message.error(e, this)