marinofaggiana 5 years ago
parent
commit
5bb9d58926
2 changed files with 36 additions and 13 deletions
  1. 28 5
      iOSClient/Share/NCShare.swift
  2. 8 8
      iOSClient/Share/NCShareNetworking.swift

+ 28 - 5
iOSClient/Share/NCShare.swift

@@ -136,15 +136,38 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
     @IBAction func touchUpInsideButtonMenu(_ sender: Any) {
 
         guard let metadata = self.metadata else { return }
-
+        guard let capabilities = NCManageDatabase.sharedInstance.getCapabilites(account: metadata.account) else { return }
         let shares = NCManageDatabase.sharedInstance.getTableShares(metadata: metadata)
-        if shares.firstShareLink != nil {
-            tapMenu(with: shares.firstShareLink!, sender: sender)
-        } else {
+
+        if capabilities.isFilesSharingPublicPasswordEnforced && shares.firstShareLink == nil {
+            let alertController = UIAlertController(title: NSLocalizedString("_enforce_password_protection_", comment: ""), message: "", preferredStyle: .alert)
+            alertController.addTextField { (textField) in
+                textField.isSecureTextEntry = true
+                textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(sender:)), for: UIControl.Event.editingChanged)
+            }
+            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?.share(password: password ?? "", permission: 1, hideDownload: false)
+            }
+            okAction.isEnabled = false
+            alertController.addAction(okAction)
+            
+            self.present(alertController, animated: true, completion:nil)
+        } else if shares.firstShareLink == nil {
             networking?.share(password: "", permission: 1, hideDownload: false)
+        } else {
+            tapMenu(with: shares.firstShareLink!, sender: sender)
         }
     }
     
+    @objc func minCharTextFieldDidChange(sender: UITextField) {
+        guard let alertController = self.presentedViewController as? UIAlertController else { return }
+        guard let password = alertController.textFields?.first else { return }
+        guard let ok = alertController.actions.last else { return }
+        ok.isEnabled =  password.text?.count ?? 0 >= 8
+    }
+    
     @objc func tapLinkMenuViewWindow(gesture: UITapGestureRecognizer) {
         shareLinkMenuView?.unLoad()
         shareLinkMenuView = nil
@@ -338,7 +361,7 @@ extension NCShare: UITableViewDataSource {
                 
                 cell.tableShare = tableShare
                 cell.delegate = self
-                cell.labelTitle.text = tableShare.shareWith
+                cell.labelTitle.text = tableShare.shareWithDisplayName
                 cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
                 cell.labelCanEdit.text = NSLocalizedString("_share_permission_edit_", comment: "")
                 cell.labelCanEdit.textColor = NCBrandColor.sharedInstance.textView

+ 8 - 8
iOSClient/Share/NCShareNetworking.swift

@@ -50,7 +50,7 @@ class NCShareNetworking: NSObject {
                 self.appDelegate.activeMain?.tableView?.reloadData()
                 self.appDelegate.activeFavorites?.tableView?.reloadData()
             } else {
-                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
             }
             self.delegate?.readShareCompleted()
         })
@@ -69,13 +69,13 @@ class NCShareNetworking: NSObject {
                         self.appDelegate.activeMain?.tableView?.reloadData()
                         self.appDelegate.activeFavorites?.tableView?.reloadData()
                     } else {
-                        self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+                        self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
                     }
                     self.delegate?.shareCompleted()
                 })
             } else {
                 NCUtility.sharedInstance.stopActivityIndicator()
-                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
             }
         })
     }
@@ -88,7 +88,7 @@ class NCShareNetworking: NSObject {
                 NCManageDatabase.sharedInstance.deleteTableShare(account: account!, idRemoteShared: idRemoteShared)
                 self.delegate?.unShareCompleted()
             } else {
-                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
             }
         })
     }
@@ -100,7 +100,7 @@ class NCShareNetworking: NSObject {
             if errorCode == 0 {
                 self.readShare()
             } else {
-                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
                 self.delegate?.updateShareWithError(idRemoteShared: idRemoteShared)
             }
         })
@@ -114,7 +114,7 @@ class NCShareNetworking: NSObject {
                 let itemsOCShareUser = items as! [OCShareUser]
                 self.delegate?.getUserAndGroup(items: itemsOCShareUser)
             } else {
-                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
                 self.delegate?.getUserAndGroup(items: nil)
             }
         })
@@ -135,13 +135,13 @@ class NCShareNetworking: NSObject {
                         self.appDelegate.activeMain?.tableView?.reloadData()
                         self.appDelegate.activeFavorites?.tableView?.reloadData()
                     } else {
-                        self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+                        self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
                     }
                     self.delegate?.shareCompleted()
                 })
             } else {
                 NCUtility.sharedInstance.stopActivityIndicator()
-                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+                self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
             }
         })
     }