Skip to content

Commit 3559cd2

Browse files
fix: use proper view mode and object permissions
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
1 parent edc5724 commit 3559cd2

12 files changed

Lines changed: 33 additions & 39 deletions

File tree

src/components/AppNavigation/CalendarList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const delegatedGroups = computed<DelegatedGroup[]>(() => {
7474
groups.set(delegatorUrl, {
7575
delegatorUrl,
7676
displayname: principal?.displayname || principal?.userId || '',
77-
readOnly: !!calendar.readOnly,
77+
readOnly: !calendar.canCreateObject && !calendar.canModifyObject,
7878
calendars: [],
7979
})
8080
}

src/components/AppNavigation/Settings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ export default {
359359
360360
defaultCalendarOptions() {
361361
return this.calendarsStore.calendars
362-
.filter((calendar) => !calendar.readOnly
362+
.filter((calendar) => (calendar.canCreateObject || calendar.canModifyObject)
363363
&& !calendar.isSharedWithMe
364364
&& calendar.supportsEvents)
365365
},

src/fullcalendar/eventSources/eventSource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default function() {
5959
},
6060
}
6161

62-
if (calendar.readOnly) {
62+
if (!calendar.canCreateObject && !calendar.canModifyObject) {
6363
source.editable = false
6464
}
6565

src/mixins/EditorMixin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,11 @@ export default {
317317
if (!this.calendarObject) {
318318
return false
319319
}
320-
if (this.isReadOnly) {
320+
if (this.isLoading) {
321321
return false
322322
}
323-
if (this.isLoading) {
323+
const calendar = this.calendarsStore.getCalendarById(this.calendarObject.calendarId)
324+
if (!calendar?.canDeleteObject) {
324325
return false
325326
}
326327

src/models/calendar.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ function getDefaultCalendarObject(props = {}) {
3939
publishURL: null,
4040
// Internal CalDAV url of this calendar
4141
url: '',
42-
// Whether this calendar is read-only
43-
readOnly: false,
4442
// The order of this calendar in the calendar-list
4543
order: 0,
4644
// Whether or not the calendar is shared with me
@@ -99,7 +97,6 @@ function mapDavCollectionToCalendar(calendar, currentUserPrincipal) {
9997
const supportsJournals = calendar.components.includes('VJOURNAL')
10098
const supportsTasks = calendar.components.includes('VTODO')
10199
const owner = calendar.owner
102-
const readOnly = !calendar.isWriteable()
103100
const canBeShared = calendar.isShareable()
104101
const canBePublished = calendar.isPublishable()
105102
const canCreateObject = calendar.currentUserPrivilegeSet.includes('{DAV:}bind') || calendar.currentUserPrivilegeSet.includes('{DAV:}write') || calendar.currentUserPrivilegeSet.includes('{DAV:}all') === true
@@ -160,7 +157,6 @@ function mapDavCollectionToCalendar(calendar, currentUserPrincipal) {
160157
supportsTasks,
161158
isSharedWithMe,
162159
owner,
163-
readOnly,
164160
publishURL,
165161
canBeShared,
166162
canBePublished,

src/store/calendars.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default defineStore('calendars', {
7474
sortedCalendars(state) {
7575
return state.calendars
7676
.filter((calendar) => calendar.supportsEvents)
77-
.filter((calendar) => !calendar.readOnly)
77+
.filter((calendar) => calendar.canCreateObject || calendar.canModifyObject)
7878
.sort((a, b) => a.order - b.order)
7979
},
8080

@@ -101,7 +101,7 @@ export default defineStore('calendars', {
101101
*/
102102
sortedWritableCalendarsEvenWithoutSupportForEvents(state) {
103103
return state.calendars
104-
.filter((calendar) => !calendar.readOnly)
104+
.filter((calendar) => calendar.canCreateObject || calendar.canModifyObject)
105105
.sort((a, b) => a.order - b.order)
106106
},
107107

@@ -114,7 +114,7 @@ export default defineStore('calendars', {
114114
ownSortedCalendars(state) {
115115
return state.calendars
116116
.filter((calendar) => calendar.supportsEvents)
117-
.filter((calendar) => !calendar.readOnly)
117+
.filter((calendar) => calendar.canCreateObject || calendar.canModifyObject)
118118
.filter((calendar) => !calendar.isSharedWithMe)
119119
.sort((a, b) => a.order - b.order)
120120
},
@@ -186,7 +186,7 @@ export default defineStore('calendars', {
186186
sortedSubscriptions(state) {
187187
return state.calendars
188188
.filter((calendar) => calendar.supportsEvents)
189-
.filter((calendar) => calendar.readOnly)
189+
.filter((calendar) => !(calendar.canCreateObject || calendar.canModifyObject))
190190
.sort((a, b) => a.order - b.order)
191191
},
192192

src/store/delegation.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ export default defineStore('delegation', () => {
168168
* The calendars are tagged with isDelegated=true so CalendarList can show them
169169
* in their own section.
170170
*
171-
* Read-only delegators' calendars are additionally marked readOnly=true so they
172-
* are excluded from the calendar picker (which only lists writable calendars).
171+
* Read-only delegators' calendars additionally have their write permissions
172+
* cleared so they are excluded from the calendar picker (which only lists
173+
* calendars with canCreateObject or canModifyObject).
173174
*/
174175
async function fetchDelegatedCalendars(): Promise<void> {
175176
if (!delegators.value.length) {
@@ -200,7 +201,7 @@ export default defineStore('delegation', () => {
200201
isDelegated: true,
201202
delegatorUrl: canonicalDelegatorUrl,
202203
// Read-only proxy access: prevent editing and hide from calendar picker
203-
...(permission === 'read' ? { readOnly: true } : {}),
204+
...(permission === 'read' ? { canCreateObject: false, canModifyObject: false, canDeleteObject: false } : {}),
204205
}))
205206

206207
for (const calendar of mappedCalendars) {

src/types/calendar.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ export interface CalendarInterface {
6666
publishURL: string | null
6767
/** Internal CalDAV url of this calendar */
6868
url: string
69-
/** Whether this calendar is read-only */
70-
readOnly: boolean
7169
/** The order of this calendar in the calendar-list */
7270
order: number
7371
/** Whether the calendar is shared with the current user */

src/views/Calendar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ export default {
375375
})
376376
377377
const writeableCalendarIndex = calendars.findIndex((calendar) => {
378-
return !calendar.readOnly
378+
return calendar.canCreateObject || calendar.canModifyObject
379379
})
380380
381381
// No writeable calendars? Create a new one!

tests/javascript/unit/fullcalendar/eventSources/eventSource.test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ describe('fullcalendar/eventSource test suite', () => {
3232
const calendar = {
3333
id: 'calendar-id-123',
3434
color: '#ff00ff',
35-
readOnly: false,
35+
canCreateObject: true,
36+
canModifyObject: true,
3637
}
3738

3839
const eventSourceFunction = eventSource()
@@ -52,7 +53,8 @@ describe('fullcalendar/eventSource test suite', () => {
5253
const calendar = {
5354
id: 'calendar-id-123',
5455
color: '#ff00ff',
55-
readOnly: true,
56+
canCreateObject: false,
57+
canModifyObject: false,
5658
}
5759

5860
const eventSourceFunction = eventSource()
@@ -82,7 +84,8 @@ describe('fullcalendar/eventSource test suite', () => {
8284
const calendar = {
8385
id: 'calendar-id-123',
8486
color: '#ff00ff',
85-
readOnly: true,
87+
canCreateObject: false,
88+
canModifyObject: false,
8689
}
8790

8891
const getTimezoneForId = vi.fn()
@@ -151,7 +154,8 @@ describe('fullcalendar/eventSource test suite', () => {
151154
const calendar = {
152155
id: 'calendar-id-123',
153156
color: '#ff00ff',
154-
readOnly: true,
157+
canCreateObject: false,
158+
canModifyObject: false,
155159
}
156160

157161
const getTimezoneForId = vi.fn()
@@ -215,7 +219,8 @@ describe('fullcalendar/eventSource test suite', () => {
215219
const calendar = {
216220
id: 'calendar-id-123',
217221
color: '#ff00ff',
218-
readOnly: true,
222+
canCreateObject: false,
223+
canModifyObject: false,
219224
}
220225

221226
const getTimezoneForId = vi.fn()
@@ -282,7 +287,8 @@ describe('fullcalendar/eventSource test suite', () => {
282287
const calendar = {
283288
id: 'calendar-id-123',
284289
color: '#ff00ff',
285-
readOnly: true,
290+
canCreateObject: false,
291+
canModifyObject: false,
286292
}
287293

288294
const getTimezoneForId = vi.fn()

0 commit comments

Comments
 (0)