clarify when desktop client should offer to unlock a file
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Wed, 25 Sep 2024 14:38:17 +0000 (16:38 +0200)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Thu, 26 Sep 2024 07:25:32 +0000 (09:25 +0200)
a file can be unlocked when:

 * the lock is an user lock from the current user
 * the lock is a token lock from the current desktop files client

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/gui/socketapi/socketapi.cpp
src/libsync/account.cpp

index 81d98040596fb38a7332acc9354b40e780705267..bd68063fa297830c2d6804595846c3f190cc5892 100644 (file)
@@ -1110,8 +1110,9 @@ void SocketApi::setFileLock(const QString &localFile, const SyncFileItem::LockSt
     }
 
     const auto record = fileData.journalRecord();
-    if (static_cast<SyncFileItem::LockOwnerType>(record._lockstate._lockOwnerType) != SyncFileItem::LockOwnerType::UserLock) {
-        qCDebug(lcSocketApi) << "Only user lock state or non-locked files can be affected manually!";
+
+    if (lockState == SyncFileItem::LockStatus::UnlockedItem &&
+        !shareFolder->accountState()->account()->fileCanBeUnlocked(shareFolder->journalDb(), fileData.folderRelativePath)) {
         return;
     }
 
@@ -1120,7 +1121,7 @@ void SocketApi::setFileLock(const QString &localFile, const SyncFileItem::LockSt
                                                              shareFolder->path(),
                                                              shareFolder->journalDb(),
                                                              lockState,
-                                                             SyncFileItem::LockOwnerType::UserLock);
+                                                             (lockState == SyncFileItem::LockStatus::UnlockedItem) ? static_cast<SyncFileItem::LockOwnerType>(record._lockstate._lockOwnerType) : SyncFileItem::LockOwnerType::UserLock);
 
     shareFolder->journalDb()->schedulePathForRemoteDiscovery(fileData.serverRelativePath);
     shareFolder->scheduleThisFolderSoon();
index 74b1856f43b05c922e3827fe3ad474cd551312cf..401e22ae9a0387b3d5d549feb75f6bdc59ca3797 100644 (file)
@@ -1022,11 +1022,20 @@ bool Account::fileCanBeUnlocked(SyncJournalDb * const journal,
 {
     SyncJournalFileRecord record;
     if (journal->getFileRecord(folderRelativePath, &record)) {
-        if (record._lockstate._lockOwnerType != static_cast<int>(SyncFileItem::LockOwnerType::UserLock)) {
+        if (record._lockstate._lockOwnerType == static_cast<int>(SyncFileItem::LockOwnerType::AppLock)) {
+            qCDebug(lcAccount()) << folderRelativePath << "cannot be unlocked: app lock";
             return false;
         }
 
-        if (record._lockstate._lockOwnerId != sharedFromThis()->davUser()) {
+        if (record._lockstate._lockOwnerType == static_cast<int>(SyncFileItem::LockOwnerType::UserLock) &&
+            record._lockstate._lockOwnerId != sharedFromThis()->davUser()) {
+            qCDebug(lcAccount()) << folderRelativePath << "cannot be unlocked: user lock from" << record._lockstate._lockOwnerId;
+            return false;
+        }
+
+        if (record._lockstate._lockOwnerType == static_cast<int>(SyncFileItem::LockOwnerType::TokenLock) &&
+            record._lockstate._lockToken.isEmpty()) {
+            qCDebug(lcAccount()) << folderRelativePath << "cannot be unlocked: token lock without known token";
             return false;
         }