Merge pull request #902 from nextcloud/fix/887

Prevent moving non-public tasks to calendars shared with me
This commit is contained in:
Raimund Schlüßler 2020-03-07 21:04:17 +01:00 committed by GitHub
commit 1946a9fc90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 9 deletions

View file

@ -62,7 +62,8 @@
}
&.dnd-hover {
background-color: rgba( $color-primary, .3 );
// background-color: rgba( $color-primary, .1 ); didn't work for some reason
background-color: transparentize( $color-primary, .9 );
}
button {
@ -446,7 +447,8 @@
}
&.sortable-ghost .task-body {
background-color: rgba( $color-primary, .3 );
// background-color: rgba( $color-primary, .1 ); didn't work for some reason
background-color: transparentize( $color-primary, .9 );
}
.subtasks-container {

View file

@ -307,6 +307,15 @@ export default {
if (this.calendar.readOnly) {
return
}
if (this.calendar.isSharedWithMe) {
const taskUri = e.dataTransfer.getData('text/plain')
if (taskUri) {
const task = this.getTask(taskUri)
if (task.class !== 'PUBLIC') {
return
}
}
}
// Get the correct element, in case we hover a child.
if (e.target.closest) {
const target = e.target.closest('li.list')

View file

@ -23,7 +23,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
<template>
<li v-show="showTask"
:task-id="task.uri"
:class="{done: task.completed, readOnly: task.calendar.readOnly, deleted: !!deleteTimeout}"
:class="{done: task.completed, readOnly: readOnly, deleted: !!deleteTimeout}"
:data-priority="[task.priority]"
class="task-item"
@dragstart="dragStart($event)">
@ -38,10 +38,10 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
type="checkbox"
class="checkbox no-nav"
name="toggleCompleted"
:class="{'disabled': task.calendar.readOnly}"
:class="{'disabled': readOnly}"
:checked="task.completed"
:aria-checked="task.completed"
:disabled="task.calendar.readOnly"
:disabled="readOnly"
:aria-label="$t('tasks', 'Task is completed')"
@click="toggleCompleted(task)">
<label class="reactive no-nav" :for="'toggleCompleted_' + task.uid" />
@ -120,7 +120,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
</ActionButton>
</Actions>
<button class="inline task-star reactive no-nav" @click="toggleStarred(task)">
<span :class="[iconStar, {'disabled': task.calendar.readOnly}]" class="icon" />
<span :class="[iconStar, {'disabled': readOnly}]" class="icon" />
</button>
</div>
</div>

View file

@ -24,6 +24,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
:list="['']"
:set-data="setDragData"
v-bind="{group: 'tasks', swapThreshold: 0.30, delay: 500, delayOnTouchOnly: true, touchStartThreshold: 3, disabled: disabled, filter: '.readOnly'}"
:move="onMove"
@add="onAdd">
<slot />
</draggable>
@ -81,6 +82,44 @@ export default {
$event.stopPropagation()
},
/**
* Called when a task is moved.
* We check here if drop onto the target is allowed.
*
* Dropping tasks with class not PUBLIC onto calendars shared with me
* is forbidden.
*
* @param {Object} $event The event which caused the move
* @returns {Boolean} If the drop is allowed
*/
onMove($event) {
// The task to move
const taskAttribute = $event.dragged.attributes['task-id']
if (taskAttribute) {
const task = this.getTask(taskAttribute.value)
if (task.class === 'PUBLIC') {
return true
}
let calendar
const calendarAttribute = $event.to.attributes['calendar-id']
if (calendarAttribute) {
calendar = this.getCalendar(calendarAttribute.value)
}
if (!calendar) {
const parentAttribute = $event.to.attributes['task-id']
if (parentAttribute) {
const parent = this.getTask(parentAttribute.value)
// If we move to a parent task, the calendar has to be the parents calendar.
calendar = parent.calendar
}
}
if (calendar && calendar.isSharedWithMe) {
return false
}
}
return true
},
/**
* Function to move a task to a new calendar or parent
*

View file

@ -184,7 +184,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
track-by="id"
:placeholder="$t('tasks', 'Select a calendar')"
label="displayName"
:options="writableCalendars"
:options="targetCalendars"
:close-on-select="true"
class="multiselect-vue"
@input="changeCalendar"
@ -656,6 +656,15 @@ export default {
return 'icon-sprt-bw sprt-current'
}
},
targetCalendars() {
let calendars = this.writableCalendars
// Tasks with an access class other than PUBLIC cannot be moved
// into calendars shared with me
if (this.task.class !== 'PUBLIC') {
calendars = calendars.filter(calendar => !calendar.isSharedWithMe)
}
return calendars
},
...mapGetters({
writableCalendars: 'getSortedWritableCalendars',
task: 'getTaskByRoute',

View file

@ -1183,8 +1183,8 @@ const actions = {
if (task.calendar.readOnly) {
return task
}
// Don't move tasks in shared calendars with access class not PUBLIC
if (task.calendar.isSharedWithMe && task.class !== 'PUBLIC') {
// Don't move tasks with access class not PUBLIC from or to calendars shared with me
if ((task.calendar.isSharedWithMe || calendar.isSharedWithMe) && task.class !== 'PUBLIC') {
return
}
// Don't move if source and target calendar are the same.