diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index b7ed851831..ee1a1b0909 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -164,6 +164,7 @@ C32F0D5074355BA3F35E7FCE /* NCAccountSetupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A84566BEF80733CC99BA52 /* NCAccountSetupView.swift */; }; C7724CB38D2A7B4B98CA1AFA /* NCLoginServerErrorClassifierTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE2A4CC67E2712B70FCFC090 /* NCLoginServerErrorClassifierTests.swift */; }; 4463A0C1300D000100A00004 /* NCAutoUploadKnownFilesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4463A0C1300D000100A00003 /* NCAutoUploadKnownFilesTests.swift */; }; + 4E3A0C13000D000100A00012 /* NCReceivedShareRootTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3A0C13000D000100A00011 /* NCReceivedShareRootTests.swift */; }; 4437B0C1300D000100A00002 /* NCBackupExclusionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4437B0C1300D000100A00001 /* NCBackupExclusionTests.swift */; }; CB3666201AF7550816B5CD6A /* NCContextMenuComment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8932E90EC4278026D86CCCC9 /* NCContextMenuComment.swift */; }; D56DFFE5D5014F66A7C9FED0 /* PasscodeUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC6C501EF1104A6A8569D9C1 /* PasscodeUITests.swift */; }; @@ -1465,6 +1466,7 @@ C0DEDA7E30C1000100A00001 /* NCAutoUploadDateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCAutoUploadDateTests.swift; sourceTree = ""; }; C4A84566BEF80733CC99BA52 /* NCAccountSetupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCAccountSetupView.swift; sourceTree = ""; }; 4463A0C1300D000100A00003 /* NCAutoUploadKnownFilesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCAutoUploadKnownFilesTests.swift; sourceTree = ""; }; + 4E3A0C13000D000100A00011 /* NCReceivedShareRootTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCReceivedShareRootTests.swift; sourceTree = ""; }; 4437B0C1300D000100A00001 /* NCBackupExclusionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCBackupExclusionTests.swift; sourceTree = ""; }; CE0CD9A00D74B01055F238E9 /* NCErrorContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCErrorContext.swift; sourceTree = ""; }; CE2A4CC67E2712B70FCFC090 /* NCLoginServerErrorClassifierTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCLoginServerErrorClassifierTests.swift; sourceTree = ""; }; @@ -2323,6 +2325,7 @@ C0DEDA7E30C1000100A00001 /* NCAutoUploadDateTests.swift */, 4463A0C1300D000100A00003 /* NCAutoUploadKnownFilesTests.swift */, 4437B0C1300D000100A00001 /* NCBackupExclusionTests.swift */, + 4E3A0C13000D000100A00011 /* NCReceivedShareRootTests.swift */, 4E3A0C13000D000100A00005 /* NCMenuPresentationMonitorTests.swift */, 320C20803A58DAF7575440A8 /* NKErrorUserFriendlyMessageTests.swift */, C0DEA070306D000100000007 /* NCAutoUploadAssetTests.swift */, @@ -4704,6 +4707,7 @@ C0DEDA7E30C1000100A00002 /* NCAutoUploadDateTests.swift in Sources */, 4463A0C1300D000100A00004 /* NCAutoUploadKnownFilesTests.swift in Sources */, 4437B0C1300D000100A00002 /* NCBackupExclusionTests.swift in Sources */, + 4E3A0C13000D000100A00012 /* NCReceivedShareRootTests.swift in Sources */, 4E3A0C13000D000100A00006 /* NCMenuPresentationMonitorTests.swift in Sources */, C0DEA070306D000100000008 /* NCAutoUploadAssetTests.swift in Sources */, F76BED7E306D0000002E1442 /* NCPhotoLibraryAssetTests.swift in Sources */, diff --git a/Tests/NextcloudUnitTests/NCReceivedShareRootTests.swift b/Tests/NextcloudUnitTests/NCReceivedShareRootTests.swift new file mode 100644 index 0000000000..13f5466fbb --- /dev/null +++ b/Tests/NextcloudUnitTests/NCReceivedShareRootTests.swift @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: Nextcloud GmbH +// SPDX-FileCopyrightText: 2026 Marino Faggiana +// SPDX-License-Identifier: GPL-3.0-or-later + +import Testing +@testable import Nextcloud + +@Suite("Received share root detection") +struct NCReceivedShareRootTests { + @Test("A shared item in one of the user's own folders is the top of a received share") + func receivedShareRoot() { + #expect(NCMetadataPermissions.isReceivedShareRoot(permissions: "SRGDNVCK", parentPermissions: "RGDNVCK")) + } + + @Test("An item inside a received share is not its top") + func itemInsideReceivedShare() { + #expect(!NCMetadataPermissions.isReceivedShareRoot(permissions: "SRGDNVW", parentPermissions: "SRGDNVCK")) + } + + @Test("The user's own items are not received shares") + func ownItem() { + #expect(!NCMetadataPermissions.isReceivedShareRoot(permissions: "RGDNVCK", parentPermissions: "RGDNVCK")) + } + + @Test("Without the parent folder the item is not treated as a received share") + func unknownParent() { + #expect(!NCMetadataPermissions.isReceivedShareRoot(permissions: "SRGDNVCK", parentPermissions: nil)) + } +} diff --git a/iOSClient/Main/Collection Common/Cell/NCListCell.swift b/iOSClient/Main/Collection Common/Cell/NCListCell.swift index 61b3897b08..75801e1033 100755 --- a/iOSClient/Main/Collection Common/Cell/NCListCell.swift +++ b/iOSClient/Main/Collection Common/Cell/NCListCell.swift @@ -175,8 +175,19 @@ class NCListCell: UICollectionViewCell, NCCellMainProtocol { tagMore.setContentHuggingPriority(.required, for: .horizontal) } + /// Shows the avatar of the user who shared the item, cropped to a circle like avatars elsewhere in the app. func setSharedAvatarImage(_ image: UIImage) { - buttonShared.setImage(image, for: .normal) + let side = min(image.size.width, image.size.height) + let format = UIGraphicsImageRendererFormat.preferred() + format.scale = image.scale + let roundedImage = UIGraphicsImageRenderer(size: CGSize(width: side, height: side), format: format).image { _ in + let bounds = CGRect(x: 0, y: 0, width: side, height: side) + UIBezierPath(ovalIn: bounds).addClip() + // Center the image so a non-square avatar is cropped evenly. + image.draw(at: CGPoint(x: (side - image.size.width) / 2, y: (side - image.size.height) / 2)) + } + + buttonShared.setImage(roundedImage.withRenderingMode(.alwaysOriginal), for: .normal) buttonShared.imageEdgeInsets = UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4) } diff --git a/iOSClient/Menu/NCContextMenuMain.swift b/iOSClient/Menu/NCContextMenuMain.swift index 0caf019830..c86be666d2 100644 --- a/iOSClient/Menu/NCContextMenuMain.swift +++ b/iOSClient/Menu/NCContextMenuMain.swift @@ -357,12 +357,26 @@ class NCContextMenuMain: NSObject { } private func makeDeleteFileAction(metadata: tableMetadata) -> UIAction { + // On the top of a received share the server removes the share for this user + // instead of deleting the owner's data, so say "Leave share" rather than "Delete". + let parentPermissions = NCManageDatabase.shared.getTableDirectory( + predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl) + )?.permissions + let isReceivedShareRoot = NCMetadataPermissions.isReceivedShareRoot(permissions: metadata.permissions, parentPermissions: parentPermissions) + + let title: String + let imageName: String + if isReceivedShareRoot { + title = "_leave_share_" + imageName = "person.2.slash" + } else { + title = metadata.directory ? "_delete_folder_" : "_delete_file_" + imageName = "trash" + } + return UIAction( - title: NSLocalizedString( - metadata.directory ? "_delete_folder_" : "_delete_file_", - comment: "" - ), - image: utility.loadImage(named: "trash"), + title: NSLocalizedString(title, comment: ""), + image: utility.loadImage(named: imageName), attributes: .destructive ) { _ in if self.viewController is NCCollectionViewCommon { diff --git a/iOSClient/Share/NCMetadataPermissions.swift b/iOSClient/Share/NCMetadataPermissions.swift index dac4313c48..18f8cba119 100644 --- a/iOSClient/Share/NCMetadataPermissions.swift +++ b/iOSClient/Share/NCMetadataPermissions.swift @@ -36,6 +36,23 @@ enum NCMetadataPermissions { return metadata.permissions.contains(permissionCanMove) } + /// Whether an item is the top of a share received from another user. + /// + /// The server marks every item inside a received share with `S`, so the top of the + /// share is the item that has `S` while its parent folder does not. Deleting that item + /// only removes the share for the current user; the owner's data is not touched. + /// + /// - Parameters: + /// - permissions: The WebDAV permissions of the item. + /// - parentPermissions: The WebDAV permissions of the folder that contains it, or `nil` if unknown. + /// - Returns: `false` when the parent folder is unknown. + static func isReceivedShareRoot(permissions: String, parentPermissions: String?) -> Bool { + guard let parentPermissions else { + return false + } + return permissions.contains(permissionShared) && !parentPermissions.contains(permissionShared) + } + static func canRename(_ metadata: tableMetadata) -> Bool { return metadata.permissions.contains(permissionCanRename) } diff --git a/iOSClient/Supporting Files/en.lproj/Localizable.strings b/iOSClient/Supporting Files/en.lproj/Localizable.strings index 895eaa4bee..dbd6e1de23 100644 --- a/iOSClient/Supporting Files/en.lproj/Localizable.strings +++ b/iOSClient/Supporting Files/en.lproj/Localizable.strings @@ -131,6 +131,7 @@ "_remove_file_" = "Remove file"; "_delete_file_" = "Delete file"; "_delete_folder_" = "Delete folder"; +"_leave_share_" = "Leave share"; "_size_" = "Size"; "_set_user_status_" = "Online status"; "_set_user_status_message_" = "Status message";