From 28a14103ad29b5c3b53232d8c5ed51e68a4bcb4d Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Tue, 20 Jun 2023 20:00:25 +0200 Subject: [PATCH 1/5] Add attributes to realm Signed-off-by: Milen Pivchev --- Nextcloud.xcodeproj/project.pbxproj | 6 ++- .../Data/NCManageDatabase+Metadata.swift | 2 + iOSClient/Data/NCManageDatabase+Share.swift | 53 ++++++++++++++++++- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index e78858cd83..b96026cc4a 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -3976,6 +3976,7 @@ DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + ENABLE_TESTING_SEARCH_PATHS = YES; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -4039,6 +4040,7 @@ DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + ENABLE_TESTING_SEARCH_PATHS = YES; GCC_NO_COMMON_BLOCKS = YES; GCC_PREPROCESSOR_DEFINITIONS = ( "$(inherited)", @@ -4289,8 +4291,8 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/nextcloud/NextcloudKit"; requirement = { - kind = exactVersion; - version = 2.6.0; + branch = "2425-missing-sharing-options"; + kind = branch; }; }; F788ECC5263AAAF900ADC67F /* XCRemoteSwiftPackageReference "MarkdownKit" */ = { diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index 7c48c8665c..5ed4a10c69 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -333,6 +333,8 @@ extension NCManageDatabase { } } +// metadata.attributes = file.attributes + return metadata } diff --git a/iOSClient/Data/NCManageDatabase+Share.swift b/iOSClient/Data/NCManageDatabase+Share.swift index 3558887258..7e4adc4f00 100644 --- a/iOSClient/Data/NCManageDatabase+Share.swift +++ b/iOSClient/Data/NCManageDatabase+Share.swift @@ -25,8 +25,8 @@ import Foundation import RealmSwift import NextcloudKit -typealias tableShare = tableShareV2 -class tableShareV2: Object { +typealias tableShare = tableShareV3 +class tableShareV3: Object { @objc dynamic var account = "" @objc dynamic var canEdit: Bool = false @@ -67,12 +67,57 @@ class tableShareV2: Object { @objc dynamic var userIcon = "" @objc dynamic var userMessage = "" @objc dynamic var userStatus = "" +// @objc dynamic var attributes = "" + let attributes = List() + +// let attributes = List() override static func primaryKey() -> String { return "primaryKey" } } +class ShareAttribute: Object { + @objc dynamic var scope: String = "" + @objc dynamic var key: String = "" + @objc dynamic var enabled: Bool = false + + convenience init(scope: String, key: String, enabled: Bool) { + self.init() + + self.scope = scope + self.key = key + self.enabled = enabled + } +} + +// convenience init(account: String, group: String, permission: Int) { +// self.init() +// +// self.account = account +// self.group = group +// self.permission = permission +// } + +//extension NKShare.Attribute : RealmCollectionValue { +// +// public static func _rlmDefaultValue() -> Self { +// <#code#> +// } +// +// public typealias PersistedType = <#type#> +// +// public static func _rlmFromObjc(_ value: Any, insideOptional: Bool) -> Self? { +// <#code#> +// } +// +// public var _rlmObjcValue: Any { +// <#code#> +// } +// +// +//} + extension NCManageDatabase { func addShare(account: String, home: String, shares: [NKShare]) { @@ -134,6 +179,10 @@ extension NCManageDatabase { object.userMessage = share.userMessage object.userStatus = share.userStatus + for element in share.attributes { + object.attributes.append(ShareAttribute(scope: element.scope, key: element.key, enabled: element.enabled)) + } + realm.add(object, update: .all) } } From 1571e4777784809327a4f2c3cf4718b653daa09a Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Wed, 21 Jun 2023 12:06:03 +0200 Subject: [PATCH 2/5] WIP Signed-off-by: Milen Pivchev --- iOSClient/Data/NCManageDatabase+Share.swift | 22 ++++++++-- .../Advanced/NCShareAdvancePermission.swift | 6 ++- iOSClient/Share/Advanced/NCShareCells.swift | 42 ++++++++++++++++++- iOSClient/Share/NCShare+Helper.swift | 4 ++ 4 files changed, 67 insertions(+), 7 deletions(-) diff --git a/iOSClient/Data/NCManageDatabase+Share.swift b/iOSClient/Data/NCManageDatabase+Share.swift index 7e4adc4f00..199877a947 100644 --- a/iOSClient/Data/NCManageDatabase+Share.swift +++ b/iOSClient/Data/NCManageDatabase+Share.swift @@ -68,9 +68,15 @@ class tableShareV3: Object { @objc dynamic var userMessage = "" @objc dynamic var userStatus = "" // @objc dynamic var attributes = "" - let attributes = List() + @objc dynamic var allowDownload = false -// let attributes = List() + // arrays dont work in realm, and we need to change this to List or one of these: https://www.mongodb.com/docs/realm-sdks/swift/latest/Classes/Object.html +// @objc dynamic var attributes = [NKShare.Attribute]() + let attributesInternal = List() + + var attributes: [ShareAttribute] { + return ShareAttribute.toArray(attributes: attributesInternal) + } override static func primaryKey() -> String { return "primaryKey" @@ -89,6 +95,14 @@ class ShareAttribute: Object { self.key = key self.enabled = enabled } + + static func toAttributeArray(attributes: List) -> [NKShare.Attribute] { + var array = [NKShare.Attribute]() + attributes.forEach { + array.append(NKShare.Attribute(from: <#T##Decoder#>) + } + return array + } } // convenience init(account: String, group: String, permission: Int) { @@ -178,9 +192,11 @@ extension NCManageDatabase { object.userIcon = share.userIcon object.userMessage = share.userMessage object.userStatus = share.userStatus +// object.allowDownload = share.attributes.first(where: { $0.scope == "permissions" && $0.key == "download"})?.enabled for element in share.attributes { - object.attributes.append(ShareAttribute(scope: element.scope, key: element.key, enabled: element.enabled)) +// object.attributes.append(element) + object.attributesInternal.append(ShareAttribute(scope: element.scope, key: element.key, enabled: element.enabled)) } realm.add(object, update: .all) diff --git a/iOSClient/Share/Advanced/NCShareAdvancePermission.swift b/iOSClient/Share/Advanced/NCShareAdvancePermission.swift index 607252d223..e149a72613 100644 --- a/iOSClient/Share/Advanced/NCShareAdvancePermission.swift +++ b/iOSClient/Share/Advanced/NCShareAdvancePermission.swift @@ -62,13 +62,13 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg override func viewDidLoad() { super.viewDidLoad() - self.shareConfig = NCShareConfig(parentMetadata: metadata, share: share) + self.shareConfig = NCShareConfig(parentMetadata: metadata, share: share, attributes: ShareAttribute.toArray(attributes: oldTableShare!.attributes) ?? []) tableView.estimatedRowHeight = tableView.rowHeight tableView.rowHeight = UITableView.automaticDimension self.setNavigationTitle() self.navigationItem.hidesBackButton = true - // disbale pull to dimiss + // disbale pull to dismiss isModalInPresentation = true } @@ -124,6 +124,8 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg let maxPermission = metadata.directory ? NCGlobal.shared.permissionMaxFolderShare : NCGlobal.shared.permissionMaxFileShare return shareConfig.resharePermission != maxPermission ? shareConfig.permissions.count + 1 : shareConfig.permissions.count } else if section == 1 { + return shareConfig.attributes.count + } else if section == 2 { return shareConfig.advanced.count } else { return 0 } } diff --git a/iOSClient/Share/Advanced/NCShareCells.swift b/iOSClient/Share/Advanced/NCShareCells.swift index dd6f7d4767..cd6d12dd30 100644 --- a/iOSClient/Share/Advanced/NCShareCells.swift +++ b/iOSClient/Share/Advanced/NCShareCells.swift @@ -22,6 +22,7 @@ // import UIKit +import NextcloudKit protocol NCShareCellConfig { var title: String { get } @@ -44,6 +45,13 @@ extension NCToggleCellConfig { } } +//protocol NCAttribute: NCToggleCellConfig { +// static var forDirectory: [Self] { get } +// static var forDirectoryE2EE: [Self] { get } +// static var forFile: [Self] { get } +// func hasAttribute(for parentAttribute: Int) -> Bool +//} + protocol NCPermission: NCToggleCellConfig { static var forDirectory: [Self] { get } static var forDirectoryE2EE: [Self] { get } @@ -207,18 +215,46 @@ enum NCShareDetails: CaseIterable, NCShareCellConfig { static let forUser: [NCShareDetails] = [.expirationDate, .note] } +enum NCShareAttributes: NCToggleCellConfig { + func isOn(for share: NCTableShareable) -> Bool { + <#code#> + } + + func didChange(_ share: NCTableShareable, to newValue: Bool) { + <#code#> + } + + var title: String { + switch self { + + } + } + +// func getCell(for share: NCTableShareable) -> UITableViewCell { +// <#code#> +// } +// +// func didSelect(for share: NCTableShareable) { +// <#code#> +// } + + case permissionDownload +} + struct NCShareConfig { let permissions: [NCPermission] let advanced: [NCShareDetails] let share: NCTableShareable let resharePermission: Int + let attributes: [ShareAttribute] - init(parentMetadata: tableMetadata, share: NCTableShareable) { + init(parentMetadata: tableMetadata, share: NCTableShareable, attributes: [ShareAttribute]) { self.share = share self.resharePermission = parentMetadata.sharePermissionsCollaborationServices let type: NCPermission.Type = share.shareType == NCShareCommon.shared.SHARE_TYPE_LINK ? NCLinkPermission.self : NCUserPermission.self self.permissions = parentMetadata.directory ? (parentMetadata.e2eEncrypted ? type.forDirectoryE2EE : type.forDirectory) : type.forFile self.advanced = share.shareType == NCShareCommon.shared.SHARE_TYPE_LINK ? NCShareDetails.forLink : NCShareDetails.forUser + self.attributes = attributes } func cellFor(indexPath: IndexPath) -> UITableViewCell? { @@ -240,7 +276,9 @@ struct NCShareConfig { func config(for indexPath: IndexPath) -> NCShareCellConfig? { if indexPath.section == 0, indexPath.row < permissions.count { return permissions[indexPath.row] - } else if indexPath.section == 1, indexPath.row < advanced.count { + } else if indexPath.section == 1 { + return attributes[indexPath.row] + } else if indexPath.section == 2, indexPath.row < advanced.count { return advanced[indexPath.row] } else { return nil } } diff --git a/iOSClient/Share/NCShare+Helper.swift b/iOSClient/Share/NCShare+Helper.swift index 8f1abdd80b..dbd2a12209 100644 --- a/iOSClient/Share/NCShare+Helper.swift +++ b/iOSClient/Share/NCShare+Helper.swift @@ -23,6 +23,7 @@ import UIKit import NextcloudKit +import Foundation extension tableShare: NCTableShareable { } extension NKShare: NCTableShareable { } @@ -40,6 +41,8 @@ protocol NCTableShareable: AnyObject { var note: String { get set } var expirationDate: NSDate? { get set } var shareWithDisplayname: String { get set } +// var allowDownload: Bool { get set } + var attributes: [NKShare.Attribute] { get set } } extension NCTableShareable { @@ -74,6 +77,7 @@ class NCTableShareOptions: NCTableShareable { var note: String = "" var expirationDate: NSDate? var shareWithDisplayname: String = "" +// var attributes = [NKShare.Attribute]() private init(shareType: Int, metadata: tableMetadata, password: String?) { if metadata.e2eEncrypted { From c0f443d99b299670e18ef84e1d05f5ec599154a3 Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Thu, 22 Jun 2023 20:07:00 +0200 Subject: [PATCH 3/5] WIP Signed-off-by: Milen Pivchev --- .../Data/NCManageDatabase+Metadata.swift | 2 - iOSClient/Data/NCManageDatabase+Share.swift | 22 ++-- .../Advanced/NCShareAdvancePermission.swift | 4 +- iOSClient/Share/Advanced/NCShareCells.swift | 62 ++++++----- iOSClient/Share/NCShare+Helper.swift | 2 +- .../en.lproj/Localizable.strings | 102 +++++++++--------- 6 files changed, 100 insertions(+), 94 deletions(-) diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index 5ed4a10c69..7c48c8665c 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -333,8 +333,6 @@ extension NCManageDatabase { } } -// metadata.attributes = file.attributes - return metadata } diff --git a/iOSClient/Data/NCManageDatabase+Share.swift b/iOSClient/Data/NCManageDatabase+Share.swift index 199877a947..367eec9865 100644 --- a/iOSClient/Data/NCManageDatabase+Share.swift +++ b/iOSClient/Data/NCManageDatabase+Share.swift @@ -68,15 +68,13 @@ class tableShareV3: Object { @objc dynamic var userMessage = "" @objc dynamic var userStatus = "" // @objc dynamic var attributes = "" - @objc dynamic var allowDownload = false +// @objc dynamic var allowDownload = false // arrays dont work in realm, and we need to change this to List or one of these: https://www.mongodb.com/docs/realm-sdks/swift/latest/Classes/Object.html // @objc dynamic var attributes = [NKShare.Attribute]() let attributesInternal = List() - var attributes: [ShareAttribute] { - return ShareAttribute.toArray(attributes: attributesInternal) - } + var attributes = [NKShare.Attribute]() override static func primaryKey() -> String { return "primaryKey" @@ -96,13 +94,13 @@ class ShareAttribute: Object { self.enabled = enabled } - static func toAttributeArray(attributes: List) -> [NKShare.Attribute] { - var array = [NKShare.Attribute]() - attributes.forEach { - array.append(NKShare.Attribute(from: <#T##Decoder#>) - } - return array - } +// static func toAttributeArray(attributes: List) -> [NKShare.Attribute] { +// var array = [NKShare.Attribute]() +// attributes.forEach { attribute in +// array.append(NKShare.Attribute(scope: attribute.scope)) +// } +// return array +// } } // convenience init(account: String, group: String, permission: Int) { @@ -197,6 +195,8 @@ extension NCManageDatabase { for element in share.attributes { // object.attributes.append(element) object.attributesInternal.append(ShareAttribute(scope: element.scope, key: element.key, enabled: element.enabled)) + + object.attributes.append(element) } realm.add(object, update: .all) diff --git a/iOSClient/Share/Advanced/NCShareAdvancePermission.swift b/iOSClient/Share/Advanced/NCShareAdvancePermission.swift index e149a72613..ca762e8a2e 100644 --- a/iOSClient/Share/Advanced/NCShareAdvancePermission.swift +++ b/iOSClient/Share/Advanced/NCShareAdvancePermission.swift @@ -62,7 +62,7 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg override func viewDidLoad() { super.viewDidLoad() - self.shareConfig = NCShareConfig(parentMetadata: metadata, share: share, attributes: ShareAttribute.toArray(attributes: oldTableShare!.attributes) ?? []) + self.shareConfig = NCShareConfig(parentMetadata: metadata, share: share) tableView.estimatedRowHeight = tableView.rowHeight tableView.rowHeight = UITableView.automaticDimension @@ -110,6 +110,8 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg if section == 0 { return NSLocalizedString("_permissions_", comment: "") } else if section == 1 { + return NSLocalizedString("_attributes_", comment: "") + } else if section == 2 { return NSLocalizedString("_advanced_", comment: "") } else { return nil } } diff --git a/iOSClient/Share/Advanced/NCShareCells.swift b/iOSClient/Share/Advanced/NCShareCells.swift index cd6d12dd30..d2a7b85950 100644 --- a/iOSClient/Share/Advanced/NCShareCells.swift +++ b/iOSClient/Share/Advanced/NCShareCells.swift @@ -170,6 +170,36 @@ enum NCLinkPermission: NCPermission { static let forDirectoryE2EE: [NCLinkPermission] = [.secureFileDrop] } +enum NCShareAttribute: NCToggleCellConfig { + func isOn(for share: NCTableShareable) -> Bool { + print(share.attributes.first(where: { $0.scope == "permission" && $0.key == "download" })?.enabled == true) + switch self { + case.allowDownload: return share.attributes.first(where: { $0.scope == "permission" && $0.key == "download" })?.enabled == true + } + } + + func didChange(_ share: NCTableShareable, to newValue: Bool) { + // TODO: implement + } + + var title: String { + switch self { + case .allowDownload: return NSLocalizedString("_share_attribute_allow_download_", comment: "") + } + } + +// func getCell(for share: NCTableShareable) -> UITableViewCell { +// <#code#> +// } +// +// func didSelect(for share: NCTableShareable) { +// <#code#> +// } + + case allowDownload + static let forAll: [NCShareAttribute] = [.allowDownload] +} + enum NCShareDetails: CaseIterable, NCShareCellConfig { func didSelect(for share: NCTableShareable) { switch self { @@ -215,46 +245,20 @@ enum NCShareDetails: CaseIterable, NCShareCellConfig { static let forUser: [NCShareDetails] = [.expirationDate, .note] } -enum NCShareAttributes: NCToggleCellConfig { - func isOn(for share: NCTableShareable) -> Bool { - <#code#> - } - - func didChange(_ share: NCTableShareable, to newValue: Bool) { - <#code#> - } - - var title: String { - switch self { - - } - } - -// func getCell(for share: NCTableShareable) -> UITableViewCell { -// <#code#> -// } -// -// func didSelect(for share: NCTableShareable) { -// <#code#> -// } - - case permissionDownload -} - struct NCShareConfig { let permissions: [NCPermission] let advanced: [NCShareDetails] let share: NCTableShareable let resharePermission: Int - let attributes: [ShareAttribute] + let attributes: [NCShareAttribute] - init(parentMetadata: tableMetadata, share: NCTableShareable, attributes: [ShareAttribute]) { + init(parentMetadata: tableMetadata, share: NCTableShareable) { self.share = share self.resharePermission = parentMetadata.sharePermissionsCollaborationServices let type: NCPermission.Type = share.shareType == NCShareCommon.shared.SHARE_TYPE_LINK ? NCLinkPermission.self : NCUserPermission.self self.permissions = parentMetadata.directory ? (parentMetadata.e2eEncrypted ? type.forDirectoryE2EE : type.forDirectory) : type.forFile self.advanced = share.shareType == NCShareCommon.shared.SHARE_TYPE_LINK ? NCShareDetails.forLink : NCShareDetails.forUser - self.attributes = attributes + self.attributes = NCShareAttribute.forAll } func cellFor(indexPath: IndexPath) -> UITableViewCell? { diff --git a/iOSClient/Share/NCShare+Helper.swift b/iOSClient/Share/NCShare+Helper.swift index dbd2a12209..d841bdbd4d 100644 --- a/iOSClient/Share/NCShare+Helper.swift +++ b/iOSClient/Share/NCShare+Helper.swift @@ -77,7 +77,7 @@ class NCTableShareOptions: NCTableShareable { var note: String = "" var expirationDate: NSDate? var shareWithDisplayname: String = "" -// var attributes = [NKShare.Attribute]() + var attributes = [NKShare.Attribute]() private init(shareType: Int, metadata: tableMetadata, password: String?) { if metadata.e2eEncrypted { diff --git a/iOSClient/Supporting Files/en.lproj/Localizable.strings b/iOSClient/Supporting Files/en.lproj/Localizable.strings index bb40043984..62cce7ccae 100644 --- a/iOSClient/Supporting Files/en.lproj/Localizable.strings +++ b/iOSClient/Supporting Files/en.lproj/Localizable.strings @@ -602,57 +602,59 @@ // MARK: Share -"_share_link_" = "Share link"; -"_share_link_button_" = "Send link to …"; -"_share_link_name_" = "Link name"; -"_password_" = "Password"; -"_share_password_" = "Password protected link"; -"_share_expirationdate_" = "Set expiration date for link"; -"_date_" = "Date"; -"_share_title_" = "Share"; -"_add_sharee_" = "Add users or groups"; -"_add_sharee_footer_" = "You can share this resource by adding users or groups. To remove a share, remove all users and groups"; -"_find_sharee_title_" = "Search"; -"_find_sharee_" = "Search for user or group …"; -"_find_sharee_footer_" = "Enter part of the name of the user or group to search for (at least 2 characters) followed by \"Return\", select the users that should be allowed to access the share followed by \"Done\" to confirm"; -"_user_is_group_" = "(Group)"; -"_direct_sharee_title_" = "Share"; -"_direct_sharee_footer_" = "If you already know the name, enter it, then select the share type and press \"Done\" to confirm"; -"_direct_sharee_" = "Enter the username …"; -"_user_sharee_footer_" = "Tap to change permissions"; -"_share_type_title_" = "Type of share"; -"_share_type_user_" = "User"; -"_share_type_group_" = "Group"; -"_share_type_remote_" = "Remote"; -"_enforce_password_protection_" = "Enforce password protection"; -"_password_obligatory_" = "Enforce password protection enabled, password obligatory"; -"_shared_with_you_by_" = "Shared with you by"; -"_shareLinksearch_placeholder_" = "Type a name and press Search"; +"_share_link_" = "Share link"; +"_share_link_button_" = "Send link to …"; +"_share_link_name_" = "Link name"; +"_password_" = "Password"; +"_share_password_" = "Password protected link"; +"_share_expirationdate_" = "Set expiration date for link"; +"_date_" = "Date"; +"_share_title_" = "Share"; +"_add_sharee_" = "Add users or groups"; +"_add_sharee_footer_" = "You can share this resource by adding users or groups. To remove a share, remove all users and groups"; +"_find_sharee_title_" = "Search"; +"_find_sharee_" = "Search for user or group …"; +"_find_sharee_footer_" = "Enter part of the name of the user or group to search for (at least 2 characters) followed by \"Return\", select the users that should be allowed to access the share followed by \"Done\" to confirm"; +"_user_is_group_" = "(Group)"; +"_direct_sharee_title_" = "Share"; +"_direct_sharee_footer_" = "If you already know the name, enter it, then select the share type and press \"Done\" to confirm"; +"_direct_sharee_" = "Enter the username …"; +"_user_sharee_footer_" = "Tap to change permissions"; +"_share_type_title_" = "Type of share"; +"_share_type_user_" = "User"; +"_share_type_group_" = "Group"; +"_share_type_remote_" = "Remote"; +"_enforce_password_protection_" = "Enforce password protection"; +"_password_obligatory_" = "Enforce password protection enabled, password obligatory"; +"_shared_with_you_by_" = "Shared with you by"; +"_shareLinksearch_placeholder_" = "Type a name and press Search"; "_shareLinksearch_mail_placeholder_" = "Type a name or an email and press Search"; -"_new_comment_" = "New comment …"; -"_edit_comment_" = "Edit comment"; -"_delete_comment_" = "Delete comment"; -"_share_allow_editing_" = "Allow editing"; -"_share_read_only_" = "View only"; -"_share_editing_" = "Editing"; -"_share_allow_upload_" = "Allow upload and editing"; -"_share_file_drop_" = "File drop (upload only)"; -"_share_secure_file_drop_" = "Secure file drop (upload only)"; -"_share_hide_download_" = "Hide download"; -"_share_password_protect_" = "Password protect"; -"_share_expiration_date_" = "Set expiration date"; -"_share_note_recipient_" = "Note to recipient"; -"_share_delete_sharelink_" = "Delete link"; -"_share_add_sharelink_" = "Add another link"; -"_share_can_reshare_" = "Allow resharing"; -"_share_can_create_" = "Allow creating"; -"_share_can_change_" = "Allow editing"; -"_share_can_delete_" = "Allow deleting"; -"_share_unshare_" = "Unshare"; -"_share_internal_link_" = "Internal link"; -"_share_internal_link_des_" = "Only works for users with access to this folder"; -"_share_reshare_disabled_" = "You are not allowed to reshare this file/folder"; -"_share_reshare_restricted_" = "Note: You only have limited permission to reshare this file/folder"; +"_new_comment_" = "New comment …"; +"_edit_comment_" = "Edit comment"; +"_delete_comment_" = "Delete comment"; +"_share_allow_editing_" = "Allow editing"; +"_share_read_only_" = "View only"; +"_share_editing_" = "Editing"; +"_share_allow_upload_" = "Allow upload and editing"; +"_share_file_drop_" = "File drop (upload only)"; +"_share_secure_file_drop_" = "Secure file drop (upload only)"; +"_share_hide_download_" = "Hide download"; +"_share_password_protect_" = "Password protect"; +"_share_expiration_date_" = "Set expiration date"; +"_share_note_recipient_" = "Note to recipient"; +"_share_delete_sharelink_" = "Delete link"; +"_share_add_sharelink_" = "Add another link"; +"_share_can_reshare_" = "Allow resharing"; +"_share_can_create_" = "Allow creating"; +"_share_can_change_" = "Allow editing"; +"_share_can_delete_" = "Allow deleting"; +"_share_unshare_" = "Unshare"; +"_share_internal_link_" = "Internal link"; +"_share_internal_link_des_" = "Only works for users with access to this folder"; +"_share_reshare_disabled_" = "You are not allowed to reshare this file/folder"; +"_share_reshare_restricted_" = "Note: You only have limited permission to reshare this file/folder"; +"_attributes_" = "Share attributes"; +"_share_attribute_allow_download_" = "Allow download"; "_no_transfer_" = "No transfers yet"; "_no_transfer_sub_" = "Uploads and downloads from this device will show up here"; From c3e4f2b3f8326f44535792acd8d95a1f42ca578d Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Wed, 12 Jul 2023 16:36:39 +0200 Subject: [PATCH 4/5] WIP Signed-off-by: Milen Pivchev --- Brand/Database.swift | 2 +- iOSClient/Data/NCManageDatabase+Share.swift | 49 ++----------------- .../Advanced/NCShareAdvancePermission.swift | 3 +- iOSClient/Share/Advanced/NCShareCells.swift | 24 ++++----- iOSClient/Share/NCShare+Helper.swift | 5 +- 5 files changed, 22 insertions(+), 61 deletions(-) diff --git a/Brand/Database.swift b/Brand/Database.swift index 63d330a0a7..087112093c 100644 --- a/Brand/Database.swift +++ b/Brand/Database.swift @@ -26,4 +26,4 @@ import Foundation // Database Realm // let databaseName = "nextcloud.realm" -let databaseSchemaVersion: UInt64 = 299 +let databaseSchemaVersion: UInt64 = 300 diff --git a/iOSClient/Data/NCManageDatabase+Share.swift b/iOSClient/Data/NCManageDatabase+Share.swift index be947afde3..2fbe6f1044 100644 --- a/iOSClient/Data/NCManageDatabase+Share.swift +++ b/iOSClient/Data/NCManageDatabase+Share.swift @@ -72,64 +72,26 @@ class tableShareV3: Object { // arrays dont work in realm, and we need to change this to List or one of these: https://www.mongodb.com/docs/realm-sdks/swift/latest/Classes/Object.html // @objc dynamic var attributes = [NKShare.Attribute]() - let attributesInternal = List() - - var attributes = [NKShare.Attribute]() + let attributes = List() override static func primaryKey() -> String { return "primaryKey" } } -class ShareAttribute: Object { +class ShareAttribute: EmbeddedObject { @objc dynamic var scope: String = "" @objc dynamic var key: String = "" @objc dynamic var enabled: Bool = false convenience init(scope: String, key: String, enabled: Bool) { self.init() - self.scope = scope self.key = key self.enabled = enabled } - -// static func toAttributeArray(attributes: List) -> [NKShare.Attribute] { -// var array = [NKShare.Attribute]() -// attributes.forEach { attribute in -// array.append(NKShare.Attribute(scope: attribute.scope)) -// } -// return array -// } } -// convenience init(account: String, group: String, permission: Int) { -// self.init() -// -// self.account = account -// self.group = group -// self.permission = permission -// } - -//extension NKShare.Attribute : RealmCollectionValue { -// -// public static func _rlmDefaultValue() -> Self { -// <#code#> -// } -// -// public typealias PersistedType = <#type#> -// -// public static func _rlmFromObjc(_ value: Any, insideOptional: Bool) -> Self? { -// <#code#> -// } -// -// public var _rlmObjcValue: Any { -// <#code#> -// } -// -// -//} - extension NCManageDatabase { func addShare(account: String, home: String, shares: [NKShare]) { @@ -182,13 +144,10 @@ extension NCManageDatabase { object.userIcon = share.userIcon object.userMessage = share.userMessage object.userStatus = share.userStatus -// object.allowDownload = share.attributes.first(where: { $0.scope == "permissions" && $0.key == "download"})?.enabled for element in share.attributes { -// object.attributes.append(element) - object.attributesInternal.append(ShareAttribute(scope: element.scope, key: element.key, enabled: element.enabled)) - - object.attributes.append(element) + let attribute = ShareAttribute(scope: element.scope, key: element.key, enabled: element.enabled) + object.attributes.append(attribute) } realm.add(object, update: .all) diff --git a/iOSClient/Share/Advanced/NCShareAdvancePermission.swift b/iOSClient/Share/Advanced/NCShareAdvancePermission.swift index ca762e8a2e..f457d5fbbf 100644 --- a/iOSClient/Share/Advanced/NCShareAdvancePermission.swift +++ b/iOSClient/Share/Advanced/NCShareAdvancePermission.swift @@ -62,6 +62,7 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg override func viewDidLoad() { super.viewDidLoad() + self.shareConfig = NCShareConfig(parentMetadata: metadata, share: share) tableView.estimatedRowHeight = tableView.rowHeight @@ -117,7 +118,7 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg } override func numberOfSections(in tableView: UITableView) -> Int { - return 2 + return 3 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { diff --git a/iOSClient/Share/Advanced/NCShareCells.swift b/iOSClient/Share/Advanced/NCShareCells.swift index d2a7b85950..e52fecfa1f 100644 --- a/iOSClient/Share/Advanced/NCShareCells.swift +++ b/iOSClient/Share/Advanced/NCShareCells.swift @@ -23,6 +23,7 @@ import UIKit import NextcloudKit +import RealmSwift protocol NCShareCellConfig { var title: String { get } @@ -171,15 +172,24 @@ enum NCLinkPermission: NCPermission { } enum NCShareAttribute: NCToggleCellConfig { + private func getAttributes(share: NCTableShareable) -> List? { + return NCManageDatabase.shared.getTableShare(account: share.account, idShare: share.idShare)?.attributes + } + + private func getDownloadPermissionAttribute(share: NCTableShareable) -> ShareAttribute? { + return getAttributes(share: share)?.first(where: { $0.scope == "permissions" && $0.key == "download" }) + } + func isOn(for share: NCTableShareable) -> Bool { - print(share.attributes.first(where: { $0.scope == "permission" && $0.key == "download" })?.enabled == true) + let attributes = NCManageDatabase.shared.getTableShare(account: share.account, idShare: share.idShare)?.attributes + switch self { - case.allowDownload: return share.attributes.first(where: { $0.scope == "permission" && $0.key == "download" })?.enabled == true + case.allowDownload: return getDownloadPermissionAttribute(share: share)?.enabled ?? true // true by default } } func didChange(_ share: NCTableShareable, to newValue: Bool) { - // TODO: implement + getDownloadPermissionAttribute(share: share)?.enabled = newValue } var title: String { @@ -188,14 +198,6 @@ enum NCShareAttribute: NCToggleCellConfig { } } -// func getCell(for share: NCTableShareable) -> UITableViewCell { -// <#code#> -// } -// -// func didSelect(for share: NCTableShareable) { -// <#code#> -// } - case allowDownload static let forAll: [NCShareAttribute] = [.allowDownload] } diff --git a/iOSClient/Share/NCShare+Helper.swift b/iOSClient/Share/NCShare+Helper.swift index d841bdbd4d..c7f008850a 100644 --- a/iOSClient/Share/NCShare+Helper.swift +++ b/iOSClient/Share/NCShare+Helper.swift @@ -41,8 +41,7 @@ protocol NCTableShareable: AnyObject { var note: String { get set } var expirationDate: NSDate? { get set } var shareWithDisplayname: String { get set } -// var allowDownload: Bool { get set } - var attributes: [NKShare.Attribute] { get set } + var account: String { get set } } extension NCTableShareable { @@ -77,7 +76,7 @@ class NCTableShareOptions: NCTableShareable { var note: String = "" var expirationDate: NSDate? var shareWithDisplayname: String = "" - var attributes = [NKShare.Attribute]() + var account: String = "" private init(shareType: Int, metadata: tableMetadata, password: String?) { if metadata.e2eEncrypted { From 95da5923faca6f74e0cd138925aa263a3bf03300 Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Thu, 13 Jul 2023 10:39:32 +0200 Subject: [PATCH 5/5] WIP --- iOSClient/Data/NCManageDatabase+Share.swift | 6 +++++- iOSClient/Share/Advanced/NCShareCells.swift | 16 +++++++++------- iOSClient/Share/NCShare+Helper.swift | 5 ++++- iOSClient/Share/NCShareNetworking.swift | 6 +++--- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/iOSClient/Data/NCManageDatabase+Share.swift b/iOSClient/Data/NCManageDatabase+Share.swift index 2fbe6f1044..9a08a267b4 100644 --- a/iOSClient/Data/NCManageDatabase+Share.swift +++ b/iOSClient/Data/NCManageDatabase+Share.swift @@ -72,7 +72,7 @@ class tableShareV3: Object { // arrays dont work in realm, and we need to change this to List or one of these: https://www.mongodb.com/docs/realm-sdks/swift/latest/Classes/Object.html // @objc dynamic var attributes = [NKShare.Attribute]() - let attributes = List() + var attributes = List() override static func primaryKey() -> String { return "primaryKey" @@ -90,6 +90,10 @@ class ShareAttribute: EmbeddedObject { self.key = key self.enabled = enabled } + +// static func toArray(attributes: List) -> [NKShare.Attribute] { +//// return NKShare.Attribute +// } } extension NCManageDatabase { diff --git a/iOSClient/Share/Advanced/NCShareCells.swift b/iOSClient/Share/Advanced/NCShareCells.swift index e52fecfa1f..ac24cef25b 100644 --- a/iOSClient/Share/Advanced/NCShareCells.swift +++ b/iOSClient/Share/Advanced/NCShareCells.swift @@ -172,24 +172,26 @@ enum NCLinkPermission: NCPermission { } enum NCShareAttribute: NCToggleCellConfig { - private func getAttributes(share: NCTableShareable) -> List? { - return NCManageDatabase.shared.getTableShare(account: share.account, idShare: share.idShare)?.attributes - } - private func getDownloadPermissionAttribute(share: NCTableShareable) -> ShareAttribute? { - return getAttributes(share: share)?.first(where: { $0.scope == "permissions" && $0.key == "download" }) + return share.attributes.first(where: { $0.scope == "permissions" && $0.key == "download" }) } func isOn(for share: NCTableShareable) -> Bool { - let attributes = NCManageDatabase.shared.getTableShare(account: share.account, idShare: share.idShare)?.attributes +// let attributes = NCManageDatabase.shared.getTableShare(account: share.account, idShare: share.idShare)?.attributes + let attributes = share.attributes + print(attributes) switch self { case.allowDownload: return getDownloadPermissionAttribute(share: share)?.enabled ?? true // true by default } } func didChange(_ share: NCTableShareable, to newValue: Bool) { - getDownloadPermissionAttribute(share: share)?.enabled = newValue + switch self { + case.allowDownload: + let index = share.attributes.firstIndex(where: { $0.scope == "permissions" && $0.key == "download" })! + share.attributes[index] = ShareAttribute(scope: "permissions", key: "download", enabled: newValue) + } } var title: String { diff --git a/iOSClient/Share/NCShare+Helper.swift b/iOSClient/Share/NCShare+Helper.swift index c7f008850a..0c84eb8229 100644 --- a/iOSClient/Share/NCShare+Helper.swift +++ b/iOSClient/Share/NCShare+Helper.swift @@ -24,9 +24,10 @@ import UIKit import NextcloudKit import Foundation +import RealmSwift extension tableShare: NCTableShareable { } -extension NKShare: NCTableShareable { } +//extension NKShare: NCTableShareable { } protocol NCTableShareable: AnyObject { var shareType: Int { get set } @@ -42,6 +43,7 @@ protocol NCTableShareable: AnyObject { var expirationDate: NSDate? { get set } var shareWithDisplayname: String { get set } var account: String { get set } + var attributes: List { get set } } extension NCTableShareable { @@ -77,6 +79,7 @@ class NCTableShareOptions: NCTableShareable { var expirationDate: NSDate? var shareWithDisplayname: String = "" var account: String = "" + var attributes = List() private init(shareType: Int, metadata: tableMetadata, password: String?) { if metadata.e2eEncrypted { diff --git a/iOSClient/Share/NCShareNetworking.swift b/iOSClient/Share/NCShareNetworking.swift index bcabbf73ae..faf41c479f 100644 --- a/iOSClient/Share/NCShareNetworking.swift +++ b/iOSClient/Share/NCShareNetworking.swift @@ -88,9 +88,9 @@ class NCShareNetworking: NSObject { option.idShare = share.idShare let home = NCUtilityFileSystem.shared.getHomeServer(urlBase: self.metadata.urlBase, userId: self.metadata.userId) NCManageDatabase.shared.addShare(account: self.metadata.account, home: home, shares: [share]) - if option.hasChanges(comparedTo: share) { +// if option.hasChanges(comparedTo: share) { self.updateShare(option: option) - } +// } } else { NCContentPresenter.shared.showError(error: error) } @@ -113,7 +113,7 @@ class NCShareNetworking: NSObject { func updateShare(option: NCTableShareable) { NCActivityIndicator.shared.start(backgroundView: view) - NextcloudKit.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, data, error in + NextcloudKit.shared.updateShare(idShare: option.idShare, password: option.password, expireDate: option.expDateString, permissions: option.permissions, note: option.note, label: option.label, hideDownload: option.hideDownload, attributes: "") { account, share, data, error in NCActivityIndicator.shared.stop() if error == .success, let share = share { let home = NCUtilityFileSystem.shared.getHomeServer(urlBase: self.metadata.urlBase, userId: self.metadata.userId)