|
| 1 | +// SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
| 2 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | + |
| 4 | +import Foundation |
| 5 | + |
| 6 | +/// |
| 7 | +/// Represents a Nextcloud share with its associated properties and permissions. |
| 8 | +/// |
| 9 | +public final class NKShare: NSObject { |
| 10 | + /// |
| 11 | + /// Bitmask values defining share permissions as used in ``NKShare\\permissions``. |
| 12 | + /// |
| 13 | + /// As defined in the [OCS Share API documentation](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-share-api.html). |
| 14 | + /// |
| 15 | + public struct Permission: OptionSet { |
| 16 | + public let rawValue: Int |
| 17 | + |
| 18 | + public init(rawValue: Int) { |
| 19 | + self.rawValue = rawValue |
| 20 | + } |
| 21 | + |
| 22 | + /// Access the shared item. |
| 23 | + /// Default value for public shares. |
| 24 | + public static let read = Permission(rawValue: 1) |
| 25 | + |
| 26 | + /// Edit the shared items. |
| 27 | + public static let update = Permission(rawValue: 2) |
| 28 | + |
| 29 | + /// Create the shared items. |
| 30 | + public static let create = Permission(rawValue: 4) |
| 31 | + |
| 32 | + /// Delete the shared items. |
| 33 | + public static let delete = Permission(rawValue: 8) |
| 34 | + |
| 35 | + /// Reshare the shared items. |
| 36 | + public static let share = Permission(rawValue: 16) |
| 37 | + |
| 38 | + /// Default value except for public shares. |
| 39 | + public static let all: Permission = [.read, .update, .create, .delete, .share] |
| 40 | + |
| 41 | + /// Determine the default permission value based on the given type value. |
| 42 | + public static func defaultPermission(for type: Int) -> Permission { |
| 43 | + if type == 3 { |
| 44 | + return .read |
| 45 | + } else { |
| 46 | + return .all |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + public var account = "" |
| 52 | + public var canEdit: Bool = false |
| 53 | + public var canDelete: Bool = false |
| 54 | + public var date: Date? |
| 55 | + public var displaynameFileOwner = "" |
| 56 | + public var displaynameOwner = "" |
| 57 | + public var expirationDate: NSDate? |
| 58 | + public var fileParent: Int = 0 |
| 59 | + public var fileSource: Int = 0 |
| 60 | + public var fileTarget = "" |
| 61 | + public var hideDownload: Bool = false |
| 62 | + public var idShare: Int = 0 |
| 63 | + public var itemSource: Int = 0 |
| 64 | + public var itemType = "" |
| 65 | + public var label = "" |
| 66 | + public var mailSend: Bool = false |
| 67 | + public var mimeType = "" |
| 68 | + public var note = "" |
| 69 | + public var parent = "" |
| 70 | + public var password = "" |
| 71 | + public var path = "" |
| 72 | + |
| 73 | + /// |
| 74 | + /// See ``Permission`` for possible bitmask values. |
| 75 | + /// |
| 76 | + public var permissions: Int = 0 |
| 77 | + |
| 78 | + public var sendPasswordByTalk: Bool = false |
| 79 | + public var shareType: Int = 0 |
| 80 | + public var shareWith = "" |
| 81 | + public var shareWithDisplayname = "" |
| 82 | + public var storage: Int = 0 |
| 83 | + public var storageId = "" |
| 84 | + public var token = "" |
| 85 | + public var uidFileOwner = "" |
| 86 | + public var uidOwner = "" |
| 87 | + public var url = "" |
| 88 | + public var userClearAt: Date? |
| 89 | + public var userIcon = "" |
| 90 | + public var userMessage = "" |
| 91 | + public var userStatus = "" |
| 92 | + public var attributes: String? |
| 93 | +} |
0 commit comments