fix(tasks): don't allow adding the same assignee multiple times
continuous-integration/drone/push Build is passing Details

See https://community.vikunja.io/t/task-can-be-assigned-twice-or-more-to-the-same-user/883
This commit is contained in:
kolaente 2022-10-06 18:03:17 +02:00
parent d4c179c862
commit bc1e366750
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 64 additions and 45 deletions

View File

@ -28,7 +28,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {ref, shallowReactive, watch, type PropType} from 'vue' import {ref, shallowReactive, watch, nextTick, type PropType} from 'vue'
import {useI18n} from 'vue-i18n' import {useI18n} from 'vue-i18n'
import User from '@/components/misc/user.vue' import User from '@/components/misc/user.vue'
@ -58,7 +58,7 @@ const props = defineProps({
type: Array as PropType<IUser[]>, type: Array as PropType<IUser[]>,
default: () => [], default: () => [],
}, },
}) })
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
const taskStore = useTaskStore() const taskStore = useTaskStore()
@ -67,6 +67,7 @@ const {t} = useI18n({useScope: 'global'})
const listUserService = shallowReactive(new ListUserService()) const listUserService = shallowReactive(new ListUserService())
const foundUsers = ref([]) const foundUsers = ref([])
const assignees = ref<IUser[]>([]) const assignees = ref<IUser[]>([])
let isAdding = false
watch( watch(
() => props.modelValue, () => props.modelValue,
@ -80,9 +81,19 @@ watch(
) )
async function addAssignee(user: IUser) { async function addAssignee(user: IUser) {
if (isAdding) {
return
}
try {
nextTick(() => isAdding = true)
await taskStore.addAssignee({user: user, taskId: props.taskId}) await taskStore.addAssignee({user: user, taskId: props.taskId})
emit('update:modelValue', assignees.value) emit('update:modelValue', assignees.value)
success({message: t('task.assignee.assignSuccess')}) success({message: t('task.assignee.assignSuccess')})
} finally {
nextTick(() => isAdding = false)
}
} }
async function removeAssignee(user: IUser) { async function removeAssignee(user: IUser) {
@ -119,6 +130,7 @@ function clearAllFoundUsers() {
} }
const multiselect = ref() const multiselect = ref()
function focus() { function focus() {
multiselect.value.focus() multiselect.value.focus()
} }

View File

@ -171,6 +171,9 @@ export const useTaskStore = defineStore('task', {
user: IUser, user: IUser,
taskId: ITask['id'] taskId: ITask['id']
}) { }) {
const cancel = setModuleLoading(this)
try {
const kanbanStore = useKanbanStore() const kanbanStore = useKanbanStore()
const taskAssigneeService = new TaskAssigneeService() const taskAssigneeService = new TaskAssigneeService()
const r = await taskAssigneeService.create(new TaskAssigneeModel({ const r = await taskAssigneeService.create(new TaskAssigneeModel({
@ -196,7 +199,11 @@ export const useTaskStore = defineStore('task', {
], ],
}, },
}) })
return r return r
} finally {
cancel()
}
}, },
async removeAssignee({ async removeAssignee({