Skip to content

Commit ed88fc5

Browse files
committed
feat: Share permission and type types.
- Moved NKShare into dedicated source code file. - Added documentation comments. - Introduced OptionSet for bitmask operations in share permissions which previously were implemented in projects using this library. - Introduced nested ShareType enum in NKShare. - OptionSets are the conventional way to work with bit masks in Swift. Signed-off-by: Iva Horn <iva.horn@nextcloud.com>
1 parent 7520e1e commit ed88fc5

2 files changed

Lines changed: 143 additions & 40 deletions

File tree

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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+
}

Sources/NextcloudKit/NextcloudKit+Share.swift

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -690,43 +690,3 @@ public extension NextcloudKit {
690690
return share
691691
}
692692
}
693-
694-
public class NKShare: NSObject {
695-
public var account = ""
696-
public var canEdit: Bool = false
697-
public var canDelete: Bool = false
698-
public var date: Date?
699-
public var displaynameFileOwner = ""
700-
public var displaynameOwner = ""
701-
public var expirationDate: NSDate?
702-
public var fileParent: Int = 0
703-
public var fileSource: Int = 0
704-
public var fileTarget = ""
705-
public var hideDownload: Bool = false
706-
public var idShare: Int = 0
707-
public var itemSource: Int = 0
708-
public var itemType = ""
709-
public var label = ""
710-
public var mailSend: Bool = false
711-
public var mimeType = ""
712-
public var note = ""
713-
public var parent = ""
714-
public var password = ""
715-
public var path = ""
716-
public var permissions: Int = 0
717-
public var sendPasswordByTalk: Bool = false
718-
public var shareType: Int = 0
719-
public var shareWith = ""
720-
public var shareWithDisplayname = ""
721-
public var storage: Int = 0
722-
public var storageId = ""
723-
public var token = ""
724-
public var uidFileOwner = ""
725-
public var uidOwner = ""
726-
public var url = ""
727-
public var userClearAt: Date?
728-
public var userIcon = ""
729-
public var userMessage = ""
730-
public var userStatus = ""
731-
public var attributes: String?
732-
}

0 commit comments

Comments
 (0)