Skip to content

Commit 8d20663

Browse files
committed
fix(trashbin): restrict retore and delete on the frontend
Signed-off-by: Hamza <hamzamahjoubi221@gmail.com>
1 parent 62534af commit 8d20663

2 files changed

Lines changed: 41 additions & 10 deletions

File tree

src/components/AppNavigation/CalendarList/Trashbin.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@
7070
</td>
7171
<td>
7272
<div class="item-actions">
73-
<NcButton variant="secondary" @click="restore(item)">
73+
<NcButton v-if="item.canRestore" variant="secondary" @click="restore(item)">
7474
{{ t('calendar', 'Restore') }}
7575
</NcButton>
7676

77-
<NcActions :forceMenu="true">
77+
<NcActions v-if="item.canDelete" :forceMenu="item.canRestore">
7878
<NcActionButton @click="onDeletePermanently(item)">
7979
<template #icon>
8080
<IconDelete :size="20" decorative />
@@ -164,6 +164,7 @@ export default {
164164
url: calendar._url,
165165
deletedAt: calendar._props['{http://nextcloud.com/ns}deleted-at'],
166166
color: calendar.color ?? uidToHexColor(calendar.displayname),
167+
readonly: false,
167168
}))
168169
const formattedCalendarObjects = this.objects.map((vobject) => {
169170
let eventSummary = t('calendar', 'Untitled item')
@@ -185,6 +186,8 @@ export default {
185186
const color = vobject.calendarComponent.getComponentIterator().next().value?.color
186187
?? vobject.calendar?.color
187188
?? uidToHexColor(subline)
189+
const canDelete = vobject.calendar?.canDeleteObject
190+
const canRestore = vobject.calendar?.canCreateObject && vobject.calendar?.canModifyObject
188191
return {
189192
vobject,
190193
type: 'object',
@@ -194,6 +197,8 @@ export default {
194197
url: vobject.uri,
195198
deletedAt: vobject.dav._props['{http://nextcloud.com/ns}deleted-at'],
196199
color,
200+
canDelete,
201+
canRestore,
197202
}
198203
})
199204
@@ -281,6 +286,9 @@ export default {
281286
return
282287
}
283288
this.items.forEach((item) => {
289+
if (!this.canModify(item)) {
290+
return
291+
}
284292
this.onDeletePermanently(item)
285293
})
286294
},

src/store/calendars.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,40 @@ export default defineStore('calendars', {
126126
* @return {Array}
127127
*/
128128
allDeletedCalendarObjects(state) {
129-
const calendarUriMap = {}
129+
const lastSegment = (uri) => (uri ?? '').split('/').filter(Boolean).at(-1) ?? ''
130+
131+
const sourceUriOf = (calendar) => {
132+
const tail = lastSegment(calendar.url)
133+
const at = tail.lastIndexOf('_shared_by_')
134+
if (at > 0) {
135+
return tail.slice(0, at)
136+
}
137+
return tail
138+
}
139+
140+
// Key calendars by `${ownerUserId}|${sourceUri}` so deleted objects
141+
// match their origin calendar across owned/shared/delegated views.
142+
const calendarBySource = new Map()
130143
state.calendars.forEach((calendar) => {
131-
const withoutTrail = calendar.url.replace(/\/$/, '')
132-
const uri = withoutTrail.slice(withoutTrail.lastIndexOf('/') + 1)
133-
calendarUriMap[uri] = calendar
144+
let key = `${lastSegment(calendar.owner)}|${sourceUriOf(calendar)}`
145+
if (calendar.isDelegated) {
146+
key += lastSegment(calendar.delegatorUrl)
147+
}
148+
calendarBySource.set(key, calendar)
134149
})
135150

136-
return state.deletedCalendarObjects.map((obj) => ({
137-
calendar: calendarUriMap[obj.dav._props['{http://nextcloud.com/ns}calendar-uri']],
138-
...obj,
139-
}))
151+
return state.deletedCalendarObjects.map((obj) => {
152+
const owner = obj.dav.calendarOwnerPrincipalUri
153+
const sourceUri = obj.dav.sourceCalendarUri
154+
let key = `${lastSegment(owner)}|${sourceUri}`
155+
if (obj.dav.delegator) {
156+
key += lastSegment(obj.dav.delegator)
157+
}
158+
return {
159+
calendar: calendarBySource.get(key),
160+
...obj,
161+
}
162+
})
140163
},
141164

142165
/**

0 commit comments

Comments
 (0)