2019-03-03 12:50:06 +00:00
|
|
|
<template>
|
2021-01-30 16:17:04 +00:00
|
|
|
<div>
|
2021-06-23 23:24:57 +00:00
|
|
|
<p class="has-text-weight-bold">
|
|
|
|
{{ $t('list.share.userTeam.shared', {type: shareTypeNames}) }}
|
|
|
|
</p>
|
2021-01-30 16:17:04 +00:00
|
|
|
<div v-if="userIsAdmin">
|
2021-01-06 22:36:31 +00:00
|
|
|
<div class="field has-addons">
|
2021-01-17 17:57:57 +00:00
|
|
|
<p
|
|
|
|
class="control is-expanded"
|
2021-01-30 16:17:04 +00:00
|
|
|
:class="{ 'is-loading': searchService.loading }"
|
2021-01-17 17:57:57 +00:00
|
|
|
>
|
2021-01-06 22:36:31 +00:00
|
|
|
<multiselect
|
|
|
|
:loading="searchService.loading"
|
2021-06-23 23:24:57 +00:00
|
|
|
:placeholder="$t('misc.searchPlaceholder')"
|
2021-01-06 22:36:31 +00:00
|
|
|
@search="find"
|
|
|
|
:search-results="found"
|
|
|
|
:label="searchLabel"
|
|
|
|
v-model="sharable"
|
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
<p class="control">
|
2021-06-23 23:24:57 +00:00
|
|
|
<x-button @click="add()">{{ $t('list.share.share') }}</x-button>
|
2021-01-06 22:36:31 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-01-30 16:17:04 +00:00
|
|
|
|
|
|
|
<table class="table has-actions is-striped is-hoverable is-fullwidth mb-4" v-if="sharables.length > 0">
|
2021-01-06 22:36:31 +00:00
|
|
|
<tbody>
|
2021-01-23 18:54:22 +01:00
|
|
|
<tr :key="s.id" v-for="s in sharables">
|
|
|
|
<template v-if="shareType === 'user'">
|
|
|
|
<td>{{ s.getDisplayName() }}</td>
|
|
|
|
<td>
|
|
|
|
<template v-if="s.id === userInfo.id">
|
2021-06-23 23:24:57 +00:00
|
|
|
<b class="is-success">{{ $t('list.share.userTeam.you') }}</b>
|
2021-01-23 18:54:22 +01:00
|
|
|
</template>
|
|
|
|
</td>
|
|
|
|
</template>
|
|
|
|
<template v-if="shareType === 'team'">
|
|
|
|
<td>
|
|
|
|
<router-link
|
|
|
|
:to="{
|
2021-01-17 17:57:57 +00:00
|
|
|
name: 'teams.edit',
|
|
|
|
params: { id: s.id },
|
|
|
|
}"
|
2021-01-23 18:54:22 +01:00
|
|
|
>
|
|
|
|
{{ s.name }}
|
|
|
|
</router-link>
|
|
|
|
</td>
|
|
|
|
</template>
|
|
|
|
<td class="type">
|
|
|
|
<template v-if="s.right === rights.ADMIN">
|
2019-03-03 12:50:06 +00:00
|
|
|
<span class="icon is-small">
|
2021-01-23 18:54:22 +01:00
|
|
|
<icon icon="lock"/>
|
2019-03-03 12:50:06 +00:00
|
|
|
</span>
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('list.share.right.admin') }}
|
2021-01-23 18:54:22 +01:00
|
|
|
</template>
|
|
|
|
<template v-else-if="s.right === rights.READ_WRITE">
|
2019-03-03 12:50:06 +00:00
|
|
|
<span class="icon is-small">
|
2021-01-23 18:54:22 +01:00
|
|
|
<icon icon="pen"/>
|
2019-03-03 12:50:06 +00:00
|
|
|
</span>
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('list.share.right.readWrite') }}
|
2021-01-23 18:54:22 +01:00
|
|
|
</template>
|
|
|
|
<template v-else>
|
2021-01-17 17:57:57 +00:00
|
|
|
<span class="icon is-small">
|
2021-01-23 18:54:22 +01:00
|
|
|
<icon icon="users"/>
|
2019-03-03 12:50:06 +00:00
|
|
|
</span>
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('list.share.right.read') }}
|
2021-01-23 18:54:22 +01:00
|
|
|
</template>
|
|
|
|
</td>
|
|
|
|
<td class="actions" v-if="userIsAdmin">
|
|
|
|
<div class="select">
|
|
|
|
<select
|
|
|
|
@change="toggleType(s)"
|
2021-10-20 12:20:12 +02:00
|
|
|
class="mr-2"
|
2021-01-23 18:54:22 +01:00
|
|
|
v-model="selectedRight[s.id]"
|
|
|
|
>
|
|
|
|
<option
|
|
|
|
:selected="s.right === rights.READ"
|
|
|
|
:value="rights.READ"
|
|
|
|
>
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('list.share.right.read') }}
|
2021-01-23 18:54:22 +01:00
|
|
|
</option>
|
|
|
|
<option
|
|
|
|
:selected="s.right === rights.READ_WRITE"
|
|
|
|
:value="rights.READ_WRITE"
|
|
|
|
>
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('list.share.right.readWrite') }}
|
2021-01-23 18:54:22 +01:00
|
|
|
</option>
|
|
|
|
<option
|
|
|
|
:selected="s.right === rights.ADMIN"
|
|
|
|
:value="rights.ADMIN"
|
2021-01-17 17:57:57 +00:00
|
|
|
>
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('list.share.right.admin') }}
|
2021-01-23 18:54:22 +01:00
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<x-button
|
|
|
|
@click="
|
2021-01-17 17:57:57 +00:00
|
|
|
() => {
|
|
|
|
sharable = s
|
|
|
|
showDeleteModal = true
|
|
|
|
}
|
|
|
|
"
|
2021-01-23 18:54:22 +01:00
|
|
|
class="is-danger"
|
|
|
|
icon="trash-alt"
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
2021-01-06 22:36:31 +00:00
|
|
|
</tbody>
|
|
|
|
</table>
|
2019-03-03 12:50:06 +00:00
|
|
|
|
2021-01-30 16:17:04 +00:00
|
|
|
<nothing v-else>
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('list.share.userTeam.notShared', {type: shareTypeNames}) }}
|
2021-01-30 16:17:04 +00:00
|
|
|
</nothing>
|
|
|
|
|
2021-01-23 18:54:22 +01:00
|
|
|
<transition name="modal">
|
|
|
|
<modal
|
|
|
|
@close="showDeleteModal = false"
|
|
|
|
@submit="deleteSharable()"
|
|
|
|
v-if="showDeleteModal"
|
|
|
|
>
|
2021-08-19 19:55:13 +02:00
|
|
|
<template #header>
|
|
|
|
<span>{{ $t('list.share.userTeam.removeHeader', {type: shareTypeName, sharable: sharableName}) }}</span>
|
|
|
|
</template>
|
|
|
|
<template #text>
|
|
|
|
<p>{{ $t('list.share.userTeam.removeText', {type: shareTypeName, sharable: sharableName}) }}</p>
|
|
|
|
</template>
|
2021-01-23 18:54:22 +01:00
|
|
|
</modal>
|
|
|
|
</transition>
|
2021-01-30 16:17:04 +00:00
|
|
|
</div>
|
2019-03-03 12:50:06 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-09-05 22:35:52 +02: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'
|
2019-03-03 12:50:06 +00:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
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'
|
2019-03-03 12:50:06 +00:00
|
|
|
|
2021-09-10 14:21:33 +00:00
|
|
|
import rights from '../../models/constants/rights.json'
|
2021-07-25 13:27:15 +00:00
|
|
|
import Multiselect from '@/components/input/multiselect.vue'
|
|
|
|
import Nothing from '@/components/misc/nothing.vue'
|
2019-03-03 12:50:06 +00:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
export default {
|
|
|
|
name: 'userTeamShare',
|
|
|
|
props: {
|
|
|
|
type: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
2019-03-03 12:50:06 +00:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
shareType: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
2019-03-03 12:50:06 +00:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
id: {
|
|
|
|
type: Number,
|
|
|
|
default: 0,
|
2019-03-03 12:50:06 +00:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
userIsAdmin: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
|
|
|
|
found: [],
|
|
|
|
searchLabel: '',
|
|
|
|
rights: rights,
|
|
|
|
selectedRight: {},
|
|
|
|
|
|
|
|
typeString: '',
|
|
|
|
sharables: [], // This holds either teams or users who this namepace or list is shared with
|
|
|
|
showDeleteModal: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2021-01-30 16:17:04 +00:00
|
|
|
Nothing,
|
2021-01-06 22:36:31 +00:00
|
|
|
Multiselect,
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2021-06-23 23:24:57 +00:00
|
|
|
computed: {
|
|
|
|
userInfo() {
|
|
|
|
return this.$store.state.auth.info
|
|
|
|
},
|
|
|
|
shareTypeNames() {
|
|
|
|
if (this.shareType === 'user') {
|
|
|
|
return this.$tc('list.share.userTeam.typeUser', 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.shareType === 'team') {
|
|
|
|
return this.$tc('list.share.userTeam.typeTeam', 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ''
|
|
|
|
},
|
|
|
|
shareTypeName() {
|
|
|
|
if (this.shareType === 'user') {
|
|
|
|
return this.$tc('list.share.userTeam.typeUser', 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.shareType === 'team') {
|
|
|
|
return this.$tc('list.share.userTeam.typeTeam', 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ''
|
|
|
|
},
|
|
|
|
sharableName() {
|
|
|
|
if (this.type === 'list') {
|
|
|
|
return this.$t('list.list.title')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.shareType === 'namespace') {
|
|
|
|
return this.$t('namespace.namespace')
|
|
|
|
}
|
|
|
|
|
|
|
|
return ''
|
|
|
|
},
|
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
created() {
|
|
|
|
if (this.shareType === 'user') {
|
|
|
|
this.searchService = new UserService()
|
|
|
|
this.sharable = new UserModel()
|
|
|
|
this.searchLabel = 'username'
|
2019-03-03 12:50:06 +00:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
if (this.type === 'list') {
|
2021-07-17 21:21:46 +00:00
|
|
|
this.typeString = 'list'
|
2020-09-05 22:35:52 +02:00
|
|
|
this.stuffService = new UserListService()
|
2021-01-23 18:54:22 +01:00
|
|
|
this.stuffModel = new UserListModel({listId: this.id})
|
2020-09-05 22:35:52 +02:00
|
|
|
} else if (this.type === 'namespace') {
|
2021-07-17 21:21:46 +00:00
|
|
|
this.typeString = 'namespace'
|
2020-09-05 22:35:52 +02:00
|
|
|
this.stuffService = new UserNamespaceService()
|
2021-01-17 17:57:57 +00:00
|
|
|
this.stuffModel = new UserNamespaceModel({
|
|
|
|
namespaceId: this.id,
|
|
|
|
})
|
2020-09-05 22:35:52 +02:00
|
|
|
} else {
|
|
|
|
throw new Error('Unknown type: ' + this.type)
|
2019-03-03 12:50:06 +00:00
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
} else if (this.shareType === 'team') {
|
|
|
|
this.searchService = new TeamService()
|
|
|
|
this.sharable = new TeamModel()
|
|
|
|
this.searchLabel = 'name'
|
2019-03-03 12:50:06 +00:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
if (this.type === 'list') {
|
2021-07-17 21:21:46 +00:00
|
|
|
this.typeString = 'list'
|
2020-09-05 22:35:52 +02:00
|
|
|
this.stuffService = new TeamListService()
|
2021-01-23 18:54:22 +01:00
|
|
|
this.stuffModel = new TeamListModel({listId: this.id})
|
2020-09-05 22:35:52 +02:00
|
|
|
} else if (this.type === 'namespace') {
|
2021-07-17 21:21:46 +00:00
|
|
|
this.typeString = 'namespace'
|
2020-09-05 22:35:52 +02:00
|
|
|
this.stuffService = new TeamNamespaceService()
|
2021-01-17 17:57:57 +00:00
|
|
|
this.stuffModel = new TeamNamespaceModel({
|
|
|
|
namespaceId: this.id,
|
|
|
|
})
|
2019-03-03 12:50:06 +00:00
|
|
|
} else {
|
2020-09-05 22:35:52 +02:00
|
|
|
throw new Error('Unknown type: ' + this.type)
|
2019-03-03 12:50:06 +00:00
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
} else {
|
|
|
|
throw new Error('Unkown share type')
|
|
|
|
}
|
2019-03-03 12:50:06 +00:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
this.load()
|
|
|
|
},
|
|
|
|
methods: {
|
2021-10-11 19:37:20 +02:00
|
|
|
async load() {
|
|
|
|
this.sharables = await this.stuffService.getAll(this.stuffModel)
|
|
|
|
this.sharables.forEach((s) =>
|
|
|
|
this.selectedRight[s.id] = s.right,
|
|
|
|
)
|
2019-03-03 12:50:06 +00:00
|
|
|
},
|
2021-10-11 19:37:20 +02:00
|
|
|
|
|
|
|
async deleteSharable() {
|
2020-09-05 22:35:52 +02:00
|
|
|
if (this.shareType === 'user') {
|
|
|
|
this.stuffModel.userId = this.sharable.username
|
|
|
|
} else if (this.shareType === 'team') {
|
|
|
|
this.stuffModel.teamId = this.sharable.id
|
|
|
|
}
|
2021-05-26 17:32:03 +02:00
|
|
|
|
2021-10-11 19:37:20 +02:00
|
|
|
await this.stuffService.delete(this.stuffModel)
|
|
|
|
this.showDeleteModal = false
|
|
|
|
for (const i in this.sharables) {
|
|
|
|
if (
|
|
|
|
(this.sharables[i].username === this.stuffModel.userId && this.shareType === 'user') ||
|
|
|
|
(this.sharables[i].id === this.stuffModel.teamId && this.shareType === 'team')
|
|
|
|
) {
|
|
|
|
this.sharables.splice(i, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.$message.success({message: this.$t('list.share.userTeam.removeSuccess', {type: this.shareTypeName, sharable: this.sharableName})})
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2021-10-11 19:37:20 +02:00
|
|
|
|
|
|
|
async add(admin) {
|
2020-09-05 22:35:52 +02:00
|
|
|
if (admin === null) {
|
|
|
|
admin = false
|
|
|
|
}
|
|
|
|
this.stuffModel.right = rights.READ
|
|
|
|
if (admin) {
|
|
|
|
this.stuffModel.right = rights.ADMIN
|
|
|
|
}
|
2019-03-03 12:50:06 +00:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
if (this.shareType === 'user') {
|
|
|
|
this.stuffModel.userId = this.sharable.username
|
|
|
|
} else if (this.shareType === 'team') {
|
|
|
|
this.stuffModel.teamId = this.sharable.id
|
|
|
|
}
|
2019-03-03 12:50:06 +00:00
|
|
|
|
2021-10-11 19:37:20 +02:00
|
|
|
await this.stuffService.create(this.stuffModel)
|
|
|
|
this.$message.success({message: this.$t('list.share.userTeam.addedSuccess', {type: this.shareTypeName})})
|
|
|
|
await this.load()
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2021-10-11 19:37:20 +02:00
|
|
|
|
|
|
|
async toggleType(sharable) {
|
2021-01-17 17:57:57 +00:00
|
|
|
if (
|
|
|
|
this.selectedRight[sharable.id] !== rights.ADMIN &&
|
2020-09-05 22:35:52 +02:00
|
|
|
this.selectedRight[sharable.id] !== rights.READ &&
|
|
|
|
this.selectedRight[sharable.id] !== rights.READ_WRITE
|
|
|
|
) {
|
|
|
|
this.selectedRight[sharable.id] = rights.READ
|
|
|
|
}
|
|
|
|
this.stuffModel.right = this.selectedRight[sharable.id]
|
2019-03-03 12:50:06 +00:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
if (this.shareType === 'user') {
|
|
|
|
this.stuffModel.userId = sharable.username
|
|
|
|
} else if (this.shareType === 'team') {
|
|
|
|
this.stuffModel.teamId = sharable.id
|
|
|
|
}
|
2019-03-03 12:50:06 +00:00
|
|
|
|
2021-10-11 19:37:20 +02:00
|
|
|
const r = await this.stuffService.update(this.stuffModel)
|
|
|
|
for (const i in this.sharables) {
|
|
|
|
if (
|
|
|
|
(this.sharables[i].username ===
|
|
|
|
this.stuffModel.userId &&
|
|
|
|
this.shareType === 'user') ||
|
|
|
|
(this.sharables[i].id === this.stuffModel.teamId &&
|
|
|
|
this.shareType === 'team')
|
|
|
|
) {
|
|
|
|
this.sharables[i].right = r.right
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.$message.success({message: this.$t('list.share.userTeam.updatedSuccess', {type: this.shareTypeName})})
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2021-10-11 19:37:20 +02:00
|
|
|
|
|
|
|
async find(query) {
|
2020-09-05 22:35:52 +02:00
|
|
|
if (query === '') {
|
2021-08-19 21:35:38 +02:00
|
|
|
this.clearAll()
|
2020-09-05 22:35:52 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:37:20 +02:00
|
|
|
this.found = await this.searchService.getAll({}, {s: query})
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2021-10-11 19:37:20 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
clearAll() {
|
2021-08-19 21:35:38 +02:00
|
|
|
this.found = []
|
2019-03-03 12:50:06 +00:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
}
|
2019-03-03 12:50:06 +00:00
|
|
|
</script>
|
2021-11-08 15:46:39 +01:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@include modal-transition();
|
|
|
|
</style>
|