2019-03-03 13:50:06 +01:00
|
|
|
<template>
|
2019-09-09 19:55:43 +02:00
|
|
|
<div class="card is-fullwidth">
|
2019-03-03 13:50:06 +01:00
|
|
|
<header class="card-header">
|
|
|
|
<p class="card-header-title">
|
2020-02-09 15:11:14 +01:00
|
|
|
Shared with these {{shareType}}s
|
2019-03-03 13:50:06 +01:00
|
|
|
</p>
|
|
|
|
</header>
|
|
|
|
<div class="card-content content sharables-list">
|
|
|
|
<form @submit.prevent="add()" class="add-form" v-if="userIsAdmin">
|
|
|
|
<div class="field is-grouped">
|
|
|
|
<p class="control is-expanded" v-bind:class="{ 'is-loading': searchService.loading}">
|
|
|
|
<multiselect
|
|
|
|
v-model="sharable"
|
|
|
|
:options="found"
|
|
|
|
:multiple="false"
|
|
|
|
:searchable="true"
|
|
|
|
:loading="searchService.loading"
|
|
|
|
:internal-search="true"
|
|
|
|
@search-change="find"
|
2020-07-15 21:13:59 +02:00
|
|
|
placeholder="Type to search..."
|
|
|
|
:showNoOptions="false"
|
2019-03-03 13:50:06 +01:00
|
|
|
:label="searchLabel"
|
|
|
|
track-by="id">
|
|
|
|
<template slot="clear" slot-scope="props">
|
|
|
|
<div class="multiselect__clear" v-if="sharable.id !== 0" @mousedown.prevent.stop="clearAll(props.search)"></div>
|
|
|
|
</template>
|
|
|
|
<span slot="noResult">Oops! No {{shareType}} found. Consider changing the search query.</span>
|
|
|
|
</multiselect>
|
|
|
|
</p>
|
|
|
|
<p class="control">
|
|
|
|
<button type="submit" class="button is-success">
|
|
|
|
<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="s in sharables" :key="s.id">
|
|
|
|
<template v-if="shareType === 'user'">
|
|
|
|
<td>{{s.username}}</td>
|
|
|
|
<td>
|
2020-05-08 20:43:51 +02:00
|
|
|
<template v-if="s.id === userInfo.id">
|
2019-03-03 13:50:06 +01:00
|
|
|
<b class="is-success">You</b>
|
|
|
|
</template>
|
|
|
|
</td>
|
|
|
|
</template>
|
|
|
|
<template v-if="shareType === 'team'">
|
|
|
|
<td>
|
2020-06-17 22:24:37 +02:00
|
|
|
<router-link :to="{name: 'teams.edit', params: {id: s.id}}">
|
2019-03-03 13:50:06 +01:00
|
|
|
{{s.name}}
|
|
|
|
</router-link>
|
|
|
|
</td>
|
|
|
|
</template>
|
|
|
|
<td class="type">
|
|
|
|
<template v-if="s.right === rights.ADMIN">
|
|
|
|
<span class="icon is-small">
|
|
|
|
<icon icon="lock"/>
|
|
|
|
</span>
|
|
|
|
Admin
|
|
|
|
</template>
|
|
|
|
<template v-else-if="s.right === rights.READ_WRITE">
|
|
|
|
<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">
|
|
|
|
<div class="select">
|
2020-05-11 20:56:35 +02:00
|
|
|
<select @change="toggleType(s)" v-model="selectedRight[s.id]" class="button buttonright">
|
2019-03-03 13:50:06 +01:00
|
|
|
<option :value="rights.READ" :selected="s.right === rights.READ">Read only</option>
|
|
|
|
<option :value="rights.READ_WRITE" :selected="s.right === rights.READ_WRITE">Read & write</option>
|
|
|
|
<option :value="rights.ADMIN" :selected="s.right === rights.ADMIN">Admin</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
2020-02-26 20:34:14 +01:00
|
|
|
<button @click="() => {sharable = s; showDeleteModal = true}" class="button is-danger icon-only">
|
2019-03-03 13:50:06 +01:00
|
|
|
<span class="icon is-small">
|
|
|
|
<icon icon="trash-alt"/>
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<modal
|
|
|
|
v-if="showDeleteModal"
|
|
|
|
@close="showDeleteModal = false"
|
|
|
|
@submit="deleteSharable()">
|
|
|
|
<span slot="header">Remove a {{shareType}} from the {{typeString}}</span>
|
|
|
|
<p slot="text">Are you sure you want to remove this {{shareType}} from the {{typeString}}?<br/>
|
|
|
|
<b>This CANNOT BE UNDONE!</b></p>
|
|
|
|
</modal>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import multiselect from 'vue-multiselect'
|
2020-05-08 20:43:51 +02:00
|
|
|
import {mapState} from 'vuex'
|
2019-03-03 13:50:06 +01:00
|
|
|
|
|
|
|
import UserNamespaceService from '../../services/userNamespace'
|
|
|
|
import UserNamespaceModel from '../../models/userNamespace'
|
|
|
|
import UserListModel from '../../models/userList'
|
|
|
|
import UserListService from '../../services/userList'
|
|
|
|
import UserService from '../../services/user'
|
|
|
|
import UserModel from '../../models/user'
|
|
|
|
|
|
|
|
import TeamNamespaceService from '../../services/teamNamespace'
|
|
|
|
import TeamNamespaceModel from '../../models/teamNamespace'
|
|
|
|
import TeamListModel from '../../models/teamList'
|
|
|
|
import TeamListService from '../../services/teamList'
|
|
|
|
import TeamService from '../../services/team'
|
|
|
|
import TeamModel from '../../models/team'
|
|
|
|
|
|
|
|
import rights from '../../models/rights'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'userTeamShare',
|
|
|
|
props: {
|
2019-12-15 21:42:40 +01:00
|
|
|
type: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
shareType: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
id: {
|
|
|
|
type: Number,
|
|
|
|
default: 0,
|
|
|
|
},
|
|
|
|
userIsAdmin: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2019-03-03 13:50:06 +01:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
stuffService: Object, // This user service is either a userNamespaceService or a userListService, depending on the type we are using
|
|
|
|
stuffModel: Object,
|
|
|
|
searchService: Object,
|
|
|
|
sharable: Object,
|
2020-02-26 20:34:14 +01:00
|
|
|
|
2019-03-03 13:50:06 +01:00
|
|
|
found: [],
|
|
|
|
searchLabel: '',
|
|
|
|
rights: rights,
|
2020-05-11 20:56:35 +02:00
|
|
|
selectedRight: {},
|
2019-03-03 13:50:06 +01:00
|
|
|
|
|
|
|
typeString: '',
|
|
|
|
sharables: [], // This holds either teams or users who this namepace or list is shared with
|
|
|
|
showDeleteModal: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
multiselect
|
|
|
|
},
|
2020-05-08 20:43:51 +02:00
|
|
|
computed: mapState({
|
|
|
|
userInfo: state => state.auth.info
|
|
|
|
}),
|
2019-03-03 13:50:06 +01:00
|
|
|
created() {
|
|
|
|
|
|
|
|
if (this.shareType === 'user') {
|
|
|
|
this.searchService = new UserService()
|
|
|
|
this.sharable = new UserModel()
|
|
|
|
this.searchLabel = 'username'
|
|
|
|
|
|
|
|
if (this.type === 'list') {
|
|
|
|
this.typeString = `list`
|
|
|
|
this.stuffService = new UserListService()
|
2020-04-12 23:54:46 +02:00
|
|
|
this.stuffModel = new UserListModel({listId: this.id})
|
2019-03-03 13:50:06 +01:00
|
|
|
} else if (this.type === 'namespace') {
|
|
|
|
this.typeString = `namespace`
|
|
|
|
this.stuffService = new UserNamespaceService()
|
2020-04-17 12:19:53 +02:00
|
|
|
this.stuffModel = new UserNamespaceModel({namespaceId: this.id})
|
2019-03-03 13:50:06 +01:00
|
|
|
} else {
|
|
|
|
throw new Error('Unknown type: ' + this.type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (this.shareType === 'team') {
|
|
|
|
this.searchService = new TeamService()
|
|
|
|
this.sharable = new TeamModel()
|
|
|
|
this.searchLabel = 'name'
|
|
|
|
|
|
|
|
if (this.type === 'list') {
|
|
|
|
this.typeString = `list`
|
|
|
|
this.stuffService = new TeamListService()
|
2020-04-12 23:54:46 +02:00
|
|
|
this.stuffModel = new TeamListModel({listId: this.id})
|
2019-03-03 13:50:06 +01:00
|
|
|
} else if (this.type === 'namespace') {
|
|
|
|
this.typeString = `namespace`
|
|
|
|
this.stuffService = new TeamNamespaceService()
|
2020-04-17 12:19:53 +02:00
|
|
|
this.stuffModel = new TeamNamespaceModel({namespaceId: this.id})
|
2019-03-03 13:50:06 +01:00
|
|
|
} else {
|
|
|
|
throw new Error('Unknown type: ' + this.type)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new Error('Unkown share type')
|
|
|
|
}
|
|
|
|
|
|
|
|
this.load()
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
load() {
|
|
|
|
this.stuffService.getAll(this.stuffModel)
|
|
|
|
.then(r => {
|
|
|
|
this.$set(this, 'sharables', r)
|
2020-05-11 20:56:35 +02:00
|
|
|
r.forEach(s => this.$set(this.selectedRight, s.id, s.right))
|
2019-03-03 13:50:06 +01:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2020-01-30 22:47:08 +01:00
|
|
|
this.error(e, this)
|
2019-03-03 13:50:06 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
deleteSharable() {
|
|
|
|
|
|
|
|
if (this.shareType === 'user') {
|
2020-04-12 23:54:46 +02:00
|
|
|
this.stuffModel.userId = this.sharable.username
|
2019-03-03 13:50:06 +01:00
|
|
|
} else if (this.shareType === 'team') {
|
2020-04-12 23:54:46 +02:00
|
|
|
this.stuffModel.teamId = this.sharable.id
|
2019-03-03 13:50:06 +01:00
|
|
|
}
|
|
|
|
this.stuffService.delete(this.stuffModel)
|
|
|
|
.then(() => {
|
|
|
|
this.showDeleteModal = false
|
|
|
|
for (const i in this.sharables) {
|
|
|
|
if (
|
2020-04-12 23:54:46 +02:00
|
|
|
(this.sharables[i].id === this.stuffModel.userId && this.shareType === 'user') ||
|
|
|
|
(this.sharables[i].id === this.stuffModel.teamId && this.shareType === 'team')
|
2019-03-03 13:50:06 +01:00
|
|
|
) {
|
|
|
|
this.sharables.splice(i, 1)
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 22:47:08 +01:00
|
|
|
this.success({message: 'The ' + this.shareType + ' was successfully deleted from the ' + this.typeString + '.'}, this)
|
2019-03-03 13:50:06 +01:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2020-01-30 22:47:08 +01:00
|
|
|
this.error(e, this)
|
2019-03-03 13:50:06 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
add(admin) {
|
|
|
|
if(admin === null) {
|
|
|
|
admin = false
|
|
|
|
}
|
|
|
|
this.stuffModel.right = rights.READ
|
|
|
|
if (admin) {
|
|
|
|
this.stuffModel.right = rights.ADMIN
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.shareType === 'user') {
|
2020-04-12 23:54:46 +02:00
|
|
|
this.stuffModel.userId = this.sharable.username
|
2019-03-03 13:50:06 +01:00
|
|
|
} else if (this.shareType === 'team') {
|
2020-04-12 23:54:46 +02:00
|
|
|
this.stuffModel.teamId = this.sharable.id
|
2019-03-03 13:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.stuffService.create(this.stuffModel)
|
|
|
|
.then(() => {
|
2020-01-30 22:47:08 +01:00
|
|
|
this.success({message: 'The ' + this.shareType + ' was successfully added.'}, this)
|
2019-03-03 13:50:06 +01:00
|
|
|
this.load()
|
|
|
|
})
|
|
|
|
.catch(e => {
|
2020-01-30 22:47:08 +01:00
|
|
|
this.error(e, this)
|
2019-03-03 13:50:06 +01:00
|
|
|
})
|
|
|
|
},
|
2020-02-26 20:34:14 +01:00
|
|
|
toggleType(sharable) {
|
2020-05-11 20:56:35 +02:00
|
|
|
if (this.selectedRight[sharable.id] !== rights.ADMIN &&
|
|
|
|
this.selectedRight[sharable.id] !== rights.READ &&
|
|
|
|
this.selectedRight[sharable.id] !== rights.READ_WRITE
|
2019-03-03 13:50:06 +01:00
|
|
|
) {
|
2020-05-11 20:56:35 +02:00
|
|
|
this.selectedRight[sharable.id] = rights.READ
|
2019-03-03 13:50:06 +01:00
|
|
|
}
|
2020-05-11 20:56:35 +02:00
|
|
|
this.stuffModel.right = this.selectedRight[sharable.id]
|
2019-03-03 13:50:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (this.shareType === 'user') {
|
2020-04-12 23:54:46 +02:00
|
|
|
this.stuffModel.userId = sharable.username
|
2019-03-03 13:50:06 +01:00
|
|
|
} else if (this.shareType === 'team') {
|
2020-04-12 23:54:46 +02:00
|
|
|
this.stuffModel.teamId = sharable.id
|
2019-03-03 13:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.stuffService.update(this.stuffModel)
|
|
|
|
.then(r => {
|
|
|
|
for (const i in this.sharables) {
|
|
|
|
if (
|
2020-05-11 20:56:35 +02:00
|
|
|
(this.sharables[i].username === this.stuffModel.userId && this.shareType === 'user') ||
|
2020-04-12 23:54:46 +02:00
|
|
|
(this.sharables[i].id === this.stuffModel.teamId && this.shareType === 'team')
|
2019-03-03 13:50:06 +01:00
|
|
|
) {
|
|
|
|
this.$set(this.sharables[i], 'right', r.right)
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 22:47:08 +01:00
|
|
|
this.success({message: 'The ' + this.shareType + ' right was successfully updated.'}, this)
|
2019-03-03 13:50:06 +01:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2020-01-30 22:47:08 +01:00
|
|
|
this.error(e, this)
|
2019-03-03 13:50:06 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
find(query) {
|
|
|
|
if(query === '') {
|
|
|
|
this.$set(this, 'found', [])
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this.searchService.getAll({}, {s: query})
|
|
|
|
.then(response => {
|
|
|
|
this.$set(this, 'found', response)
|
|
|
|
})
|
|
|
|
.catch(e => {
|
2020-01-30 22:47:08 +01:00
|
|
|
this.error(e, this)
|
2019-03-03 13:50:06 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
clearAll () {
|
|
|
|
this.$set(this, 'found', [])
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|