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

Workaround share creation by just creating the share and updating right away after each other.

- fix password protection alert. Only check for link or email, otherwise password is not needed
- fix footer debug background

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 жил өмнө
parent
commit
a7aff4b4a5

+ 1 - 2
iOSClient/Share/Advanced/NCShareAdvancePermission.swift

@@ -66,7 +66,6 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg
 
         // tableFooterView can't use auto layout directly
         let container = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 120))
-        container.backgroundColor = .blue
         container.addSubview(footerView)
         tableView.tableFooterView = container
         footerView.translatesAutoresizingMaskIntoConstraints = false
@@ -136,7 +135,7 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg
                 tableView.reloadData()
                 return
             }
-            let alertController = UIAlertController.withTextField(titleKey: "_enforce_password_protection_") { textField in
+            let alertController = UIAlertController.withTextField(titleKey: "_share_password_") { textField in
                 textField.placeholder = NSLocalizedString("_password_", comment: "")
                 textField.isSecureTextEntry = true
             } completion: { password in

+ 1 - 2
iOSClient/Share/Advanced/NCShareAdvancePermissionFooter.swift

@@ -35,8 +35,7 @@ class NCShareAdvancePermissionFooter: UIView {
 
     func setupUI(delegate: NCShareAdvanceFotterDelegate?) {
         self.delegate = delegate
-
-        backgroundColor = .red
+        backgroundColor = .clear
 
         buttonCancel.addTarget(self, action: #selector(cancelClicked), for: .touchUpInside)
         buttonCancel.setTitle(NSLocalizedString("_cancel_", comment: ""), for: .normal)

+ 13 - 9
iOSClient/Share/NCShare.swift

@@ -185,12 +185,13 @@ class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent
         networking?.getSharees(searchString: searchString)
     }
 
-    func checkEnforcedPassword(callback: @escaping (String?) -> Void) {
+    func checkEnforcedPassword(shareType: Int? = nil, completion: @escaping (String?) -> Void) {
         guard let metadata = self.metadata,
-              NCManageDatabase.shared.getCapabilitiesServerBool(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesFileSharingPubPasswdEnforced, exists: false)
-        else { return callback(nil) }
+              NCManageDatabase.shared.getCapabilitiesServerBool(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesFileSharingPubPasswdEnforced, exists: false),
+              shareType == NCShareCommon.shared.SHARE_TYPE_USER || shareType == NCShareCommon.shared.SHARE_TYPE_EMAIL
+        else { return completion(nil) }
 
-        self.present(UIAlertController.sharePassword(completion: callback), animated: true)
+        self.present(UIAlertController.sharePassword(completion: completion), animated: true)
     }
 
     // MARK: - NCShareNetworkingDelegate
@@ -253,11 +254,14 @@ class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent
                 let advancePermission = UIStoryboard(name: "NCShare", bundle: nil).instantiateViewController(withIdentifier: "NCShareAdvancePermission") as? NCShareAdvancePermission,
                 let navigationController = self.navigationController,
                 let metadata = self.metadata else { return }
-            let shareOptions = NCTableShareOptions(sharee: sharee, metadata: metadata)
-            advancePermission.share = shareOptions
-            advancePermission.networking = self.networking
-            advancePermission.metadata = metadata
-            navigationController.pushViewController(advancePermission, animated: true)
+            self.checkEnforcedPassword(shareType: sharee.shareType) { password in
+                let shareOptions = NCTableShareOptions(sharee: sharee, metadata: metadata)
+                if let password = password { shareOptions.password = password }
+                advancePermission.share = shareOptions
+                advancePermission.networking = self.networking
+                advancePermission.metadata = metadata
+                navigationController.pushViewController(advancePermission, animated: true)
+            }
         }
 
         dropDown.show()

+ 12 - 8
iOSClient/Share/NCShareNetworking.swift

@@ -53,8 +53,8 @@ class NCShareNetworking: NSObject {
                 NCUtility.shared.stopActivityIndicator()
             }
 
-             if errorCode == 0 && shares != nil {
-                NCManageDatabase.shared.addShare(urlBase: self.urlBase, account: self.metadata.account, shares: shares!)
+             if errorCode == 0, let shares = shares {
+                NCManageDatabase.shared.addShare(urlBase: self.urlBase, account: self.metadata.account, shares: shares)
                 self.appDelegate.shares = NCManageDatabase.shared.getTableShares(account: self.metadata.account)
             } else {
                 NCContentPresenter.shared.messageNotification("_share_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.errorInternalError)
@@ -64,19 +64,23 @@ class NCShareNetworking: NSObject {
     }
     
     func createShare(option: NCTableShareable) {
-        // NOTE: Permissions don't work for file drop!
+        // NOTE: Permissions don't work for creating with file drop!
         // https://github.com/nextcloud/server/issues/17504
 
-        // NOTE: Can't save label, expirationDate, and note, until library update
+        // NOTE: Can't save label, expirationDate, and note in same request.
+        // Library update needed:
         // https://github.com/nextcloud/ios-communication-library/pull/104
+
         NCUtility.shared.startActivityIndicator(backgroundView: view, blurEffect: false)
         let filenamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, urlBase: urlBase, account: metadata.account)!
         let permission = max(1, metadata.sharePermissionsCollaborationServices & option.permissions)
 
         NCCommunication.shared.createShare(path: filenamePath, shareType: option.shareType, shareWith: option.shareWith, password: option.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!])
+            if errorCode == 0, let share = share {
+                option.idShare = share.idShare
+                self.updateShare(option: option)
+                NCManageDatabase.shared.addShare(urlBase: self.urlBase, account: self.metadata.account, shares: [share])
                 self.appDelegate.shares = NCManageDatabase.shared.getTableShares(account: self.metadata.account)
             } else {
                 NCContentPresenter.shared.messageNotification("_share_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.errorInternalError)
@@ -102,8 +106,8 @@ class NCShareNetworking: NSObject {
         NCUtility.shared.startActivityIndicator(backgroundView: view, blurEffect: false)
         NCCommunication.shared.updateShare(idShare: option.idShare, password: option.password, expireDate: option.expDateString, permissions: option.permissions, note: option.note, label: option.label, hideDownload: option.hideDownload) { 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!])
+            if errorCode == 0, let share = share {
+                NCManageDatabase.shared.addShare(urlBase: self.urlBase, account: self.metadata.account, shares: [share])
                 self.appDelegate.shares = NCManageDatabase.shared.getTableShares(account: self.metadata.account)
                 self.delegate?.readShareCompleted()
             } else {