From 3c2ae27fc7a10f661d0133d24efa64f9264c8233 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Thu, 26 Nov 2026 15:34:06 +0100 Subject: [PATCH] fix: show "Leave share" on received shares and round the sharer avatar On the top folder or file of a share received from another user, the menu offered "Delete folder"/"Delete file". The server only removes the share for the recipient in that case and leaves the owner's data alone, but the label made users afraid of deleting someone else's files and hid the way to leave a share. The item is detected with the rule the app already uses for the shared-folder icon: it has the S permission and its parent folder does not. The sharer's avatar shown in the list cell share button was drawn as a square; it is now cropped to a circle like avatars elsewhere in the app. Assisted-by: Claude Code:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Marino Faggiana --- Nextcloud.xcodeproj/project.pbxproj | 4 +++ .../NCReceivedShareRootTests.swift | 29 +++++++++++++++++++ .../Collection Common/Cell/NCListCell.swift | 13 ++++++++- iOSClient/Menu/NCContextMenuMain.swift | 24 +++++++++++---- iOSClient/Share/NCMetadataPermissions.swift | 17 +++++++++++ .../en.lproj/Localizable.strings | 1 + 6 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 Tests/NextcloudUnitTests/NCReceivedShareRootTests.swift diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 3cd942a24e..770606f3d3 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 */; }; @@ -1463,6 +1464,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 = ""; }; @@ -2317,6 +2319,7 @@ C0DEDA7E30C1000100A00001 /* NCAutoUploadDateTests.swift */, 4463A0C1300D000100A00003 /* NCAutoUploadKnownFilesTests.swift */, 4437B0C1300D000100A00001 /* NCBackupExclusionTests.swift */, + 4E3A0C13000D000100A00011 /* NCReceivedShareRootTests.swift */, 320C20803A58DAF7575440A8 /* NKErrorUserFriendlyMessageTests.swift */, C0DEA070306D000100000007 /* NCAutoUploadAssetTests.swift */, F76BED7B306D0000002E1442 /* NCPhotoLibraryAssetTests.swift */, @@ -4698,6 +4701,7 @@ C0DEDA7E30C1000100A00002 /* NCAutoUploadDateTests.swift in Sources */, 4463A0C1300D000100A00004 /* NCAutoUploadKnownFilesTests.swift in Sources */, 4437B0C1300D000100A00002 /* NCBackupExclusionTests.swift in Sources */, + 4E3A0C13000D000100A00012 /* NCReceivedShareRootTests.swift in Sources */, C0DEA070306D000100000008 /* NCAutoUploadAssetTests.swift in Sources */, F76BED7E306D0000002E1442 /* NCPhotoLibraryAssetTests.swift in Sources */, A1E2EE01000000000000000A /* NCEndToEndKeySetArchiveTests.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 1e805421be..a29e772abc 100755 --- a/iOSClient/Main/Collection Common/Cell/NCListCell.swift +++ b/iOSClient/Main/Collection Common/Cell/NCListCell.swift @@ -181,8 +181,19 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellMainP 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";