Marino Faggiana 1 year ago
parent
commit
34a738bda2

+ 13 - 0
iOSClient/Data/NCManageDatabase+Directory.swift

@@ -138,6 +138,19 @@ extension NCManageDatabase {
         return nil
     }
 
+    func getTableDirectory(account: String, serverUrl: String) -> tableDirectory? {
+
+        do {
+            let realm = try Realm()
+            realm.refresh()
+            return realm.objects(tableDirectory.self).filter("account == %@ AND serverUrl == %@", account, serverUrl).first
+        } catch let error as NSError {
+            NextcloudKit.shared.nkCommonInstance.writeLog("Could not access database: \(error)")
+        }
+
+        return nil
+    }
+
     func getTableDirectory(ocId: String) -> tableDirectory? {
 
         do {

+ 8 - 3
iOSClient/Data/NCManageDatabase+Metadata.swift

@@ -235,17 +235,22 @@ extension tableMetadata {
         NCUtility.shared.isDirectoryE2EE(account: account, urlBase: urlBase, userId: userId, serverUrl: serverUrl)
     }
 
+    var isDirectoryTopE2EE: Bool {
+        NCUtility.shared.isDirectoryE2EETop(account: account, serverUrl: serverUrl)
+    }
+
     /// Returns false if the user is lokced out of the file. I.e. The file is locked but by somone else
     func canUnlock(as user: String) -> Bool {
         return !lock || (lockOwner == user && lockOwnerType == 0)
     }
 
-    // Return if is sharable (temp)
-    // TODO: modifify for E2EE 2.0
+    // Return if is sharable
     func isSharable() -> Bool {
         guard NCGlobal.shared.capabilityFileSharingApiEnabled else { return false }
 
-        if !e2eEncrypted && !isDirectoryE2EE {
+        if NCGlobal.shared.capabilityE2EEApiVersion == NCGlobal.shared.e2eeVersionV20, isDirectoryE2EE {
+            return !isDirectoryTopE2EE
+        } else if !e2eEncrypted && !isDirectoryE2EE {
             return true
         } else if NCGlobal.shared.capabilityServerVersionMajor >= NCGlobal.shared.nextcloudVersion26 && directory {
             // E2EE DIRECTORY SECURE FILE DROP (SHARE AVAILABLE)

+ 3 - 14
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -38,8 +38,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     internal var emptyDataSet: NCEmptyDataSet?
     internal var backgroundImageView = UIImageView()
     internal var serverUrl: String = ""
-    internal var isDirectoryE2EE = false
-    internal var isDirectoryE2EETop = false
     internal var isEditMode = false
     internal var selectOcId: [String] = []
     internal var selectIndexPath: [IndexPath] = []
@@ -953,9 +951,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     @objc func reloadDataSource(isForced: Bool = true) {
         guard !appDelegate.account.isEmpty else { return }
 
-        // E2EE
-        isDirectoryE2EE = NCUtility.shared.isDirectoryE2EE(serverUrl: serverUrl, userBase: appDelegate)
-        isDirectoryE2EETop =  NCUtility.shared.isDirectoryE2EETop(account: appDelegate.account, serverUrl: serverUrl)
         // get auto upload folder
         autoUploadFileName = NCManageDatabase.shared.getAccountAutoUploadFileName()
         autoUploadDirectory = NCManageDatabase.shared.getAccountAutoUploadDirectory(urlBase: appDelegate.urlBase, userId: appDelegate.userId, account: appDelegate.account)
@@ -1622,11 +1617,6 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
             }
         }
 
-        // Disable Share Button
-        if appDelegate.disableSharesView || (isDirectoryE2EE && !isDirectoryE2EETop ) {
-            cell.hideButtonShare(true)
-        }
-
         // Separator
         if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 || isSearchingMode {
             cell.cellSeparatorView?.isHidden = true
@@ -1669,12 +1659,11 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
         }
 
         // ** IMPORT MUST BE AT THE END **
-        //
-
-        if !metadata.isSharable() {
+        // Disable Share Button
+        if appDelegate.disableSharesView || !metadata.isSharable() {
             cell.hideButtonShare(true)
         }
-        
+
         return cell
     }
 

+ 4 - 4
iOSClient/Utility/NCUtility.swift

@@ -757,7 +757,7 @@ class NCUtility: NSObject {
 
     func isDirectoryE2EE(account: String, urlBase: String, userId: String, serverUrl: String) -> Bool {
         if serverUrl == NCUtilityFileSystem.shared.getHomeServer(urlBase: urlBase, userId: userId) || serverUrl == ".." { return false }
-        if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", account, serverUrl)) {
+        if let directory = NCManageDatabase.shared.getTableDirectory(account: account, serverUrl: serverUrl) {
             return directory.e2eEncrypted
         }
         return false
@@ -765,7 +765,7 @@ class NCUtility: NSObject {
 
     func isDirectoryE2EETop(account: String, serverUrl: String) -> Bool {
         if let url = URL(string: serverUrl)?.deletingLastPathComponent() {
-            if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", account, String(url.absoluteString.dropLast()))) {
+            if let directory = NCManageDatabase.shared.getTableDirectory(account: account, serverUrl: String(url.absoluteString.dropLast())) {
                 return !directory.e2eEncrypted
             }
         }
@@ -774,11 +774,11 @@ class NCUtility: NSObject {
 
     func getDirectoryE2EETop(serverUrl: String, account: String) -> tableDirectory? {
         var serverUrl = serverUrl
-        var top = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", account, serverUrl))
+        var top = NCManageDatabase.shared.getTableDirectory(account: account, serverUrl: serverUrl)
         while true {
             if let url = URL(string: serverUrl)?.deletingLastPathComponent() {
                 serverUrl = String(url.absoluteString.dropLast())
-                if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", account, serverUrl)) {
+                if let directory = NCManageDatabase.shared.getTableDirectory(account: account, serverUrl: serverUrl) {
                     if directory.e2eEncrypted {
                         top = directory
                     } else {