From 70ab717c0d27370d1301d6192078f52b11b34840 Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Mon, 1 Sep 2025 17:31:29 +0200 Subject: [PATCH 1/3] Add more checks Signed-off-by: Milen Pivchev --- iOSClient/Share/NCShareNetworking.swift | 36 ++++++++++++++----------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/iOSClient/Share/NCShareNetworking.swift b/iOSClient/Share/NCShareNetworking.swift index 5315160e08..e91799eba9 100644 --- a/iOSClient/Share/NCShareNetworking.swift +++ b/iOSClient/Share/NCShareNetworking.swift @@ -114,7 +114,7 @@ class NCShareNetworking: NSObject { } } - func createShare(_ template: Shareable, downloadLimit: DownloadLimitViewModel) { + func createShare(_ shareable: Shareable, downloadLimit: DownloadLimitViewModel) { // NOTE: Permissions don't work for creating with file drop! // https://github.com/nextcloud/server/issues/17504 @@ -123,14 +123,14 @@ class NCShareNetworking: NSObject { let capabilities = NCNetworking.shared.capabilities[self.metadata.account] ?? NKCapabilities.Capabilities() NextcloudKit.shared.createShare(path: filenamePath, - shareType: template.shareType, - shareWith: template.shareWith, + shareType: shareable.shareType, + shareWith: shareable.shareWith, publicUpload: false, - note: template.note, + note: shareable.note, hideDownload: false, - password: template.password, - permissions: template.permissions, - attributes: template.attributes, + password: shareable.password, + permissions: shareable.permissions, + attributes: shareable.attributes, account: metadata.account) { task in Task { let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: self.metadata.account, @@ -142,16 +142,18 @@ class NCShareNetworking: NSObject { NCActivityIndicator.shared.stop() if error == .success, let share = share { - template.idShare = share.idShare + shareable.idShare = share.idShare let home = self.utilityFileSystem.getHomeServer(session: self.session) self.database.addShare(account: self.metadata.account, home: home, shares: [share]) - if template.hasChanges(comparedTo: share) { - self.updateShare(template, downloadLimit: downloadLimit) + if shareable.hasChanges(comparedTo: share) { + self.updateShare(shareable, downloadLimit: downloadLimit) // Download limit update should happen implicitly on share update. } else { if case let .limited(limit, _) = downloadLimit, - capabilities.fileSharingDownloadLimit { + capabilities.fileSharingDownloadLimit, + shareable.shareType == NCShareCommon.shareTypeLink, + shareable.itemType == NCShareCommon.itemTypeFile { self.setShareDownloadLimit(limit, token: share.token) } } @@ -196,12 +198,12 @@ class NCShareNetworking: NSObject { } } - func updateShare(_ option: Shareable, downloadLimit: DownloadLimitViewModel) { + func updateShare(_ shareable: Shareable, downloadLimit: DownloadLimitViewModel) { NCActivityIndicator.shared.start(backgroundView: view) - NextcloudKit.shared.updateShare(idShare: option.idShare, password: option.password, expireDate: option.formattedDateString, permissions: option.permissions, note: option.note, label: option.label, hideDownload: option.hideDownload, attributes: option.attributes, account: metadata.account) { task in + NextcloudKit.shared.updateShare(idShare: shareable.idShare, password: shareable.password, expireDate: shareable.formattedDateString, permissions: shareable.permissions, note: shareable.note, label: shareable.label, hideDownload: shareable.hideDownload, attributes: shareable.attributes, account: metadata.account) { task in Task { let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: self.metadata.account, - path: "_\(option.idShare)", + path: "_\(shareable.idShare)", name: "updateShare") await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task) } @@ -215,7 +217,9 @@ class NCShareNetworking: NSObject { self.database.addShare(account: self.metadata.account, home: home, shares: [share]) self.delegate?.readShareCompleted() - if capabilities.fileSharingDownloadLimit { + if capabilities.fileSharingDownloadLimit, + shareable.shareType == NCShareCommon.shareTypeLink, + shareable.itemType == NCShareCommon.itemTypeFile { if case let .limited(limit, _) = downloadLimit { self.setShareDownloadLimit(limit, token: share.token) } else { @@ -230,7 +234,7 @@ class NCShareNetworking: NSObject { } } else { NCContentPresenter().showError(error: error) - self.delegate?.updateShareWithError(idShare: option.idShare) + self.delegate?.updateShareWithError(idShare: shareable.idShare) } } } From cf4309bb3be96c0e0bc80f896b5e42cf0c35d4fa Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Mon, 1 Sep 2025 17:33:08 +0200 Subject: [PATCH 2/3] Refactor Signed-off-by: Milen Pivchev --- iOSClient/Share/NCShareNetworking.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/iOSClient/Share/NCShareNetworking.swift b/iOSClient/Share/NCShareNetworking.swift index e91799eba9..1fe339f505 100644 --- a/iOSClient/Share/NCShareNetworking.swift +++ b/iOSClient/Share/NCShareNetworking.swift @@ -115,9 +115,6 @@ class NCShareNetworking: NSObject { } func createShare(_ shareable: Shareable, downloadLimit: DownloadLimitViewModel) { - // NOTE: Permissions don't work for creating with file drop! - // https://github.com/nextcloud/server/issues/17504 - NCActivityIndicator.shared.start(backgroundView: view) let filenamePath = utilityFileSystem.getFileNamePath(metadata.fileName, serverUrl: metadata.serverUrl, session: session) let capabilities = NCNetworking.shared.capabilities[self.metadata.account] ?? NKCapabilities.Capabilities() From 7478e79ca37e324bf3fdb06c3df87b81dbc099e7 Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Mon, 1 Sep 2025 17:38:10 +0200 Subject: [PATCH 3/3] Prevent sending empty token + fix min date Signed-off-by: Milen Pivchev --- iOSClient/Share/Advanced/NCShareDateCell.swift | 2 +- iOSClient/Share/NCShareNetworking.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iOSClient/Share/Advanced/NCShareDateCell.swift b/iOSClient/Share/Advanced/NCShareDateCell.swift index 7d4e8c18c2..4af43ab227 100644 --- a/iOSClient/Share/Advanced/NCShareDateCell.swift +++ b/iOSClient/Share/Advanced/NCShareDateCell.swift @@ -18,7 +18,7 @@ class NCShareDateCell: UITableViewCell { super.init(style: .value1, reuseIdentifier: "shareExpDate") picker.datePickerMode = .date - picker.minimumDate = Date() + picker.minimumDate = Calendar.current.date(byAdding: .day, value: 1, to: Date()) picker.preferredDatePickerStyle = .wheels picker.action(for: .valueChanged) { datePicker in guard let datePicker = datePicker as? UIDatePicker else { return } diff --git a/iOSClient/Share/NCShareNetworking.swift b/iOSClient/Share/NCShareNetworking.swift index 08480b5e23..1fe339f505 100644 --- a/iOSClient/Share/NCShareNetworking.swift +++ b/iOSClient/Share/NCShareNetworking.swift @@ -265,7 +265,7 @@ class NCShareNetworking: NSObject { func removeShareDownloadLimit(token: String) { let capabilities = NCNetworking.shared.capabilities[self.metadata.account] ?? NKCapabilities.Capabilities() - if !capabilities.fileSharingDownloadLimit { + if !capabilities.fileSharingDownloadLimit || token.isEmpty { return } @@ -290,7 +290,7 @@ class NCShareNetworking: NSObject { func setShareDownloadLimit(_ limit: Int, token: String) { let capabilities = NCNetworking.shared.capabilities[self.metadata.account] ?? NKCapabilities.Capabilities() - if !capabilities.fileSharingDownloadLimit { + if !capabilities.fileSharingDownloadLimit || token.isEmpty { return }