Ask the server whether a home set is a calendar before offering list creation, and fix the changelog section (#180)
This commit is contained in:
1 parent
4ed54f6c7e
commit
eaa8f3ec74
6 files changed
+70
-17
No files matched your search
+4
-2
@@ -59,6 +59,10 @@ All notable changes to this project are documented here. The format follows
|
||||
all-day reminder time. With a tasks app as the store, both ends gain or
|
||||
drop their time together (#101).
|
||||
|
||||
### Fixed
|
||||
- CalDAV accounts on servers that give each calendar its own account, such as
|
||||
all-inkl.com, find their task list instead of reporting none (#180).
|
||||
|
||||
## [1.3.2] - 2026-11-13
|
||||
|
||||
### Added
|
||||
@@ -96,8 +100,6 @@ All notable changes to this project are documented here. The format follows
|
||||
the next occurrence showed them already ticked. Unticking gives them back
|
||||
their state and dates, and repeating sub-tasks keep their own schedule
|
||||
(#160).
|
||||
- CalDAV accounts on servers that give each calendar its own account, such as
|
||||
all-inkl.com, find their task list instead of reporting none (#180).
|
||||
|
||||
## [1.3.1] - 2026-11-09
|
||||
|
||||
|
||||
@@ -107,7 +107,6 @@ 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
|
||||
|
||||
@@ -234,17 +233,10 @@ 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.
|
||||
|
||||
@@ -320,21 +320,21 @@ class CalDavDiscovery(
|
||||
|
||||
for (homeSet in homeSets.distinct()) {
|
||||
var self: TaskCollection? = null
|
||||
var hasMemberCollections = false
|
||||
var hasMemberCalendars = false
|
||||
val result = runCatching {
|
||||
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
|
||||
if (response[ResourceType::class.java]?.types?.contains(ResourceType.CALENDAR) == true) {
|
||||
hasMemberCalendars = 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) }
|
||||
// A home set that is itself a calendar with none inside it is the
|
||||
// account's one list, as on all-inkl.com (#180).
|
||||
self?.takeIf { !hasMemberCalendars }?.let { collections.putIfAbsent(it.url, it) }
|
||||
}
|
||||
result.fold(
|
||||
// A failed home set must not fail the account — the same rule the
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package de.jeanlucmakiola.caldav
|
||||
|
||||
import at.bitfire.dav4jvm.DavResource
|
||||
import at.bitfire.dav4jvm.Property
|
||||
import at.bitfire.dav4jvm.XmlUtils
|
||||
import at.bitfire.dav4jvm.XmlUtils.insertTag
|
||||
import at.bitfire.dav4jvm.property.ResourceType
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.OkHttpClient
|
||||
@@ -121,7 +123,7 @@ class DavCollectionAdmin(
|
||||
mkCalendar = "MKCALENDAR" in allow,
|
||||
extendedMkCol = "EXTENDED-MKCOL" in dav,
|
||||
)
|
||||
}
|
||||
}.takeIf { !it.canCreate || !isCalendar(homeSet) } ?: CollectionSupport.NONE
|
||||
} catch (_: IOException) {
|
||||
// Unknown reads as "no", which costs the user an affordance they can
|
||||
// reach again on the next attempt — the other way round costs them a
|
||||
@@ -129,6 +131,19 @@ class DavCollectionAdmin(
|
||||
CollectionSupport.NONE
|
||||
}
|
||||
|
||||
/** A home set that is itself a calendar, as on all-inkl.com (#180), cannot hold another. */
|
||||
private fun isCalendar(homeSet: HttpUrl): Boolean {
|
||||
var calendar = false
|
||||
runCatching {
|
||||
DavResource(httpClient, homeSet).propfind(0, ResourceType.NAME) { response, _ ->
|
||||
if (response[ResourceType::class.java]?.types?.contains(ResourceType.CALENDAR) == true) {
|
||||
calendar = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return calendar
|
||||
}
|
||||
|
||||
/**
|
||||
* ⚠️ MKCALENDAR first where both exist. It is the method written for this
|
||||
* job, every server that has it treats it as authoritative, and extended
|
||||
|
||||
@@ -302,6 +302,21 @@ class CalDavDiscoveryTest {
|
||||
assertThat(found.collections.map { it.url.encodedPath }).containsExactly("/calendars/user/1/tasks/")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a calendar home set holding only non-calendar collections is still offered`() {
|
||||
server.enqueue(homeSetResponse("/calendars/user/1/"))
|
||||
server.enqueue(
|
||||
calendarAsHomeSet(
|
||||
eventsAndTasks,
|
||||
collection("/calendars/user/1/attachments/", "<collection/>"),
|
||||
taskResource,
|
||||
),
|
||||
)
|
||||
|
||||
val found = discovery.fromPrincipal(server.url("/calendars/principals/user/")) as CalDavDiscovery.Outcome.Found
|
||||
assertThat(found.collections.map { it.url.encodedPath }).containsExactly("/calendars/user/1/")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a home set that is a VEVENT-only calendar is not a list`() {
|
||||
server.enqueue(homeSetResponse("/calendars/user/1/"))
|
||||
|
||||
@@ -39,6 +39,7 @@ class CollectionAdminTest {
|
||||
.setHeader("Allow", "OPTIONS, GET, PROPFIND, MKCOL")
|
||||
.setHeader("DAV", "1, 2, 3, calendar-access, extended-mkcol"),
|
||||
)
|
||||
server.enqueue(resourceType("<collection/>"))
|
||||
|
||||
val support = admin.support(homeSet())
|
||||
|
||||
@@ -47,6 +48,34 @@ class CollectionAdminTest {
|
||||
assertThat(support.canCreate).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a home set that is itself a calendar offers nothing`() {
|
||||
// all-inkl.com (#180): the home set is the account's one calendar, and
|
||||
// a calendar cannot hold another.
|
||||
server.enqueue(
|
||||
MockResponse()
|
||||
.setResponseCode(200)
|
||||
.setHeader("Allow", "OPTIONS, GET, PROPFIND, MKCALENDAR")
|
||||
.setHeader("DAV", "1, 2, 3, calendar-access, extended-mkcol"),
|
||||
)
|
||||
server.enqueue(resourceType("<collection/><C:calendar/>"))
|
||||
|
||||
assertThat(admin.support(homeSet())).isEqualTo(CollectionSupport.NONE)
|
||||
}
|
||||
|
||||
private fun resourceType(types: String) = MockResponse()
|
||||
.setResponseCode(207)
|
||||
.setHeader("Content-Type", "application/xml; charset=utf-8")
|
||||
.setBody(
|
||||
"""
|
||||
<multistatus xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
|
||||
<response><href>/dav/calendars/me/</href>
|
||||
<propstat><prop><resourcetype>$types</resourcetype></prop>
|
||||
<status>HTTP/1.1 200 OK</status></propstat></response>
|
||||
</multistatus>
|
||||
""".trimIndent(),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `a server offering neither offers nothing`() {
|
||||
server.enqueue(
|
||||
|
||||
Reference in new issue
Block a user