Don't offer to delete a list that is the account's calendar home (#180)
This commit is contained in:
1 parent
74d6be61f2
commit
1c59c5e409
13 files changed
+65
-11
No files matched your search
+3
-1
@@ -61,7 +61,9 @@ All notable changes to this project are documented here. The format follows
|
||||
|
||||
### 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).
|
||||
all-inkl.com, find their task list instead of reporting none. That list is
|
||||
the account's calendar itself, so Agendula doesn't offer to delete it or to
|
||||
create new lists there (#180).
|
||||
|
||||
## [1.3.2] - 2026-11-13
|
||||
|
||||
|
||||
@@ -205,6 +205,7 @@ class RemoteListRepository @Inject constructor(
|
||||
val url = list.href?.toHttpUrlOrNull() ?: return@withContext Outcome.NoAccount
|
||||
val account = list.accountId?.let { database.accounts().account(it) }
|
||||
?: return@withContext Outcome.NoAccount
|
||||
if (isHomeSet(list.href, account.homeSetUrl)) return@withContext Outcome.AccountHome
|
||||
val admin = adminFor(account) ?: return@withContext Outcome.NoAccount
|
||||
|
||||
when (val outcome = admin.delete(url)) {
|
||||
|
||||
@@ -25,6 +25,9 @@ interface RemoteLists {
|
||||
/** Ours is a read-only share; the write belongs to whoever owns it. */
|
||||
data object ReadOnly : Outcome
|
||||
|
||||
/** The list is the account's home set itself, which the app never deletes (#180). */
|
||||
data object AccountHome : Outcome
|
||||
|
||||
/** The account is gone, stopped, or has no credential we can decrypt. */
|
||||
data object NoAccount : Outcome
|
||||
|
||||
@@ -50,3 +53,7 @@ interface RemoteLists {
|
||||
|
||||
suspend fun delete(listId: Long): Outcome
|
||||
}
|
||||
|
||||
/** Whether a list at [href] is the account's home set at [homeSetUrl] itself. */
|
||||
fun isHomeSet(href: String?, homeSetUrl: String?): Boolean =
|
||||
href != null && homeSetUrl != null && href.trimEnd('/') == homeSetUrl.trimEnd('/')
|
||||
@@ -12,6 +12,7 @@ data class TaskListRow(
|
||||
@Embedded val list: TaskListEntity,
|
||||
@ColumnInfo(name = "account_display_name") val accountDisplayName: String?,
|
||||
@ColumnInfo(name = "account_label") val accountLabel: String? = null,
|
||||
@ColumnInfo(name = "account_home_set_url") val accountHomeSetUrl: String? = null,
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.jeanlucmakiola.agendula.data.tasks.room
|
||||
|
||||
import de.jeanlucmakiola.agendula.data.sync.isHomeSet
|
||||
import de.jeanlucmakiola.agendula.domain.LocalAccount
|
||||
import de.jeanlucmakiola.agendula.domain.Task
|
||||
import de.jeanlucmakiola.agendula.domain.TaskList
|
||||
@@ -29,6 +30,7 @@ object RoomTaskMapper {
|
||||
owner = row.list.owner,
|
||||
accountId = row.list.accountId,
|
||||
isReadOnly = row.list.isReadOnly,
|
||||
isAccountHome = isHomeSet(row.list.href, row.accountHomeSetUrl),
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,8 @@ interface TaskListDao {
|
||||
|
||||
@Query(
|
||||
"""
|
||||
SELECT l.*, a.display_name AS account_display_name, a.label AS account_label
|
||||
SELECT l.*, a.display_name AS account_display_name, a.label AS account_label,
|
||||
a.home_set_url AS account_home_set_url
|
||||
FROM task_lists l LEFT JOIN accounts a ON a.id = l.account_id
|
||||
ORDER BY a.display_name COLLATE NOCASE, l.sort_order, l.name COLLATE NOCASE, l.name
|
||||
"""
|
||||
@@ -25,7 +26,8 @@ interface TaskListDao {
|
||||
|
||||
@Query(
|
||||
"""
|
||||
SELECT l.*, a.display_name AS account_display_name, a.label AS account_label
|
||||
SELECT l.*, a.display_name AS account_display_name, a.label AS account_label,
|
||||
a.home_set_url AS account_home_set_url
|
||||
FROM task_lists l LEFT JOIN accounts a ON a.id = l.account_id
|
||||
WHERE l.id = :listId
|
||||
"""
|
||||
|
||||
@@ -27,6 +27,11 @@ data class TaskList(
|
||||
* to do, and attempting either answers 403.
|
||||
*/
|
||||
val isReadOnly: Boolean = false,
|
||||
/**
|
||||
* The account's calendar home set itself (#180). Deleting it would remove the
|
||||
* account's only calendar, events included, so the app never does.
|
||||
*/
|
||||
val isAccountHome: Boolean = false,
|
||||
) {
|
||||
/** A device-only list Agendula (or another app) created locally, not synced. */
|
||||
val isLocal: Boolean
|
||||
|
||||
@@ -83,7 +83,8 @@ data class ListDestination(val accountId: Long?, val label: String)
|
||||
* ⚠️ [onDelete] no longer means "device-only list". An account's collection can
|
||||
* be deleted now, on the server, which is what the caller wires it to; it stays
|
||||
* null for a list the app must not remove — a read-only share, whose removal
|
||||
* belongs to whoever owns it.
|
||||
* belongs to whoever owns it. The account's home set itself is never deletable,
|
||||
* whatever the caller passes.
|
||||
*/
|
||||
@Composable
|
||||
fun ListEditorSheet(
|
||||
@@ -111,6 +112,7 @@ fun ListEditorSheet(
|
||||
?: destinations.firstOrNull()
|
||||
|
||||
val readOnly = initial?.isReadOnly == true
|
||||
val deletable = onDelete != null && initial?.isAccountHome != true
|
||||
val valid = name.isNotBlank() && !readOnly
|
||||
val commit = {
|
||||
if (valid) {
|
||||
@@ -157,7 +159,7 @@ fun ListEditorSheet(
|
||||
|
||||
if (readOnly) {
|
||||
Spacer(Modifier.height(20.dp))
|
||||
ReadOnlyNote()
|
||||
ListNote(stringResource(R.string.list_read_only))
|
||||
}
|
||||
|
||||
Spacer(Modifier.height(20.dp))
|
||||
@@ -181,9 +183,12 @@ fun ListEditorSheet(
|
||||
)
|
||||
}
|
||||
|
||||
if (onDelete != null) {
|
||||
if (deletable) {
|
||||
Spacer(Modifier.height(24.dp))
|
||||
DeleteRow(onClick = { confirmDelete = true })
|
||||
} else if (initial?.isAccountHome == true) {
|
||||
Spacer(Modifier.height(24.dp))
|
||||
ListNote(stringResource(R.string.list_delete_account_home))
|
||||
}
|
||||
Spacer(Modifier.height(24.dp))
|
||||
}
|
||||
@@ -202,7 +207,7 @@ fun ListEditorSheet(
|
||||
)
|
||||
}
|
||||
|
||||
if (confirmDelete && onDelete != null) {
|
||||
if (confirmDelete && deletable && onDelete != null) {
|
||||
DeleteListDialog(
|
||||
listName = initial?.name.orEmpty(),
|
||||
// A synced list is deleted on the server too, and that reaches every
|
||||
@@ -223,9 +228,9 @@ fun ListEditorSheet(
|
||||
private fun destinationIcon(destination: ListDestination) =
|
||||
if (destination.accountId == null) Icons.Rounded.PhoneAndroid else Icons.Rounded.CloudSync
|
||||
|
||||
/** A share we may read and not write; the edit has nowhere to land. */
|
||||
/** Why part of the sheet is missing: a read-only share, or the account's home (#180). */
|
||||
@Composable
|
||||
private fun ReadOnlyNote() {
|
||||
private fun ListNote(text: String) {
|
||||
GroupedSurface(
|
||||
position = Position.Alone,
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
@@ -238,7 +243,7 @@ private fun ReadOnlyNote() {
|
||||
) {
|
||||
Icon(Icons.Rounded.Lock, contentDescription = null)
|
||||
Text(
|
||||
text = stringResource(R.string.list_read_only),
|
||||
text = text,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
|
||||
@@ -260,6 +260,7 @@ internal fun listWriteFailureMessage(failure: ListWriteFailure): Int = when (fai
|
||||
ListWriteFailure.OFFLINE -> R.string.list_save_failed_offline
|
||||
ListWriteFailure.READ_ONLY -> R.string.list_save_failed_read_only
|
||||
ListWriteFailure.UNSUPPORTED -> R.string.list_save_failed_unsupported
|
||||
ListWriteFailure.ACCOUNT_HOME -> R.string.list_delete_account_home
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -55,6 +55,9 @@ enum class ListWriteFailure {
|
||||
|
||||
/** This account cannot make collections at all — iCloud, Posteo, Google. */
|
||||
UNSUPPORTED,
|
||||
|
||||
/** The list is the account's calendar home itself (#180). */
|
||||
ACCOUNT_HOME,
|
||||
}
|
||||
|
||||
/** Maps a remote outcome onto the wording the screens already know how to show. */
|
||||
@@ -65,6 +68,7 @@ internal fun RemoteLists.Outcome.asFailure(local: ListWriteFailure): ListWriteFa
|
||||
RemoteLists.Outcome.Unreachable -> ListWriteFailure.OFFLINE
|
||||
RemoteLists.Outcome.Unsupported -> ListWriteFailure.UNSUPPORTED
|
||||
RemoteLists.Outcome.ReadOnly -> ListWriteFailure.READ_ONLY
|
||||
RemoteLists.Outcome.AccountHome -> ListWriteFailure.ACCOUNT_HOME
|
||||
// The account is gone, stopped or undecryptable, or the server said
|
||||
// something this call cannot place. Nothing specific to say beyond
|
||||
// "that did not save", which is what [local] is — and specifically not
|
||||
|
||||
@@ -429,7 +429,7 @@ fun TaskListScreen(
|
||||
// owns it — and which the server would refuse anyway. Present for
|
||||
// the account's own collections, where it now deletes on the server
|
||||
// as well as here.
|
||||
onDelete = if (list.isReadOnly) {
|
||||
onDelete = if (list.isReadOnly || list.isAccountHome) {
|
||||
null
|
||||
} else {
|
||||
{ viewModel.deleteList(list.id, list.accountId) }
|
||||
|
||||
@@ -325,6 +325,7 @@
|
||||
<string name="list_delete">Delete list</string>
|
||||
<string name="list_save_failed">Could not save the list.</string>
|
||||
<string name="list_delete_failed">Could not delete the list.</string>
|
||||
<string name="list_delete_account_home">This list is the account’s calendar itself, so it can’t be deleted here. Deleting it would also delete the calendar’s events.</string>
|
||||
<string name="list_delete_confirm_title">Delete list?</string>
|
||||
<string name="list_where">Where</string>
|
||||
<string name="list_where_device">On this device only</string>
|
||||
|
||||
@@ -39,4 +39,27 @@ class RoomTaskMapperTest {
|
||||
assertThat(RoomTaskMapper.taskList(list).accountName).isEqualTo("Work server")
|
||||
assertThat(RoomTaskMapper.taskList(list.copy(accountLabel = null)).accountName).isEqualTo("me@host")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a list at the account's home set is the account's home (#180)`() {
|
||||
val list = TaskListRow(
|
||||
list = TaskListEntity(
|
||||
id = 2,
|
||||
name = "Kalender",
|
||||
color = 0,
|
||||
accountId = 1,
|
||||
href = "https://webmail.example.com/calendars/user/1",
|
||||
),
|
||||
accountDisplayName = "user",
|
||||
accountHomeSetUrl = "https://webmail.example.com/calendars/user/1/",
|
||||
)
|
||||
|
||||
assertThat(RoomTaskMapper.taskList(list).isAccountHome).isTrue()
|
||||
assertThat(
|
||||
RoomTaskMapper.taskList(
|
||||
list.copy(list = list.list.copy(href = "https://webmail.example.com/calendars/user/1/tasks/")),
|
||||
).isAccountHome,
|
||||
).isFalse()
|
||||
assertThat(RoomTaskMapper.taskList(list.copy(accountHomeSetUrl = null)).isAccountHome).isFalse()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user