fix(file-provider): allow adding items to a folder only when the server permits it
`Item.capabilities` granted `allowsAddingSubItems` to every folder whose permissions contain `NV`. On the server `N` means rename and `V` means move, and creating items is `C` and `K`, which the `CK` branch already maps to `allowsWriting`, the same bit as `allowsAddingSubItems`. A read-only received share is listed as `SGDNV`, so the framework was told that items could be added to a share that does not permit it. `NV` now grants only renaming and moving. The root and trash containers are built without server permissions and relied on the default `RGDNVW` for adding items, so they now carry `RGDNVCK` and keep exactly the capabilities they had. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Julius van der Vaart <[email protected]>
This commit is contained in:
1 parent
545b78d9de
commit
3588a35970
2 files changed
+46
-8
No files matched your search
+3
-5
@@ -58,12 +58,8 @@ public final class Item: NSObject, NSFileProviderItem, Sendable {
|
||||
capabilities.insert(.allowsWriting)
|
||||
}
|
||||
|
||||
if permissions.contains("NV") { // Updateable, renameable, moveable
|
||||
if permissions.contains("NV") { // Renameable, moveable
|
||||
capabilities.formUnion([.allowsRenaming, .allowsReparenting])
|
||||
|
||||
if metadata.directory {
|
||||
capabilities.insert(.allowsAddingSubItems)
|
||||
}
|
||||
}
|
||||
|
||||
if permissions.contains("CK"), metadata.directory { // Folder not changeable but adding sub-files & -folders
|
||||
@@ -374,6 +370,7 @@ public final class Item: NSObject, NSFileProviderItem, Sendable {
|
||||
ownerId: "", // Placeholder as not set in original code
|
||||
ownerDisplayName: "", // Placeholder as not set in original code
|
||||
path: "", // Placeholder as not set in original code
|
||||
permissions: "RGDNVCK",
|
||||
serverUrl: account.davFilesUrl,
|
||||
size: 0, // Default as not set in original code
|
||||
uploaded: true,
|
||||
@@ -431,6 +428,7 @@ public final class Item: NSObject, NSFileProviderItem, Sendable {
|
||||
ownerId: "", // Placeholder as not set in original code
|
||||
ownerDisplayName: "", // Placeholder as not set in original code
|
||||
path: "", // Placeholder as not set in original code
|
||||
permissions: "RGDNVCK",
|
||||
serverUrl: account.trashUrl,
|
||||
size: 0, // Default as not set in original code
|
||||
uploaded: true,
|
||||
|
||||
+43
-3
@@ -1173,7 +1173,7 @@ final class ItemPropertyTests: NextcloudFileProviderKitTestCase {
|
||||
// Case 1: Can add sub-items to a directory
|
||||
var dirMetadata =
|
||||
SendableItemMetadata(ocId: "dir-add-id", fileName: "MyFolder", account: Self.account)
|
||||
dirMetadata.permissions = "NV"
|
||||
dirMetadata.permissions = "CK"
|
||||
dirMetadata.directory = true
|
||||
let canAddSubItemsItem = Item(
|
||||
metadata: dirMetadata,
|
||||
@@ -1187,7 +1187,7 @@ final class ItemPropertyTests: NextcloudFileProviderKitTestCase {
|
||||
)
|
||||
XCTAssertTrue(
|
||||
canAddSubItemsItem.capabilities.contains(.allowsAddingSubItems),
|
||||
"Directory with 'NV' should allow adding sub-items."
|
||||
"Directory with 'CK' should allow adding sub-items."
|
||||
)
|
||||
|
||||
// Case 2: Cannot add sub-items to a file
|
||||
@@ -1227,6 +1227,46 @@ final class ItemPropertyTests: NextcloudFileProviderKitTestCase {
|
||||
cannotAddToLockedDirItem.capabilities.contains(.allowsAddingSubItems),
|
||||
"Locked directory should not allow adding sub-items."
|
||||
)
|
||||
|
||||
// Case 4: A read-only received share is listed with 'NV' but without 'CK'
|
||||
var readOnlyShareMetadata = dirMetadata
|
||||
readOnlyShareMetadata.ocId = "read-only-share-id"
|
||||
readOnlyShareMetadata.permissions = "SGDNV"
|
||||
let readOnlyShareItem = Item(
|
||||
metadata: readOnlyShareMetadata,
|
||||
parentItemIdentifier: .rootContainer,
|
||||
account: Self.account,
|
||||
remoteInterface: MockRemoteInterface(account: Self.account),
|
||||
dbManager: Self.dbManager,
|
||||
displayFileActions: false,
|
||||
remoteSupportsTrash: true,
|
||||
log: FileProviderLogMock()
|
||||
)
|
||||
XCTAssertTrue(
|
||||
readOnlyShareItem.capabilities.isSuperset(of: [.allowsRenaming, .allowsReparenting]),
|
||||
"A received share can still be renamed and moved."
|
||||
)
|
||||
XCTAssertFalse(
|
||||
readOnlyShareItem.capabilities.contains(.allowsAddingSubItems),
|
||||
"A share without 'CK' must not allow adding sub-items."
|
||||
)
|
||||
|
||||
// Case 5: The root and trash containers keep allowing sub-items
|
||||
XCTAssertTrue(
|
||||
makeRootItem().capabilities.contains(.allowsAddingSubItems),
|
||||
"The root container must allow adding sub-items."
|
||||
)
|
||||
let trashItem = Item.trashContainer(
|
||||
remoteInterface: MockRemoteInterface(account: Self.account),
|
||||
account: Self.account,
|
||||
dbManager: Self.dbManager,
|
||||
remoteSupportsTrash: true,
|
||||
log: FileProviderLogMock()
|
||||
)
|
||||
XCTAssertTrue(
|
||||
trashItem.capabilities.contains(.allowsAddingSubItems),
|
||||
"The trash container must keep allowing sub-items."
|
||||
)
|
||||
}
|
||||
|
||||
func testCapabilitiesFullPermissionsFile() {
|
||||
@@ -1261,7 +1301,7 @@ final class ItemPropertyTests: NextcloudFileProviderKitTestCase {
|
||||
var metadata = SendableItemMetadata(
|
||||
ocId: "full-perms-folder", fileName: "SuperFolder", account: Self.account
|
||||
)
|
||||
metadata.permissions = "RGDNVW"
|
||||
metadata.permissions = "RGDNVCK"
|
||||
metadata.directory = true
|
||||
let item = Item(
|
||||
metadata: metadata,
|
||||
|
||||
Reference in new issue
Block a user