Browse Source

Implement share permission discard changes only when changed

- keep copy of old state, check if there have been changes when canceling
- Note: Doesn't work for readonly link shares: https://github.com/nextcloud/server/blame/f99876997a9119518fe5f7ad3a3a51d33459d4cc/apps/files_sharing/lib/Controller/ShareAPIController.php#L1104-L1107

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 years ago
parent
commit
9e626f2311

+ 1 - 0
iOSClient/Menu/NCShare+Menu.swift

@@ -50,6 +50,7 @@ extension NCShare {
                         let navigationController = self.navigationController, !share.isInvalidated else { return }
                     advancePermission.networking = self.networking
                     advancePermission.share = tableShare(value: share)
+                    advancePermission.oldTableShare = tableShare(value: share)
                     advancePermission.metadata = self.metadata
                     navigationController.pushViewController(advancePermission, animated: true)
                 }

+ 5 - 0
iOSClient/Share/Advanced/NCShareAdvancePermission.swift

@@ -29,6 +29,10 @@ import CloudKit
 class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDelegate, NCShareDetail {
     func dismissShareAdvanceView(shouldSave: Bool) {
         guard shouldSave else {
+            guard oldTableShare?.hasChanges(comparedTo: share) != false else {
+                navigationController?.popViewController(animated: true)
+                return
+            }
             let alert = UIAlertController(
                 title: NSLocalizedString("_cancel_request_", comment: ""),
                 message: NSLocalizedString("_discard_changes_info_", comment: ""),
@@ -49,6 +53,7 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg
         navigationController?.popViewController(animated: true)
     }
 
+    var oldTableShare: tableShare?
     var share: NCTableShareable!
     var isNewShare: Bool { NCManageDatabase.shared.getTableShare(account: share.account, idShare: share.idShare) == nil }
     var metadata: tableMetadata!

+ 11 - 0
iOSClient/Share/NCShare+Helper.swift

@@ -49,6 +49,17 @@ extension NCTableShareable {
         dateFormatter.dateFormat = "YYYY-MM-dd HH:mm:ss"
         return dateFormatter.string(from: date as Date)
     }
+
+    func hasChanges(comparedTo other: NCTableShareable) -> Bool {
+        return other.account != account
+        || other.shareType != shareType
+        || other.permissions != permissions
+        || other.hideDownload != hideDownload
+        || other.password != password
+        || other.label != label
+        || other.note != note
+        || other.expirationDate != expirationDate
+    }
 }
 
 class NCTableShareOptions: NCTableShareable {