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
|
|
|
>
|
2022-05-22 14:59:43 +00:00
|
|
|
<Multiselect
|
2021-01-06 22:36:31 +00:00
|
|
|
: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>
|
|
|
|
|
2022-02-15 13:07:34 +01:00
|
|
|
<script lang="ts">
|
2022-05-22 14:59:43 +00:00
|
|
|
import {defineComponent, ShallowReactive, shallowReactive} from 'vue'
|
|
|
|
export default defineComponent({ name: 'userTeamShare' })
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import {ref, reactive, computed} from 'vue'
|
|
|
|
import type {PropType} from 'vue'
|
|
|
|
import {useStore} from 'vuex'
|
|
|
|
import {useI18n} from 'vue-i18n'
|
|
|
|
|
|
|
|
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/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'
|
2022-05-22 14:59:43 +00:00
|
|
|
import { success } from '@/message'
|
2019-03-03 12:50:06 +00:00
|
|
|
|
2022-05-22 14:59:43 +00:00
|
|
|
const props = defineProps({
|
|
|
|
type: {
|
|
|
|
type: String as PropType<'list' | 'namespace'>,
|
|
|
|
default: '',
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2022-05-22 14:59:43 +00:00
|
|
|
shareType: {
|
|
|
|
type: String as PropType<'user' | 'team' | 'namespace'>,
|
|
|
|
default: '',
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2022-05-22 14:59:43 +00:00
|
|
|
id: {
|
|
|
|
type: Number,
|
|
|
|
default: 0,
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2022-05-22 14:59:43 +00:00
|
|
|
userIsAdmin: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
2021-06-23 23:24:57 +00:00
|
|
|
},
|
2022-05-22 14:59:43 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const {t} = useI18n()
|
|
|
|
|
|
|
|
// This user service is either a userNamespaceService or a userListService, depending on the type we are using
|
|
|
|
let stuffService: ShallowReactive<UserNamespaceService | UserListService | TeamListService | TeamNamespaceService>
|
|
|
|
let stuffModel: UserNamespaceModel | UserListModel | TeamListModel | TeamNamespaceModel
|
|
|
|
let searchService: ShallowReactive<UserService | TeamService>
|
|
|
|
let sharable: UserModel | TeamModel
|
|
|
|
|
|
|
|
const searchLabel = ref('')
|
|
|
|
const selectedRight = ref({})
|
|
|
|
|
|
|
|
|
|
|
|
// This holds either teams or users who this namepace or list is shared with
|
|
|
|
const sharables = ref([])
|
|
|
|
const showDeleteModal = ref(false)
|
|
|
|
|
|
|
|
|
|
|
|
const store = useStore()
|
|
|
|
const userInfo = computed(() => store.state.auth.info)
|
|
|
|
|
|
|
|
function createShareTypeNameComputed(count: number) {
|
|
|
|
return computed(() => {
|
|
|
|
if (props.shareType === 'user') {
|
|
|
|
return t('list.share.userTeam.typeUser', count)
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
2019-03-03 12:50:06 +00:00
|
|
|
|
2022-05-22 14:59:43 +00:00
|
|
|
if (props.shareType === 'team') {
|
|
|
|
return t('list.share.userTeam.typeTeam', count)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ''
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const shareTypeNames = createShareTypeNameComputed(2)
|
|
|
|
const shareTypeName = createShareTypeNameComputed(1)
|
|
|
|
|
|
|
|
const sharableName = computed(() => {
|
|
|
|
if (props.type === 'list') {
|
|
|
|
return t('list.list.title')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props.shareType === 'namespace') {
|
|
|
|
return t('namespace.namespace')
|
|
|
|
}
|
|
|
|
|
|
|
|
return ''
|
2022-02-15 13:07:59 +01:00
|
|
|
})
|
2022-05-22 14:59:43 +00:00
|
|
|
|
|
|
|
if (props.shareType === 'user') {
|
|
|
|
searchService = shallowReactive(new UserService())
|
|
|
|
sharable = reactive(new UserModel())
|
|
|
|
searchLabel.value = 'username'
|
|
|
|
|
|
|
|
if (props.type === 'list') {
|
|
|
|
stuffService = shallowReactive(new UserListService())
|
|
|
|
stuffModel = reactive(new UserListModel({listId: props.id}))
|
|
|
|
} else if (props.type === 'namespace') {
|
|
|
|
stuffService = shallowReactive(new UserNamespaceService())
|
|
|
|
stuffModel = reactive(new UserNamespaceModel({
|
|
|
|
namespaceId: props.id,
|
|
|
|
}))
|
|
|
|
} else {
|
|
|
|
throw new Error('Unknown type: ' + props.type)
|
|
|
|
}
|
|
|
|
} else if (props.shareType === 'team') {
|
|
|
|
searchService = new TeamService()
|
|
|
|
sharable = reactive(new TeamModel())
|
|
|
|
searchLabel.value = 'name'
|
|
|
|
|
|
|
|
if (props.type === 'list') {
|
|
|
|
stuffService = shallowReactive(new TeamListService())
|
|
|
|
stuffModel = reactive(new TeamListModel({listId: props.id}))
|
|
|
|
} else if (props.type === 'namespace') {
|
|
|
|
stuffService = shallowReactive(new TeamNamespaceService())
|
|
|
|
stuffModel = reactive(new TeamNamespaceModel({
|
|
|
|
namespaceId: props.id,
|
|
|
|
}))
|
|
|
|
} else {
|
|
|
|
throw new Error('Unknown type: ' + props.type)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new Error('Unkown share type')
|
|
|
|
}
|
|
|
|
|
|
|
|
load()
|
|
|
|
|
|
|
|
async function load() {
|
|
|
|
sharables.value = await stuffService.getAll(stuffModel)
|
|
|
|
sharables.value.forEach(({id, right}) =>
|
|
|
|
selectedRight.value[id] = right,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function deleteSharable() {
|
|
|
|
if (props.shareType === 'user') {
|
|
|
|
stuffModel.userId = sharable.username
|
|
|
|
} else if (props.shareType === 'team') {
|
|
|
|
stuffModel.teamId = sharable.id
|
|
|
|
}
|
|
|
|
|
|
|
|
await stuffService.delete(stuffModel)
|
|
|
|
showDeleteModal.value = false
|
|
|
|
for (const i in sharables.value) {
|
|
|
|
if (
|
|
|
|
(sharables.value[i].username === stuffModel.userId && props.shareType === 'user') ||
|
|
|
|
(sharables.value[i].id === stuffModel.teamId && props.shareType === 'team')
|
|
|
|
) {
|
|
|
|
sharables.value.splice(i, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
success({message: t('list.share.userTeam.removeSuccess', {
|
|
|
|
type: shareTypeName.value,
|
|
|
|
sharable: sharableName.value,
|
|
|
|
})})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function add(admin) {
|
|
|
|
if (admin === null) {
|
|
|
|
admin = false
|
|
|
|
}
|
|
|
|
stuffModel.right = RIGHTS.READ
|
|
|
|
if (admin) {
|
|
|
|
stuffModel.right = RIGHTS.ADMIN
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props.shareType === 'user') {
|
|
|
|
stuffModel.userId = sharable.username
|
|
|
|
} else if (props.shareType === 'team') {
|
|
|
|
stuffModel.teamId = sharable.id
|
|
|
|
}
|
|
|
|
|
|
|
|
await stuffService.create(stuffModel)
|
|
|
|
success({message: t('list.share.userTeam.addedSuccess', {type: shareTypeName.value})})
|
|
|
|
await load()
|
|
|
|
}
|
|
|
|
|
|
|
|
async function toggleType(sharable) {
|
|
|
|
if (
|
|
|
|
selectedRight.value[sharable.id] !== RIGHTS.ADMIN &&
|
|
|
|
selectedRight.value[sharable.id] !== RIGHTS.READ &&
|
|
|
|
selectedRight.value[sharable.id] !== RIGHTS.READ_WRITE
|
|
|
|
) {
|
|
|
|
selectedRight.value[sharable.id] = RIGHTS.READ
|
|
|
|
}
|
|
|
|
stuffModel.right = selectedRight.value[sharable.id]
|
|
|
|
|
|
|
|
if (props.shareType === 'user') {
|
|
|
|
stuffModel.userId = sharable.username
|
|
|
|
} else if (props.shareType === 'team') {
|
|
|
|
stuffModel.teamId = sharable.id
|
|
|
|
}
|
|
|
|
|
|
|
|
const r = await stuffService.update(stuffModel)
|
|
|
|
for (const i in sharables.value) {
|
|
|
|
if (
|
|
|
|
(sharables.value[i].username ===
|
|
|
|
stuffModel.userId &&
|
|
|
|
props.shareType === 'user') ||
|
|
|
|
(sharables.value[i].id === stuffModel.teamId &&
|
|
|
|
props.shareType === 'team')
|
|
|
|
) {
|
|
|
|
sharables.value[i].right = r.right
|
|
|
|
}
|
|
|
|
}
|
|
|
|
success({message: t('list.share.userTeam.updatedSuccess', {type: shareTypeName.value})})
|
|
|
|
}
|
|
|
|
|
|
|
|
const found = ref([])
|
|
|
|
async function find(query) {
|
|
|
|
if (query === '') {
|
|
|
|
clearAll()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
found.value = await searchService.getAll({}, {s: query})
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearAll() {
|
|
|
|
found.value = []
|
|
|
|
}
|
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>
|