@@ -9,6 +9,7 @@ import { computed, ref } from 'vue'
99import { mapDavCollectionToCalendar } from '../models/calendar.js'
1010import { mapDavToPrincipal } from '../models/principal.js'
1111import { findCalendarsAtUrl , findPrincipalByUrl , getClient } from '../services/caldavService.js'
12+
1213import logger from '../utils/logger.js'
1314import useCalendarsStore from './calendars.js'
1415import usePrincipalsStore from './principals.js'
@@ -65,17 +66,12 @@ export default defineStore('delegation', () => {
6566 return
6667 }
6768
68- const baseUrl = currentUser . url . replace ( / \/ ? $ / , '' )
69- const proxyWriteGroupUrl = baseUrl + '/calendar-proxy-write'
70- const proxyReadGroupUrl = baseUrl + '/calendar-proxy-read'
71-
7269 let writeUrls : string [ ] = [ ]
7370 let readUrls : string [ ] = [ ]
7471 try {
75- [ writeUrls , readUrls ] = await Promise . all ( [
76- getClient ( ) . getDelegateUrls ( proxyWriteGroupUrl ) ,
77- getClient ( ) . getDelegateUrls ( proxyReadGroupUrl ) ,
78- ] )
72+ const delegates = await getClient ( ) . getDelegatesForPrincipal ( currentUser . url )
73+ writeUrls = delegates . write
74+ readUrls = delegates . read
7975 } catch ( error ) {
8076 logger . error ( 'Could not fetch delegate URLs' , { error } )
8177 return
@@ -141,11 +137,7 @@ export default defineStore('delegation', () => {
141137 return
142138 }
143139
144- const baseUrl = currentUser . url . replace ( / \/ ? $ / , '' )
145- const proxyGroupUrl = permission === 'read'
146- ? baseUrl + '/calendar-proxy-read'
147- : baseUrl + '/calendar-proxy-write'
148- await getClient ( ) . addDelegate ( proxyGroupUrl , principalUrl )
140+ await getClient ( ) . addDelegate ( currentUser . url , principalUrl , permission )
149141 await fetchDelegates ( )
150142 }
151143
@@ -161,15 +153,11 @@ export default defineStore('delegation', () => {
161153 return
162154 }
163155
164- const baseUrl = currentUser . url . replace ( / \/ ? $ / , '' )
165156 // Find the delegate's current permission so we remove from the right group.
166157 const existing = delegates . value . find ( ( d ) => d . url === principalUrl )
167158 const permission = existing ?. permission ?? 'write'
168159
169- const proxyGroupUrl = permission === 'read'
170- ? baseUrl + '/calendar-proxy-read'
171- : baseUrl + '/calendar-proxy-write'
172- await getClient ( ) . removeDelegate ( proxyGroupUrl , principalUrl )
160+ await getClient ( ) . removeDelegate ( currentUser . url , principalUrl , permission )
173161 delegates . value = delegates . value . filter ( ( d ) => d . url !== principalUrl )
174162 }
175163
0 commit comments