Эх сурвалжийг харах

Merge pull request #2324 from nextcloud/filedrop

create secure file drop share
Marino Faggiana 2 жил өмнө
parent
commit
fbc9b49aad

+ 4 - 2
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1677,9 +1677,11 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
             cell.fileTitleLabel?.attributedText = attributedString
         }
 
-        // E2EE
         // ** IMPORT MUST BE AT THE END **
-        if metadata.e2eEncrypted || isDirectoryE2EE {
+        // if metadata.e2eEncrypted || isDirectoryE2EE {
+        //
+        // E2EE SECURE FILE DROP (DIR ONLY)
+        if !metadata.directory && (metadata.e2eEncrypted || isDirectoryE2EE) {
             cell.hideButtonShare(true)
         }
 

+ 1 - 1
iOSClient/Share/Advanced/NCShareAdvancePermissionHeader.swift

@@ -36,7 +36,7 @@ class NCShareAdvancePermissionHeader: UIView {
             imageView.isHidden = true
         } else {
             if metadata.directory {
-                imageView.image = NCBrandColor.cacheImages.folder
+                imageView.image = metadata.e2eEncrypted ? UIImage(named: "folderEncrypted") : UIImage(named: "folder")
             } else if !metadata.iconName.isEmpty {
                 imageView.image = UIImage(named: metadata.iconName)
             } else {

+ 9 - 2
iOSClient/Share/Advanced/NCShareCells.swift

@@ -46,6 +46,7 @@ extension NCToggleCellConfig {
 
 protocol NCPermission: NCToggleCellConfig {
     static var forDirectory: [Self] { get }
+    static var forDirectoryE2EE: [Self] { get }
     static var forFile: [Self] { get }
     func hasResharePermission(for parentPermission: Int) -> Bool
 }
@@ -74,6 +75,7 @@ enum NCUserPermission: CaseIterable, NCPermission {
 
     case reshare, edit, create, delete
     static let forDirectory: [NCUserPermission] = NCUserPermission.allCases
+    static let forDirectoryE2EE: [NCUserPermission] = []
     static let forFile: [NCUserPermission] = [.reshare, .edit]
 
     var title: String {
@@ -129,6 +131,8 @@ enum NCLinkPermission: NCPermission {
                 andIsFolder: true)
         case .fileDrop:
             return NCGlobal.shared.permissionCreateShare
+        case .secureFileDrop:
+            return NCGlobal.shared.permissionCreateShare
         }
     }
 
@@ -138,6 +142,7 @@ enum NCLinkPermission: NCPermission {
         case .viewOnly: return !CCUtility.isAnyPermission(toEdit: share.permissions) && share.permissions != NCGlobal.shared.permissionCreateShare
         case .uploadEdit: return CCUtility.isAnyPermission(toEdit: share.permissions) && share.permissions != NCGlobal.shared.permissionCreateShare
         case .fileDrop: return share.permissions == NCGlobal.shared.permissionCreateShare
+        case .secureFileDrop: return share.permissions == NCGlobal.shared.permissionCreateShare
         }
     }
 
@@ -147,12 +152,14 @@ enum NCLinkPermission: NCPermission {
         case .viewOnly: return NSLocalizedString("_share_read_only_", comment: "")
         case .uploadEdit: return NSLocalizedString("_share_allow_upload_", comment: "")
         case .fileDrop: return NSLocalizedString("_share_file_drop_", comment: "")
+        case .secureFileDrop: return NSLocalizedString("_share_secure_file_drop_", comment: "")
         }
     }
 
-    case allowEdit, viewOnly, uploadEdit, fileDrop
+    case allowEdit, viewOnly, uploadEdit, fileDrop, secureFileDrop
     static let forDirectory: [NCLinkPermission] = [.viewOnly, .uploadEdit, .fileDrop]
     static let forFile: [NCLinkPermission] = [.allowEdit]
+    static let forDirectoryE2EE: [NCLinkPermission] = [.secureFileDrop]
 }
 
 enum NCShareDetails: CaseIterable, NCShareCellConfig {
@@ -210,7 +217,7 @@ struct NCShareConfig {
         self.share = share
         self.resharePermission = parentMetadata.sharePermissionsCollaborationServices
         let type: NCPermission.Type = share.shareType == NCShareCommon.shared.SHARE_TYPE_LINK ? NCLinkPermission.self : NCUserPermission.self
-        self.permissions = parentMetadata.directory ? type.forDirectory : type.forFile
+        self.permissions = parentMetadata.directory ? (parentMetadata.e2eEncrypted ? type.forDirectoryE2EE : type.forDirectory) : type.forFile
         self.advanced = share.shareType == NCShareCommon.shared.SHARE_TYPE_LINK ? NCShareDetails.forLink : NCShareDetails.forUser
     }
 

+ 5 - 1
iOSClient/Share/NCShare+Helper.swift

@@ -76,7 +76,11 @@ class NCTableShareOptions: NCTableShareable {
     var shareWithDisplayname: String = ""
 
     private init(shareType: Int, metadata: tableMetadata, password: String?) {
-        self.permissions = NCManageDatabase.shared.getCapabilitiesServerInt(account: metadata.account, elements: ["ocs", "data", "capabilities", "files_sharing", "default_permissions"]) & metadata.sharePermissionsCollaborationServices
+        if metadata.e2eEncrypted {
+            self.permissions = NCGlobal.shared.permissionCreateShare
+        } else {
+            self.permissions = NCManageDatabase.shared.getCapabilitiesServerInt(account: metadata.account, elements: ["ocs", "data", "capabilities", "files_sharing", "default_permissions"]) & metadata.sharePermissionsCollaborationServices
+        }
         self.shareType = shareType
         if let password = password {
             self.password = password

+ 25 - 8
iOSClient/Share/NCShare.swift

@@ -83,7 +83,12 @@ class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent
 
         guard let metadata = metadata else { return }
 
-        checkSharedWithYou()
+        if metadata.e2eEncrypted {
+            searchFieldTopConstraint.constant = -50
+            searchField.isHidden = true
+        } else {
+            checkSharedWithYou()
+        }
 
         reloadData()
 
@@ -293,21 +298,33 @@ extension NCShare: UITableViewDataSource {
     }
 
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        // don't allow link creation if reshare is disabled
-        guard section != 0 else { return shares.firstShareLink != nil || canReshare ? 2 : 1 }
-        return shares.share?.count ?? 0
+        guard let metadata = self.metadata else { return 0}
+        var numRows = shares.share?.count ?? 0
+        if section == 0 {
+            if metadata.e2eEncrypted {
+                numRows = 1
+            } else {
+                // don't allow link creation if reshare is disabled
+                numRows = shares.firstShareLink != nil || canReshare ? 2 : 1
+            }
+        }
+        return numRows
     }
 
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         // Setup default share cells
         guard indexPath.section != 0 else {
-            guard let cell = tableView.dequeueReusableCell(withIdentifier: "cellLink", for: indexPath) as? NCShareLinkCell
+            guard let cell = tableView.dequeueReusableCell(withIdentifier: "cellLink", for: indexPath) as? NCShareLinkCell, let metadata = self.metadata
             else { return UITableViewCell() }
             cell.delegate = self
-            if indexPath.row == 0 {
-                cell.isInternalLink = true
-            } else if shares.firstShareLink?.isInvalidated != true {
+            if metadata.e2eEncrypted {
                 cell.tableShare = shares.firstShareLink
+            } else {
+                if indexPath.row == 0 {
+                    cell.isInternalLink = true
+                } else if shares.firstShareLink?.isInvalidated != true {
+                    cell.tableShare = shares.firstShareLink
+                }
             }
             cell.setupCellUI()
             return cell

+ 1 - 4
iOSClient/Share/NCSharePaging.swift

@@ -115,9 +115,6 @@ class NCSharePaging: UIViewController {
         sharingEnabled = sharing
         let activity = NCManageDatabase.shared.getCapabilitiesServerArray(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesActivity)
         activityEnabled = activity != nil
-        if metadata.e2eEncrypted || NCUtility.shared.isDirectoryE2EE(metadata: metadata) {
-            sharingEnabled = false
-        }
         if indexPage == .sharing && !sharingEnabled {
             indexPage = .activity
         }
@@ -315,7 +312,7 @@ class NCSharePagingView: PagingView {
             headerView.imageView.image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
         } else {
             if metadata.directory {
-                let image = UIImage(named: "folder")
+                let image = metadata.e2eEncrypted ? UIImage(named: "folderEncrypted") : UIImage(named: "folder")
                 headerView.imageView.image = image?.image(color: NCBrandColor.shared.brandElement, size: image?.size.width ?? 0)
                 headerView.imageView.image = headerView.imageView.image?.colorizeFolder(metadata: metadata)
             } else if !metadata.iconName.isEmpty {

+ 1 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -634,6 +634,7 @@
 "_share_editing_"               = "Editing";
 "_share_allow_upload_"          = "Allow upload and editing";
 "_share_file_drop_"             = "File drop (upload only)";
+"_share_secure_file_drop_"      = "Secure file drop (upload only)";
 "_share_hide_download_"         = "Hide download";
 "_share_password_protect_"      = "Password protect";
 "_share_expiration_date_"       = "Set expiration date";