Przeglądaj źródła

Files lock strict access

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 lat temu
rodzic
commit
7f7e809255

+ 1 - 1
File Provider Extension/FileProviderItem.swift

@@ -63,7 +63,7 @@ class FileProviderItem: NSObject, NSFileProviderItem {
         guard !metadata.directory else {
             return [ .allowsAddingSubItems, .allowsContentEnumerating, .allowsReading, .allowsDeleting, .allowsRenaming ]
         }
-        guard metadata.canUnlock(as: fileProviderData.shared.userId) else {
+        guard !metadata.lock else {
             return [ .allowsReading ]
         }
         return [ .allowsWriting, .allowsReading, .allowsDeleting, .allowsRenaming, .allowsReparenting ]

+ 8 - 6
iOSClient/Main/NCFunctionCenter.swift

@@ -617,7 +617,7 @@ import SVGKit
         }
         let titleOffline = isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") :  NSLocalizedString("_set_available_offline_", comment: "")
         let titleLock = metadata.lock ? NSLocalizedString("_unlock_file_", comment: "") :  NSLocalizedString("_lock_file_", comment: "")
-        let iconLock = metadata.lock ? "lock_open" : "lock"
+        let iconLock = metadata.lock ? "lock.open" : "lock"
         let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), image: UIImage(systemName: "doc.on.doc")) { _ in
             self.copyPasteboard(pasteboardOcIds: [metadata.ocId], hudView: viewController.view)
         }
@@ -745,18 +745,20 @@ import SVGKit
 
         // FILE
 
-        var children: [UIMenuElement] = [favorite, offline, openIn, moveCopy, copy, copyPath]
+        var children: [UIMenuElement] = [offline, openIn, moveCopy, copy, copyPath]
         
-        if metadata.canUnlock(as: appDelegate.userId) {
+        if !metadata.lock {
+            children.insert(favorite, at: 0)
             children.append(delete)
             children.insert(rename, at: 3)
-            if NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesFilesLockVersion) >= 1 {
-                children.insert(lockUnlock, at: metadata.lock ? 0 : 1)
-            }
         } else if enableDeleteLocal {
             children.append(deleteConfirmLocal)
         }
 
+        if NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesFilesLockVersion) >= 1, metadata.canUnlock(as: appDelegate.userId) {
+            children.insert(lockUnlock, at: metadata.lock ? 0 : 1)
+        }
+
         if (metadata.contentType != "image/svg+xml") && (metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue) {
             children.insert(save, at: 2)
         }

+ 15 - 13
iOSClient/Menu/NCCollectionViewCommon+Menu.swift

@@ -41,7 +41,6 @@ extension NCCollectionViewCommon {
         let isFolderEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account, urlBase: metadata.urlBase)
         let serverUrlHome = NCUtilityFileSystem.shared.getHomeServer(account: appDelegate.account)
         let isOffline: Bool
