Skip to content

Commit

Permalink
Always pass forceReadOnly flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sunkup committed Nov 7, 2024
1 parent a24a36a commit c202d92
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,10 @@ class LocalAddressBookTest {
@Test
fun test_shouldBeReadOnly() {
val collectionReadOnly = mockk<Collection> { every { readOnly() } returns true }
assertTrue(LocalAddressBook.shouldBeReadOnly(collectionReadOnly, null))
assertTrue(LocalAddressBook.shouldBeReadOnly(collectionReadOnly, false))
assertTrue(LocalAddressBook.shouldBeReadOnly(collectionReadOnly, true))

val collectionNotReadOnly = mockk<Collection> { every { readOnly() } returns false }
assertFalse(LocalAddressBook.shouldBeReadOnly(collectionNotReadOnly, null))
assertFalse(LocalAddressBook.shouldBeReadOnly(collectionNotReadOnly, false))
assertTrue(LocalAddressBook.shouldBeReadOnly(collectionNotReadOnly, true))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,8 @@ open class LocalAddressBook @AssistedInject constructor(
* @param info collection where to take the settings from
* @param forceReadOnly `true`: set the address book to "force read-only";
* `false`: determine read-only flag from [info];
* `null`: don't change the existing value
*/
fun update(info: Collection, forceReadOnly: Boolean? = null) {
fun update(info: Collection, forceReadOnly: Boolean) {
logger.log(Level.INFO, "Updating local address book $addressBookAccount with collection $info")
val accountManager = AccountManager.get(context)

Expand Down Expand Up @@ -443,8 +442,8 @@ open class LocalAddressBook @AssistedInject constructor(
* @param info Determine read-only flag from collection data
*/
@VisibleForTesting
internal fun shouldBeReadOnly(info: Collection, forceReadOnly: Boolean? = null,): Boolean =
forceReadOnly == true || info.readOnly()
internal fun shouldBeReadOnly(info: Collection, forceReadOnly: Boolean): Boolean =
info.readOnly() || forceReadOnly

/**
* Finds a [LocalAddressBook] based on its corresponding collection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class AccountSettingsMigrations @AssistedInject constructor(
collectionRepository.getByServiceAndUrl(service.id, url)?.let { collection ->
// Set collection ID and rename the account
val localAddressBook = localAddressBookFactory.create(oldAddressBookAccount, provider)
localAddressBook.update(collection)
localAddressBook.update(collection, false)
}
}
}
Expand Down

0 comments on commit c202d92

Please sign in to comment.