2018-09-18 16:49:44 +00:00
|
|
|
<template>
|
|
|
|
<div class="card">
|
|
|
|
|
|
|
|
<header class="card-header">
|
|
|
|
<p class="card-header-title">
|
|
|
|
Users with access to this {{type}}
|
|
|
|
</p>
|
|
|
|
</header>
|
|
|
|
<div class="card-content content users-list">
|
|
|
|
<form @submit.prevent="addUser()" class="add-user-form" v-if="userIsAdmin">
|
|
|
|
<div class="field is-grouped">
|
2019-03-02 10:25:10 +00:00
|
|
|
<p class="control is-expanded" v-bind:class="{ 'is-loading': userStuffService.loading}">
|
2018-09-21 18:12:24 +00:00
|
|
|
<multiselect
|
2019-03-02 10:25:10 +00:00
|
|
|
v-model="user"
|
2018-09-21 18:12:24 +00:00
|
|
|
:options="foundUsers"
|
|
|
|
:multiple="false"
|
|
|
|
:searchable="true"
|
2019-03-02 10:25:10 +00:00
|
|
|
:loading="userService.loading"
|
2018-09-21 18:12:24 +00:00
|
|
|
:internal-search="true"
|
|
|
|
@search-change="findUsers"
|
|
|
|
placeholder="Type to search a user"
|
|
|
|
label="username"
|
2019-03-02 10:25:10 +00:00
|
|
|
track-by="id">
|
2018-09-21 18:12:24 +00:00
|
|
|
<template slot="clear" slot-scope="props">
|
2019-03-02 10:25:10 +00:00
|
|
|
<div class="multiselect__clear" v-if="user.id !== 0" @mousedown.prevent.stop="clearAll(props.search)"></div>
|
2018-09-21 18:12:24 +00:00
|
|
|
</template>
|
|
|
|
<span slot="noResult">Oops! No users found. Consider changing the search query.</span>
|
|
|
|
</multiselect>
|
2018-09-18 16:49:44 +00:00
|
|
|
</p>
|
|
|
|
<p class="control">
|
2018-09-21 18:12:24 +00:00
|
|
|
<button type="submit" class="button is-success" style="margin-top: 3px;">
|
2018-09-18 16:49:44 +00:00
|
|
|
<span class="icon is-small">
|
|
|
|
<icon icon="plus"/>
|
|
|
|
</span>
|
|
|
|
Add
|
|
|
|
</button>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
<table class="table is-striped is-hoverable is-fullwidth">
|
|
|
|
<tbody>
|
|
|
|
<tr v-for="u in users" :key="u.id">
|
|
|
|
<td>{{u.username}}</td>
|
|
|
|
<td>
|
|
|
|
<template v-if="u.id === currentUser.id">
|
|
|
|
<b class="is-success">You</b>
|
|
|
|
</template>
|
|
|
|
</td>
|
|
|
|
<td class="type">
|
|
|
|
<template v-if="u.right === 2">
|
|
|
|
<span class="icon is-small">
|
|
|
|
<icon icon="lock"/>
|
|
|
|
</span>
|
|
|
|
Admin
|
|
|
|
</template>
|
|
|
|
<template v-else-if="u.right === 1">
|
|
|
|
<span class="icon is-small">
|
|
|
|
<icon icon="pen"/>
|
|
|
|
</span>
|
|
|
|
Write
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<span class="icon is-small">
|
|
|
|
<icon icon="users"/>
|
|
|
|
</span>
|
|
|
|
Read-only
|
|
|
|
</template>
|
|
|
|
</td>
|
|
|
|
<td class="actions" v-if="userIsAdmin">
|
|
|
|
<button @click="toggleUserType(u.id, (u.right === 2))" class="button buttonright is-primary" v-if="u.id !== currentUser.id">
|
|
|
|
Make
|
|
|
|
<template v-if="u.right === 2">
|
|
|
|
Member
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
Admin
|
|
|
|
</template>
|
|
|
|
</button>
|
2019-03-02 10:25:10 +00:00
|
|
|
<button @click="user = u; showUserDeleteModal = true" class="button is-danger" v-if="u.id !== currentUser.id">
|
2018-09-18 16:49:44 +00:00
|
|
|
<span class="icon is-small">
|
|
|
|
<icon icon="trash-alt"/>
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<modal
|
|
|
|
v-if="showUserDeleteModal"
|
|
|
|
@close="showUserDeleteModal = false"
|
|
|
|
v-on:submit="deleteUser()">
|
|
|
|
<span slot="header">Remove a user from the {{typeString}}</span>
|
|
|
|
<p slot="text">Are you sure you want to remove this user from the {{typeString}}?<br/>
|
|
|
|
<b>This CANNOT BE UNDONE!</b></p>
|
|
|
|
</modal>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import auth from '../../auth'
|
|
|
|
import message from '../../message'
|
2018-09-21 18:12:24 +00:00
|
|
|
import multiselect from 'vue-multiselect'
|
|
|
|
import 'vue-multiselect/dist/vue-multiselect.min.css'
|
2018-09-18 16:49:44 +00:00
|
|
|
|
2019-03-02 10:25:10 +00:00
|
|
|
import UserService from '../../services/user'
|
|
|
|
import UserNamespaceModel from '../../models/userNamespace'
|
|
|
|
import UserListModel from '../../models/userList'
|
|
|
|
import UserListService from '../../services/userList'
|
|
|
|
import UserNamespaceService from '../../services/userNamespace'
|
|
|
|
import UserModel from '../../models/user'
|
|
|
|
|
2018-09-18 16:49:44 +00:00
|
|
|
export default {
|
|
|
|
name: 'user',
|
|
|
|
props: {
|
|
|
|
type: '',
|
|
|
|
id: 0,
|
|
|
|
userIsAdmin: false,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2019-03-02 10:25:10 +00:00
|
|
|
userService: UserService, // To search for users
|
|
|
|
user: UserModel,
|
|
|
|
userStuff: Object, // This will be either UserNamespaceModel or UserListModel
|
|
|
|
userStuffService: Object, // This will be either UserListService or UserNamespaceService
|
|
|
|
|
2018-09-18 16:49:44 +00:00
|
|
|
currentUser: auth.user.infos,
|
|
|
|
typeString: '',
|
|
|
|
showUserDeleteModal: false,
|
|
|
|
users: [],
|
2018-09-21 18:12:24 +00:00
|
|
|
foundUsers: [],
|
2018-09-18 16:49:44 +00:00
|
|
|
}
|
|
|
|
},
|
2018-09-21 18:12:24 +00:00
|
|
|
components: {
|
|
|
|
multiselect
|
|
|
|
},
|
2018-09-18 16:49:44 +00:00
|
|
|
created() {
|
2019-03-02 10:25:10 +00:00
|
|
|
this.userService = new UserService()
|
|
|
|
this.user = new UserModel()
|
|
|
|
|
2018-09-18 16:49:44 +00:00
|
|
|
if (this.type === 'list') {
|
|
|
|
this.typeString = `list`
|
2019-03-02 10:25:10 +00:00
|
|
|
this.userStuffService = new UserListService()
|
|
|
|
this.userStuff = new UserListModel({listID: this.id})
|
2018-09-18 16:49:44 +00:00
|
|
|
} else if (this.type === 'namespace') {
|
|
|
|
this.typeString = `namespace`
|
2019-03-02 10:25:10 +00:00
|
|
|
this.userStuffService = new UserNamespaceService()
|
|
|
|
this.userStuff = new UserNamespaceModel({namespaceID: this.id})
|
2018-09-18 16:49:44 +00:00
|
|
|
} else {
|
|
|
|
throw new Error('Unknown type: ' + this.type)
|
|
|
|
}
|
|
|
|
|
|
|
|
this.loadUsers()
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
loadUsers() {
|
2019-03-02 10:25:10 +00:00
|
|
|
this.userStuffService.getAll(this.userStuff)
|
2018-09-18 16:49:44 +00:00
|
|
|
.then(response => {
|
2019-03-02 10:25:10 +00:00
|
|
|
this.$set(this, 'users', response)
|
2018-09-18 16:49:44 +00:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2019-03-02 10:25:10 +00:00
|
|
|
message.error(e, this)
|
2018-09-18 16:49:44 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
deleteUser() {
|
2019-03-02 10:25:10 +00:00
|
|
|
// The api wants the user id as userID
|
|
|
|
let usr = this.user
|
|
|
|
this.userStuff.userID = usr.id
|
|
|
|
|
|
|
|
this.userStuffService.delete(this.userStuff)
|
2018-09-18 16:49:44 +00:00
|
|
|
.then(() => {
|
|
|
|
this.showUserDeleteModal = false;
|
2019-03-02 10:25:10 +00:00
|
|
|
message.success({message: 'The user was successfully deleted from the ' + this.typeString + '.'}, this)
|
2018-09-18 16:49:44 +00:00
|
|
|
this.loadUsers()
|
|
|
|
})
|
|
|
|
.catch(e => {
|
2019-03-02 10:25:10 +00:00
|
|
|
message.error(e, this)
|
2018-09-18 16:49:44 +00:00
|
|
|
})
|
|
|
|
},
|
2019-03-02 10:25:10 +00:00
|
|
|
addUser(admin = false) {
|
|
|
|
this.userStuff.right = 0
|
2018-09-18 16:49:44 +00:00
|
|
|
if (admin) {
|
2019-03-02 10:25:10 +00:00
|
|
|
this.userStuff.right = 2
|
2018-09-18 16:49:44 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 10:25:10 +00:00
|
|
|
// The api wants the user id as userID
|
|
|
|
this.userStuff.userID = this.user.id
|
2018-09-21 18:12:24 +00:00
|
|
|
this.$set(this, 'foundUsers', [])
|
|
|
|
|
2019-03-02 10:25:10 +00:00
|
|
|
this.userStuffService.create(this.userStuff)
|
2018-09-18 16:49:44 +00:00
|
|
|
.then(() => {
|
|
|
|
this.loadUsers()
|
2019-03-02 10:25:10 +00:00
|
|
|
message.success({message: 'The user was successfully added.'}, this)
|
2018-09-18 16:49:44 +00:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2019-03-02 10:25:10 +00:00
|
|
|
message.error(e, this)
|
2018-09-18 16:49:44 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
toggleUserType(userid, current) {
|
2019-03-02 10:25:10 +00:00
|
|
|
this.userStuff.userID = userid
|
|
|
|
this.userStuff.right = 0
|
2018-09-19 18:41:53 +00:00
|
|
|
if (!current) {
|
2019-03-02 10:25:10 +00:00
|
|
|
this.userStuff.right = 2
|
2018-09-19 18:41:53 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 10:25:10 +00:00
|
|
|
this.userStuffService.update(this.userStuff)
|
2018-09-19 18:41:53 +00:00
|
|
|
.then(() => {
|
|
|
|
this.loadUsers()
|
2019-03-02 10:25:10 +00:00
|
|
|
message.success({message: 'The user right was successfully updated.'}, this)
|
2018-09-19 18:41:53 +00:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2019-03-02 10:25:10 +00:00
|
|
|
message.error(e, this)
|
2018-09-19 18:41:53 +00:00
|
|
|
})
|
2018-09-18 16:49:44 +00:00
|
|
|
},
|
2018-09-21 18:12:24 +00:00
|
|
|
findUsers(query) {
|
|
|
|
if(query === '') {
|
|
|
|
this.$set(this, 'foundUsers', [])
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-03-02 10:25:10 +00:00
|
|
|
this.userService.getAll({}, {s: query})
|
2018-09-21 18:12:24 +00:00
|
|
|
.then(response => {
|
2019-03-02 10:25:10 +00:00
|
|
|
this.$set(this, 'foundUsers', response)
|
2018-09-21 18:12:24 +00:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2019-03-02 10:25:10 +00:00
|
|
|
message.error(e, this)
|
2018-09-21 18:12:24 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
clearAll () {
|
|
|
|
this.$set(this, 'foundUsers', [])
|
|
|
|
},
|
|
|
|
limitText (count) {
|
|
|
|
return `and ${count} others`
|
|
|
|
},
|
2018-09-18 16:49:44 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2018-09-21 18:12:24 +00:00
|
|
|
<style lang="scss">
|
2018-09-18 17:02:13 +00:00
|
|
|
.card{
|
|
|
|
margin-bottom: 1rem;
|
2018-09-18 16:49:44 +00:00
|
|
|
|
2018-09-18 17:02:13 +00:00
|
|
|
.add-user-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, .users-namespace{
|
|
|
|
padding: 0 !important;
|
|
|
|
}
|
2018-09-21 18:12:24 +00:00
|
|
|
|
|
|
|
ul.multiselect__content{
|
|
|
|
margin: 0 !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.multiselect{
|
|
|
|
background-color: white;
|
|
|
|
border: 1px solid #dbdbdb;
|
|
|
|
color: #363636;
|
|
|
|
-webkit-box-shadow: inset 0 1px 2px rgba(10, 10, 10, 0.1);
|
|
|
|
box-shadow: inset 0 1px 2px rgba(10, 10, 10, 0.1);
|
|
|
|
|
|
|
|
border-radius: 4px;
|
|
|
|
font-size: 1rem;
|
|
|
|
height: 2.25em;
|
|
|
|
line-height: 1.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
.multiselect--active{
|
|
|
|
-webkit-box-shadow: inset 0 0.125em 0 rgba(10, 10, 10, 0.075), 0 0 0 0.125em rgba(91, 183, 219, 0.25);
|
|
|
|
box-shadow: inset 0 0.125em 0 rgba(10, 10, 10, 0.075), 0 0 0 0.125em rgba(91, 183, 219, 0.25);
|
|
|
|
border: 1px solid #5bb7db;
|
|
|
|
}
|
2018-09-18 16:49:44 +00:00
|
|
|
</style>
|