diff --git a/Sources/NextcloudFileProviderKit/Item/Item.swift b/Sources/NextcloudFileProviderKit/Item/Item.swift index 18bf143..9e28710 100644 --- a/Sources/NextcloudFileProviderKit/Item/Item.swift +++ b/Sources/NextcloudFileProviderKit/Item/Item.swift @@ -162,11 +162,13 @@ public class Item: NSObject, NSFileProviderItem { } public var userInfo: [AnyHashable : Any]? { - [ + var userInfoDict = [AnyHashable : Any]() + if metadata.lock { // Can be used to display lock/unlock context menu entries for FPUIActions - "isLockable": !self.contentType.conforms(to: .directory) && !metadata.lock, - "isUnlockable": !self.contentType.conforms(to: .directory) && metadata.lock, - ] + // Note that only files, not folders, should be lockable/unlockable + userInfoDict["locked"] = metadata.lock + } + return userInfoDict } @available(macOS 13.0, *) diff --git a/Tests/NextcloudFileProviderKitTests/ItemPropertyTests.swift b/Tests/NextcloudFileProviderKitTests/ItemPropertyTests.swift index d5579f6..d8f6304 100644 --- a/Tests/NextcloudFileProviderKitTests/ItemPropertyTests.swift +++ b/Tests/NextcloudFileProviderKitTests/ItemPropertyTests.swift @@ -183,35 +183,6 @@ final class ItemPropertyTests: XCTestCase { XCTAssertTrue(item.contentType.conforms(to: .bundle)) } - func testItemUserInfoLockingPropsFolder() { - let metadata = ItemMetadata() - metadata.ocId = "test-id" - metadata.etag = "test-etag" - metadata.account = Self.account.ncKitAccount - metadata.name = "test" - metadata.fileName = "test" - metadata.fileNameView = "test" - metadata.serverUrl = Self.account.davFilesUrl - metadata.urlBase = Self.account.serverUrl - metadata.userId = Self.account.username - metadata.user = Self.account.username - metadata.directory = true - metadata.contentType = "httpd/unix-directory" - metadata.lockTime = .init() - metadata.lockTimeOut = .init() - - let item = Item( - metadata: metadata, - parentItemIdentifier: .rootContainer, - remoteInterface: MockRemoteInterface(account: Self.account) - ) - - XCTAssertNotNil(item.userInfo?["isLockable"]) - XCTAssertNotNil(item.userInfo?["isUnlockable"]) - XCTAssertFalse(item.userInfo?["isLockable"] as? Bool ?? true) // directories not lockable - XCTAssertFalse(item.userInfo?["isUnlockable"] as? Bool ?? true) - } - func testItemUserInfoLockingPropsFileLocked() { let metadata = ItemMetadata() metadata.ocId = "test-id" @@ -238,10 +209,13 @@ final class ItemPropertyTests: XCTestCase { remoteInterface: MockRemoteInterface(account: Self.account) ) - XCTAssertNotNil(item.userInfo?["isLockable"]) - XCTAssertNotNil(item.userInfo?["isUnlockable"]) - XCTAssertFalse(item.userInfo?["isLockable"] as? Bool ?? true) - XCTAssertTrue(item.userInfo?["isUnlockable"] as? Bool ?? false) // locked file, can unlock + XCTAssertNotNil(item.userInfo?["locked"]) + + let fileproviderItems = ["fileproviderItems": [item]] + let lockPredicate = NSPredicate( + format: "SUBQUERY ( fileproviderItems, $fileproviderItem, $fileproviderItem.userInfo.locked != nil ).@count > 0" + ) + XCTAssertTrue(lockPredicate.evaluate(with: fileproviderItems)) } func testItemUserInfoLockingPropsFileUnlocked() { @@ -265,9 +239,12 @@ final class ItemPropertyTests: XCTestCase { remoteInterface: MockRemoteInterface(account: Self.account) ) - XCTAssertNotNil(item.userInfo?["isLockable"]) - XCTAssertNotNil(item.userInfo?["isUnlockable"]) - XCTAssertTrue(item.userInfo?["isLockable"] as? Bool ?? false) // unlocked file, can lock - XCTAssertFalse(item.userInfo?["isUnlockable"] as? Bool ?? true) + XCTAssertNil(item.userInfo?["locked"]) + + let fileproviderItems = ["fileproviderItems": [item]] + let lockPredicate = NSPredicate( + format: "SUBQUERY ( fileproviderItems, $fileproviderItem, $fileproviderItem.userInfo.locked == nil ).@count > 0" + ) + XCTAssertTrue(lockPredicate.evaluate(with: fileproviderItems)) } }