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
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ object FileLockingHelper {
*/
@JvmStatic
fun canUserUnlockFile(userId: String, file: OCFile): Boolean {
if (!file.isLocked || file.lockOwnerId == null || file.lockType != FileLockType.MANUAL) {
if (!file.isLocked) {
return false
}
return file.lockOwnerId == userId
if (file.lockType == FileLockType.MANUAL && file.lockOwnerId == userId) {
return true
}
// App locks (Text, OnlyOffice, ...) carry no lock owner id and are reported as
// COLLABORATIVE. The file owner may still unlock them: LockService::canUnlock
// accepts any TYPE_USER request from the file owner.
return file.lockType != FileLockType.TOKEN && file.ownerId == userId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ class FileActionsBottomSheet :
when (state) {
is FileActionsViewModel.UiState.LoadedForSingleFile -> {
loadFileThumbnail(state.titleFile)
// displayActions aborts when the action list is not empty, so it has to
// run before the lock info row is appended.
displayActions(state.titleFile, state.actions)
if (state.lockInfo != null) {
displayLockInfo(state.lockInfo)
}
displayActions(state.titleFile, state.actions)
displayTitle(state.titleFile)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,38 @@ class FileLockingHelperTest {
Assert.assertFalse(FileLockingHelper.canUserUnlockFile(USER_NAME, file))
}

@Test
fun fileOwnerCanUnlockLockOfAnotherClient() {
val file = OCFile("/foo.md").apply {
isLocked = true
lockOwnerId = "text"
lockType = FileLockType.MANUAL
ownerId = USER_NAME
}
Assert.assertTrue(FileLockingHelper.canUserUnlockFile(USER_NAME, file))
}

@Test
fun fileOwnerCanUnlockAppLock() {
val file = OCFile("/foo.docx").apply {
isLocked = true
lockOwnerId = null
lockType = FileLockType.COLLABORATIVE
ownerId = USER_NAME
}
Assert.assertTrue(FileLockingHelper.canUserUnlockFile(USER_NAME, file))
}

@Test
fun fileOwnerCannotUnlockTokenLock() {
val file = OCFile("/foo.docx").apply {
isLocked = true
lockType = FileLockType.TOKEN
ownerId = USER_NAME
}
Assert.assertFalse(FileLockingHelper.canUserUnlockFile(USER_NAME, file))
}

@Test
fun typeNotManual_cannotUnlock() {
val file = OCFile("/foo.md").apply {
Expand Down