|
| 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 `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 item. |
| 27 | + public static let update = Permission(rawValue: 2) |
| 28 | + |
| 29 | + /// Create the shared item. |
| 30 | + public static let create = Permission(rawValue: 4) |
| 31 | + |
| 32 | + /// Delete the shared item. |
| 33 | + public static let delete = Permission(rawValue: 8) |
| 34 | + |
| 35 | + /// Reshare the shared item. |
| 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 | + /// |
| 42 | + /// Determine the default permission value based on the given type value. |
| 43 | + /// |
| 44 | + /// - Parameters: |
| 45 | + /// - type: The share type enum value. |
| 46 | + /// |
| 47 | + public static func defaultPermission(for type: NKShare.ShareType) -> Permission { |
| 48 | + if type == .publicLink { |
| 49 | + return .read |
| 50 | + } else { |
| 51 | + return .all |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + /// |
| 57 | + /// The kind of the share. |
| 58 | + /// |
| 59 | + public enum ShareType: Int { |
| 60 | + /// |
| 61 | + /// A link which works internally only. |
| 62 | + /// |
| 63 | + case internalLink = -1 |
| 64 | + |
| 65 | + /// |
| 66 | + /// A share which is directly tied to a Nextcloud user. |
| 67 | + /// |
| 68 | + case user = 0 |
| 69 | + |
| 70 | + /// |
| 71 | + /// A share which is directly tied to a Nextcloud group. |
| 72 | + /// |
| 73 | + case group = 1 |
| 74 | + |
| 75 | + /// |
| 76 | + /// A publicly accessible link. |
| 77 | + /// |
| 78 | + case publicLink = 3 |
| 79 | + |
| 80 | + /// |
| 81 | + /// Shared by mail. |
| 82 | + /// |
| 83 | + case email = 4 |
| 84 | + |
| 85 | + /// |
| 86 | + /// A federated share. |
| 87 | + /// |
| 88 | + case federatedCloud = 6 |
| 89 | + |
| 90 | + /// |
| 91 | + /// Shared with a Nextcloud team. |
| 92 | + /// |
| 93 | + case team = 7 |
| 94 | + |
| 95 | + /// |
| 96 | + /// Shared within a Nextcloud Talk conversation. |
| 97 | + /// |
| 98 | + case talkConversation = 10 |
| 99 | + } |
| 100 | + |
| 101 | + public var account = "" |
| 102 | + public var canEdit: Bool = false |
| 103 | + public var canDelete: Bool = false |
| 104 | + public var date: Date? |
| 105 | + public var displaynameFileOwner = "" |
| 106 | + public var displaynameOwner = "" |
| 107 | + public var expirationDate: NSDate? |
| 108 | + public var fileParent: Int = 0 |
| 109 | + public var fileSource: Int = 0 |
| 110 | + public var fileTarget = "" |
| 111 | + public var hideDownload: Bool = false |
| 112 | + public var idShare: Int = 0 |
| 113 | + public var itemSource: Int = 0 |
| 114 | + public var itemType = "" |
| 115 | + public var label = "" |
| 116 | + public var mailSend: Bool = false |
| 117 | + public var mimeType = "" |
| 118 | + public var note = "" |
| 119 | + public var parent = "" |
| 120 | + public var password = "" |
| 121 | + public var path = "" |
| 122 | + |
| 123 | + /// |
| 124 | + /// See ``Permission`` for possible bitmask values. |
| 125 | + /// |
| 126 | + public var permissions: Int = 0 |
| 127 | + |
| 128 | + public var sendPasswordByTalk: Bool = false |
| 129 | + public var shareType: Int = 0 |
| 130 | + public var shareWith = "" |
| 131 | + public var shareWithDisplayname = "" |
| 132 | + public var storage: Int = 0 |
| 133 | + public var storageId = "" |
| 134 | + public var token = "" |
| 135 | + public var uidFileOwner = "" |
| 136 | + public var uidOwner = "" |
| 137 | + public var url = "" |
| 138 | + public var userClearAt: Date? |
| 139 | + public var userIcon = "" |
| 140 | + public var userMessage = "" |
| 141 | + public var userStatus = "" |
| 142 | + public var attributes: String? |
| 143 | +} |
0 commit comments