-        let canUnlock = metadata.canUnlock(as: appDelegate.userId)
 
         if metadata.directory, let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl)) {
             isOffline = directory.offline
@@ -104,19 +103,21 @@ extension NCCollectionViewCommon {
         //
         // FAVORITE
         //
-        actions.append(
-            NCMenuAction(
-                title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
-                icon: NCUtility.shared.loadImage(named: "star.fill", color: NCBrandColor.shared.yellowFavorite),
-                action: { _ in
-                    NCNetworking.shared.favoriteMetadata(metadata) { errorCode, errorDescription in
-                        if errorCode != 0 {
-                            NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
+        if !metadata.lock {
+            actions.append(
+                NCMenuAction(
+                    title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
+                    icon: NCUtility.shared.loadImage(named: "star.fill", color: NCBrandColor.shared.yellowFavorite),
+                    action: { _ in
+                        NCNetworking.shared.favoriteMetadata(metadata) { errorCode, errorDescription in
+                            if errorCode != 0 {
+                                NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                            }
                         }
                     }
-                }
+                )
             )
-        )
+        }
 
         //
         // DETAIL
@@ -136,7 +137,8 @@ extension NCCollectionViewCommon {
         //
         // LOCK / UNLOCK
         //
-        if !metadata.directory, canUnlock, NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesFilesLockVersion) >= 1 {
+        let hasLockCapability = NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesFilesLockVersion) >= 1
+        if !metadata.directory, metadata.canUnlock(as: appDelegate.userId), hasLockCapability {
             let lockAction = NCMenuAction.lockUnlockFiles(shouldLock: !metadata.lock, metadatas: [metadata])
             if metadata.lock {
                 // make unlock first action, after info rows & seperator
@@ -226,7 +228,7 @@ extension NCCollectionViewCommon {
         //
         // RENAME
         //
-        if !(isFolderEncrypted && metadata.serverUrl == serverUrlHome), canUnlock {
+        if !(isFolderEncrypted && metadata.serverUrl == serverUrlHome), !metadata.lock {
             actions.append(
                 NCMenuAction(
                     title: NSLocalizedString("_rename_", comment: ""),

+ 1 - 1
iOSClient/Menu/NCMenuAction.swift

@@ -96,7 +96,7 @@ extension NCMenuAction {
             }
         } // else: no metadata selected
 
-        let canDeleteServer = selectedMetadatas.allSatisfy { $0.canUnlock(as: (UIApplication.shared.delegate as? AppDelegate)?.userId ?? "") }
+        let canDeleteServer = selectedMetadatas.allSatisfy { !$0.lock }
         var fileList = ""
         for (ix, metadata) in selectedMetadatas.enumerated() {
             guard ix < 3 else { fileList += "\n - ..."; break }

+ 13 - 11
iOSClient/Menu/NCViewer+Menu.swift

@@ -41,19 +41,21 @@ extension NCViewer {
         //
         // FAVORITE
         //
-        actions.append(
-            NCMenuAction(
-                title: titleFavorite,
-                icon: NCUtility.shared.loadImage(named: "star.fill", color: NCBrandColor.shared.yellowFavorite),
-                action: { _ in
-                    NCNetworking.shared.favoriteMetadata(metadata) { errorCode, errorDescription in
-                        if errorCode != 0 {
-                            NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
+        if !metadata.lock {
+            actions.append(
+                NCMenuAction(
+                    title: titleFavorite,
+                    icon: NCUtility.shared.loadImage(named: "star.fill", color: NCBrandColor.shared.yellowFavorite),
+                    action: { _ in
+                        NCNetworking.shared.favoriteMetadata(metadata) { errorCode, errorDescription in
+                            if errorCode != 0 {
+                                NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                            }
                         }
                     }
-                }
+                )
             )
-        )
+        }
 
         //
         // DETAIL
@@ -146,7 +148,7 @@ extension NCViewer {
         //
         // RENAME
         //
-        if !webView, metadata.canUnlock(as: appDelegate.userId) {
+        if !webView, !metadata.lock {
             actions.append(
                 NCMenuAction(
                     title: NSLocalizedString("_rename_", comment: ""),

+ 1 - 2
iOSClient/Select/NCSelect.swift

@@ -141,8 +141,7 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, UIAdaptivePresent
             self.view.addSubview(selectCommandViewSelect!)
             selectCommandViewSelect?.selectView = self
             selectCommandViewSelect?.translatesAutoresizingMaskIntoConstraints = false
-            let userId = NCManageDatabase.shared.getActiveAccount()?.userId ?? ""
-            if items.contains(where: { !$0.canUnlock(as: userId) }) {
+            if items.contains(where: { $0.lock }) {
                 selectCommandViewSelect?.moveButton?.isEnabled = false
                 selectCommandViewSelect?.moveButton?.titleLabel?.isEnabled = false
             }

+ 1 - 1
iOSClient/Viewer/NCViewerQuickLook/NCViewerQuickLook.swift

@@ -92,7 +92,7 @@ import NCCommunication
         let userId = (UIApplication.shared.delegate as? AppDelegate)?.userId ?? ""
         if metadata.livePhoto {
             message = NSLocalizedString("_message_disable_overwrite_livephoto_", comment: "")
-        } else if !metadata.canUnlock(as: userId) {
+        } else if metadata.lock {
             message = NSLocalizedString("_file_locked_no_override_", comment: "")
         } else {
             alertController.addAction(UIAlertAction(title: NSLocalizedString("_overwrite_original_", comment: ""), style: .default) { _ in