Visitar URL original
fix: refresh share badges when folder etag is unchanged by mvanhorn · Pull Request #5013 · owncloud/android · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/5013
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Refresh share badges when the folder etag is unchanged

Share badges have been refreshed on pull-to-refresh when a file or folder is shared or unshared
but the server keeps the same etag for it.

https://github.com/owncloud/android/issues/4938
https://github.com/owncloud/android/pull/5013
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ class OCFileRepository(
})
} else if (localChildToSync.etag != remoteChild.etag ||
localChildToSync.localModificationTimestamp > remoteChild.lastSyncDateForData!! ||
isActionSetFolderAvailableOfflineOrSynchronize
isActionSetFolderAvailableOfflineOrSynchronize ||
shareMetadataChanged(localChildToSync, remoteChild)
) {
// File exists in the database, we need to check several stuff.
folderContentUpdated.add(
Expand Down Expand Up @@ -609,6 +610,11 @@ class OCFileRepository(
deleteOrResetFileFromDatabase(ocFile, onlyFromLocalStorage)
}

private fun shareMetadataChanged(localChild: OCFile, remoteChild: OCFile): Boolean =
localChild.sharedByLink != remoteChild.sharedByLink ||
(localChild.sharedWithSharee == true) != (remoteChild.sharedWithSharee == true) ||
localChild.permissions != remoteChild.permissions

private fun deleteOrResetFileFromDatabase(ocFile: OCFile, onlyFromLocalStorage: Boolean) {
if (onlyFromLocalStorage) {
localFileDataSource.saveFile(ocFile.copy(storagePath = null, etagInConflict = null, lastUsage = null, etag = null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,201 @@ class OCFileRepositoryTest {
}
}

@Suppress("MaxLineLength")
@Test
fun `refreshFolder returns a list with the OCFile that changed when the etag matches but sharedByLink changed`() {
val ocParentFolderWithoutSpaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.copy(spaceId = null)
val remoteFolderChild = OC_FOLDER_WITH_SPACE_ID.copy(spaceId = null, sharedByLink = true)
val expectedFolderChild = OC_FOLDER_WITH_SPACE_ID.copy(sharedByLink = true)
every {
remoteFileDataSource.refreshFolder(
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl
)
} returns listOf(ocParentFolderWithoutSpaceId, remoteFolderChild)
every {
localFileDataSource.getFileByRemotePath(
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
owner = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
spaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId
)
} returns OC_PARENT_FOLDER_WITH_SPACE_ID
every {
localFileDataSource.getFolderContent(
folderId = OC_PARENT_FOLDER_WITH_SPACE_ID.id!!
)
} returns listOf(OC_FOLDER_WITH_SPACE_ID)
every {
localFileDataSource.saveFilesInFolderAndReturnTheFilesThatChanged(
listOfFiles = listOf(expectedFolderChild),
folder = OC_PARENT_FOLDER_WITH_SPACE_ID,
)
} returns listOf(expectedFolderChild)

val listOfFiles = ocFileRepository.refreshFolder(
OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId,
false
)
assertEquals(listOf(expectedFolderChild), listOfFiles)

verify(exactly = 1) {
localSpacesDataSource.getWebDavUrlForSpace(
spaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId,
accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner
)
remoteFileDataSource.refreshFolder(
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl
)
localFileDataSource.getFileByRemotePath(
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
owner = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
spaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId
)
localFileDataSource.getFolderContent(
folderId = OC_PARENT_FOLDER_WITH_SPACE_ID.id!!
)
localFileDataSource.saveFilesInFolderAndReturnTheFilesThatChanged(
listOfFiles = listOf(expectedFolderChild),
folder = OC_PARENT_FOLDER_WITH_SPACE_ID,
)
}
}

@Suppress("MaxLineLength")
@Test
fun `refreshFolder returns a list with the OCFile that changed when the etag matches but sharedWithSharee changed`() {
val ocParentFolderWithoutSpaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.copy(spaceId = null)
val remoteFolderChild = OC_FOLDER_WITH_SPACE_ID.copy(spaceId = null, sharedWithSharee = true)
val expectedFolderChild = OC_FOLDER_WITH_SPACE_ID.copy(sharedWithSharee = true)
every {
remoteFileDataSource.refreshFolder(
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl
)
} returns listOf(ocParentFolderWithoutSpaceId, remoteFolderChild)
every {
localFileDataSource.getFileByRemotePath(
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
owner = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
spaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId
)
} returns OC_PARENT_FOLDER_WITH_SPACE_ID
every {
localFileDataSource.getFolderContent(
folderId = OC_PARENT_FOLDER_WITH_SPACE_ID.id!!
)
} returns listOf(OC_FOLDER_WITH_SPACE_ID)
every {
localFileDataSource.saveFilesInFolderAndReturnTheFilesThatChanged(
listOfFiles = listOf(expectedFolderChild),
folder = OC_PARENT_FOLDER_WITH_SPACE_ID,
)
} returns listOf(expectedFolderChild)

val listOfFiles = ocFileRepository.refreshFolder(
OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId,
false
)
assertEquals(listOf(expectedFolderChild), listOfFiles)

verify(exactly = 1) {
localSpacesDataSource.getWebDavUrlForSpace(
spaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId,
accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner
)
remoteFileDataSource.refreshFolder(
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl
)
localFileDataSource.getFileByRemotePath(
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
owner = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
spaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId
)
localFileDataSource.getFolderContent(
folderId = OC_PARENT_FOLDER_WITH_SPACE_ID.id!!
)
localFileDataSource.saveFilesInFolderAndReturnTheFilesThatChanged(
listOfFiles = listOf(expectedFolderChild),
folder = OC_PARENT_FOLDER_WITH_SPACE_ID,
)
}
}

@Suppress("MaxLineLength")
@Test
fun `refreshFolder returns a list with the OCFile that changed when the etag matches but permissions changed`() {
val ocParentFolderWithoutSpaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.copy(spaceId = null)
val remoteFolderChild = OC_FOLDER_WITH_SPACE_ID.copy(spaceId = null, permissions = "RDNVCKW")
val expectedFolderChild = OC_FOLDER_WITH_SPACE_ID.copy(permissions = "RDNVCKW")
every {
remoteFileDataSource.refreshFolder(
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl
)
} returns listOf(ocParentFolderWithoutSpaceId, remoteFolderChild)
every {
localFileDataSource.getFileByRemotePath(
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
owner = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
spaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId
)
} returns OC_PARENT_FOLDER_WITH_SPACE_ID
every {
localFileDataSource.getFolderContent(
folderId = OC_PARENT_FOLDER_WITH_SPACE_ID.id!!
)
} returns listOf(OC_FOLDER_WITH_SPACE_ID)
every {
localFileDataSource.saveFilesInFolderAndReturnTheFilesThatChanged(
listOfFiles = listOf(expectedFolderChild),
folder = OC_PARENT_FOLDER_WITH_SPACE_ID,
)
} returns listOf(expectedFolderChild)

val listOfFiles = ocFileRepository.refreshFolder(
OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId,
false
)
assertEquals(listOf(expectedFolderChild), listOfFiles)

verify(exactly = 1) {
localSpacesDataSource.getWebDavUrlForSpace(
spaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId,
accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner
)
remoteFileDataSource.refreshFolder(
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl
)
localFileDataSource.getFileByRemotePath(
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
owner = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
spaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId
)
localFileDataSource.getFolderContent(
folderId = OC_PARENT_FOLDER_WITH_SPACE_ID.id!!
)
localFileDataSource.saveFilesInFolderAndReturnTheFilesThatChanged(
listOfFiles = listOf(expectedFolderChild),
folder = OC_PARENT_FOLDER_WITH_SPACE_ID,
)
}
}

@Suppress("MaxLineLength")
@Test
fun `refreshFolder returns an empty list of OCFiles when folder and its content already exists in database but there are additional files in conflict in local to be removed`() {
Expand Down