Skip to content

Commit 7911c60

Browse files
committed
feat: Nextcloud share permission OptionSet.
- 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. - OptionSets are the conventional way to work with bit masks in Swift. Signed-off-by: Iva Horn <iva.horn@nextcloud.com>
1 parent 71c06c6 commit 7911c60

2 files changed

Lines changed: 93 additions & 40 deletions

File tree

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

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)