Skip to content

Commit c0822ce

Browse files
GVodyanovSebastianKrupinski
authored andcommitted
feat: add readonly delegation
Signed-off-by: Grigory Vodyanov <scratchx@gmx.com>
1 parent 60da359 commit c0822ce

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,38 @@ export default class DavClient {
638638
.filter(Boolean)
639639
}
640640

641+
/**
642+
* Returns the principal URLs and permission level of users who have granted
643+
* the given principal proxy access (both read and write).
644+
*
645+
* Inspects the group-membership property for groups ending in
646+
* /calendar-proxy-write or /calendar-proxy-read and returns objects with
647+
* the owner's principal URL and the permission granted.
648+
*
649+
* @param {string} principalUrl Absolute URL of the principal
650+
* @return {Promise<Array<{principalUrl: string, permission: 'write'|'read'}>>}
651+
*/
652+
async getDelegatorsWithPermission(principalUrl) {
653+
const groups = await this.getGroupMembership(principalUrl)
654+
const result = []
655+
656+
for (const groupUrl of groups) {
657+
if (groupUrl.includes('calendar-proxy-write')) {
658+
const ownerUrl = groupUrl.replace(/\/calendar-proxy-write\/?$/, '')
659+
if (ownerUrl) {
660+
result.push({ principalUrl: ownerUrl, permission: 'write' })
661+
}
662+
} else if (groupUrl.includes('calendar-proxy-read')) {
663+
const ownerUrl = groupUrl.replace(/\/calendar-proxy-read\/?$/, '')
664+
if (ownerUrl) {
665+
result.push({ principalUrl: ownerUrl, permission: 'read' })
666+
}
667+
}
668+
}
669+
670+
return result
671+
}
672+
641673
/**
642674
* discovers all calendar-homes in this account, all principal collections
643675
* and advertised features

0 commit comments

Comments
 (0)