Skip to content

Commit

Permalink
Merge pull request #1804 from nextcloud/fix/share-email-password
Browse files Browse the repository at this point in the history
Fix share email, not asked for password
  • Loading branch information
Marino Faggiana authored Dec 10, 2021
2 parents ff55725 + 664a833 commit f05cdc6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
51 changes: 30 additions & 21 deletions iOSClient/Share/NCShare.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Expand Down
4 changes: 2 additions & 2 deletions iOSClient/Share/NCShareNetworking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ 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"])
if permission <= 0 {
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!])
Expand Down

0 comments on commit f05cdc6

Please sign in to comment.