Răsfoiți Sursa

Fix share email, not asked for password

Check for password enforcement every time a new share should be created. Will display an alert. If password enforcement is off, callback returns `nil`.

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 ani în urmă
părinte
comite
664a83389a
2 a modificat fișierele cu 32 adăugiri și 23 ștergeri
  1. 30 21
      iOSClient/Share/NCShare.swift
  2. 2 2
      iOSClient/Share/NCShareNetworking.swift

+ 30 - 21
iOSClient/Share/NCShare.swift

@@ -231,34 +231,41 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
             }
         }
     }
+
+    func checkEnforcedPassword(callback: @escaping (String?) -> Void) {
+        guard let metadata = self.metadata,
+              NCManageDatabase.shared.getCapabilitiesServerBool(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesFileSharingPubPasswdEnforced, exists: false)
+        else { return callback(nil) }
+
+        let alertController = UIAlertController(title: NSLocalizedString("_enforce_password_protection_", comment: ""), message: "", preferredStyle: .alert)
+        alertController.addTextField { textField in
+            textField.isSecureTextEntry = true
+        }
+        alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .default) { _ in })
+        let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { _ in
+            let password = alertController.textFields?.first?.text
+            callback(password)
+        }
+
+        alertController.addAction(okAction)
+
+        self.present(alertController, animated: true, completion:nil)
+    }
     
     @IBAction func touchUpInsideButtonMenu(_ sender: Any) {
 
         guard let metadata = self.metadata else { return }
-        let isFilesSharingPublicPasswordEnforced = NCManageDatabase.shared.getCapabilitiesServerBool(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesFileSharingPubPasswdEnforced, exists: false)
         let shares = NCManageDatabase.shared.getTableShares(metadata: metadata)
 
-        if isFilesSharingPublicPasswordEnforced && shares.firstShareLink == nil {
-            let alertController = UIAlertController(title: NSLocalizedString("_enforce_password_protection_", comment: ""), message: "", preferredStyle: .alert)
-            alertController.addTextField { (textField) in
-                textField.isSecureTextEntry = true
-            }
-            alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .default) { (action:UIAlertAction) in })
-            let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { (action:UIAlertAction) in
-                let password = alertController.textFields?.first?.text
-                self.networking?.createShareLink(password: password ?? "")
+        if shares.firstShareLink == nil {
+            checkEnforcedPassword { password in
+                self.networking?.createShareLink(password: password)
             }
-            
-            alertController.addAction(okAction)
-            
-            self.present(alertController, animated: true, completion:nil)
-        } else if shares.firstShareLink == nil {
-            networking?.createShareLink(password: "")
         } else {
             tapMenu(with: shares.firstShareLink!, sender: sender)
         }
     }
-    
+
     @objc func tapLinkMenuViewWindow(gesture: UITapGestureRecognizer) {
         shareLinkMenuView?.unLoad()
         shareLinkMenuView = nil
@@ -354,12 +361,14 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
                 }
             }
         }
-        
-        dropDown.selectionAction = { [weak self] (index, item) in
+
+        dropDown.selectionAction = { (index, item) in
             let sharee = sharees[index]
-            self!.networking?.createShare(shareWith: sharee.shareWith, shareType: sharee.shareType, metadata: self!.metadata!)
+            self.checkEnforcedPassword { password in
+                self.networking?.createShare(shareWith: sharee.shareWith, shareType: sharee.shareType, password: password, metadata: self.metadata!)
+            }
         }
-        
+
         dropDown.show()
     }
 }

+ 2 - 2
iOSClient/Share/NCShareNetworking.swift

@@ -78,7 +78,7 @@ class NCShareNetworking: NSObject {
         }
     }
     
-    func createShare(shareWith: String, shareType: Int, metadata: tableMetadata) {
+    func createShare(shareWith: String, shareType: Int, password: String?, metadata: tableMetadata) {
         NCUtility.shared.startActivityIndicator(backgroundView: view, blurEffect: false)
         let filenamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, urlBase: urlBase, account: metadata.account)!
         var permission: Int = NCManageDatabase.shared.getCapabilitiesServerInt(account: metadata.account, elements: ["ocs","data","capabilities","files_sharing","default_permissions"])
@@ -86,7 +86,7 @@ class NCShareNetworking: NSObject {
             permission = metadata.directory ? NCGlobal.shared.permissionMaxFolderShare : NCGlobal.shared.permissionMaxFileShare
         }
 
-        NCCommunication.shared.createShare(path: filenamePath, shareType: shareType, shareWith: shareWith, permissions: permission) { (account, share, errorCode, errorDescription) in
+        NCCommunication.shared.createShare(path: filenamePath, shareType: shareType, shareWith: shareWith, password: password, permissions: permission) { (account, share, errorCode, errorDescription) in
             NCUtility.shared.stopActivityIndicator()
             if errorCode == 0 && share != nil {
                 NCManageDatabase.shared.addShare(urlBase: self.urlBase, account: self.metadata.account, shares: [share!])