Only offer a calendar home set as a list when it holds no collections, and don't create lists inside it (#180)
This commit is contained in:
1 parent
220c18170f
commit
4ed54f6c7e
3 files changed
+37
-8
No files matched your search
@@ -107,6 +107,7 @@ class RemoteListRepository @Inject constructor(
|
||||
val homeSet = account.homeSetUrl?.toHttpUrlOrNull()
|
||||
?: return@withContext Outcome.NoAccount
|
||||
val admin = adminFor(account) ?: return@withContext Outcome.NoAccount
|
||||
if (homeSetIsAList(account)) return@withContext Outcome.Unsupported
|
||||
val capabilities = support.refresh(accountId) { admin.support(homeSet) }
|
||||
if (!capabilities.canCreate) return@withContext Outcome.Unsupported
|
||||
|
||||
@@ -233,10 +234,17 @@ class RemoteListRepository @Inject constructor(
|
||||
|
||||
private suspend fun supportFor(account: AccountEntity): CollectionSupport {
|
||||
val homeSet = account.homeSetUrl?.toHttpUrlOrNull() ?: return CollectionSupport.NONE
|
||||
if (homeSetIsAList(account)) return CollectionSupport.NONE
|
||||
val admin = adminFor(account) ?: return CollectionSupport.NONE
|
||||
return support.refresh(account.id) { admin.support(homeSet) }
|
||||
}
|
||||
|
||||
/** A home set that is itself a calendar (#180) cannot hold another one. */
|
||||
private fun homeSetIsAList(account: AccountEntity): Boolean {
|
||||
val homeSet = account.homeSetUrl?.trimEnd('/') ?: return false
|
||||
return database.taskLists().syncedForAccount(account.id).any { it.href?.trimEnd('/') == homeSet }
|
||||
}
|
||||
|
||||
/**
|
||||
* Null when the account has no credential we can use — a stopped account, or
|
||||
* a restore.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package de.jeanlucmakiola.caldav
|
||||
|
||||
import at.bitfire.dav4jvm.DavResource
|
||||
import at.bitfire.dav4jvm.UrlUtils
|
||||
import at.bitfire.dav4jvm.Response
|
||||
import at.bitfire.dav4jvm.property.ResourceType
|
||||
import at.bitfire.dav4jvm.property.CalendarHomeSet
|
||||
import at.bitfire.dav4jvm.exception.HttpException
|
||||
import at.bitfire.dav4jvm.property.CurrentUserPrincipal
|
||||
@@ -318,16 +319,22 @@ class CalDavDiscovery(
|
||||
var anySucceeded = false
|
||||
|
||||
for (homeSet in homeSets.distinct()) {
|
||||
var self: TaskCollection? = null
|
||||
var hasMemberCollections = false
|
||||
val result = runCatching {
|
||||
// The home set itself is classified too: all-inkl.com reports its
|
||||
// one calendar as the home set (#180). A plain home collection is
|
||||
// not a calendar, so the classifier drops it as before. Keyed
|
||||
// slash-insensitively, since the self href may lack the slash.
|
||||
DavResource(httpClient, homeSet).propfind(1, *collectionProperties) { response, _ ->
|
||||
CollectionClassifier.classify(response)?.let {
|
||||
collections[UrlUtils.withTrailingSlash(it.url)] = it
|
||||
DavResource(httpClient, homeSet).propfind(1, *collectionProperties) { response, relation ->
|
||||
if (relation == Response.HrefRelation.SELF) {
|
||||
if (self == null) self = CollectionClassifier.classify(response)
|
||||
return@propfind
|
||||
}
|
||||
if (response[ResourceType::class.java]?.types?.contains(ResourceType.COLLECTION) == true) {
|
||||
hasMemberCollections = true
|
||||
}
|
||||
CollectionClassifier.classify(response)?.let { collections[it.url] = it }
|
||||
}
|
||||
// A home set that is itself a calendar with no collections in it
|
||||
// is the account's one list, as on all-inkl.com (#180).
|
||||
self?.takeIf { !hasMemberCollections }?.let { collections.putIfAbsent(it.url, it) }
|
||||
}
|
||||
result.fold(
|
||||
// A failed home set must not fail the account — the same rule the
|
||||
|
||||
@@ -288,6 +288,20 @@ class CalDavDiscoveryTest {
|
||||
assertThat(found.collections.map { it.url.encodedPath.trimEnd('/') }).containsExactly("/calendars/user/1")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a calendar home set with calendars in it offers only those`() {
|
||||
server.enqueue(homeSetResponse("/calendars/user/1/"))
|
||||
server.enqueue(
|
||||
calendarAsHomeSet(
|
||||
"",
|
||||
collection("/calendars/user/1/tasks/", "<collection/><CAL:calendar/>"),
|
||||
),
|
||||
)
|
||||
|
||||
val found = discovery.fromPrincipal(server.url("/calendars/principals/user/")) as CalDavDiscovery.Outcome.Found
|
||||
assertThat(found.collections.map { it.url.encodedPath }).containsExactly("/calendars/user/1/tasks/")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a home set that is a VEVENT-only calendar is not a list`() {
|
||||
server.enqueue(homeSetResponse("/calendars/user/1/"))
|
||||
|
||||
Reference in new issue
Block a user