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

Add "allow download" sharing permission attribute #2500

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4937,8 +4937,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" */ = {
Expand Down
70 changes: 68 additions & 2 deletions iOSClient/Data/NCManageDatabase+Share.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,12 +67,69 @@ class tableShareV2: Object {
@objc dynamic var userIcon = ""
@objc dynamic var userMessage = ""
@objc dynamic var userStatus = ""
// @objc dynamic var attributes = ""
// @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<ShareAttribute>()

var attributes = [NKShare.Attribute]()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Realm wants a List I have to add this internal field


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
}

// static func toAttributeArray(attributes: List<ShareAttribute>) -> [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]) {
Expand Down Expand Up @@ -125,6 +182,15 @@ 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)
}

realm.add(object, update: .all)
}
}
Expand Down
6 changes: 5 additions & 1 deletion iOSClient/Share/Advanced/NCShareAdvancePermission.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg
tableView.rowHeight = UITableView.automaticDimension
self.setNavigationTitle()
self.navigationItem.hidesBackButton = true
// disbale pull to dimiss
// disbale pull to dismiss
isModalInPresentation = true
}

Expand Down Expand Up @@ -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 }
}
Expand All @@ -124,6 +126,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 }
}
Expand Down
44 changes: 43 additions & 1 deletion iOSClient/Share/Advanced/NCShareCells.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//

import UIKit
import NextcloudKit

protocol NCShareCellConfig {
var title: String { get }
Expand All @@ -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 }
Expand Down Expand Up @@ -162,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]
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I make another share NCToggleCellConfig, but for attributes

enum NCShareDetails: CaseIterable, NCShareCellConfig {
func didSelect(for share: NCTableShareable) {
switch self {
Expand Down Expand Up @@ -212,13 +250,15 @@ struct NCShareConfig {
let advanced: [NCShareDetails]
let share: NCTableShareable
let resharePermission: Int
let attributes: [NCShareAttribute]

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 = NCShareAttribute.forAll
}

func cellFor(indexPath: IndexPath) -> UITableViewCell? {
Expand All @@ -240,7 +280,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 }
}
Expand Down
4 changes: 4 additions & 0 deletions iOSClient/Share/NCShare+Helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import UIKit
import NextcloudKit
import Foundation

extension tableShare: NCTableShareable { }
extension NKShare: NCTableShareable { }
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
102 changes: 52 additions & 50 deletions iOSClient/Supporting Files/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down