Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix share email, not asked for password #1804

Merged
merged 1 commit into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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