Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -1465,6 +1466,7 @@
C0DEDA7E30C1000100A00001 /* NCAutoUploadDateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCAutoUploadDateTests.swift; sourceTree = "<group>"; };
C4A84566BEF80733CC99BA52 /* NCAccountSetupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCAccountSetupView.swift; sourceTree = "<group>"; };
4463A0C1300D000100A00003 /* NCAutoUploadKnownFilesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCAutoUploadKnownFilesTests.swift; sourceTree = "<group>"; };
4E3A0C13000D000100A00011 /* NCReceivedShareRootTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCReceivedShareRootTests.swift; sourceTree = "<group>"; };
4437B0C1300D000100A00001 /* NCBackupExclusionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCBackupExclusionTests.swift; sourceTree = "<group>"; };
CE0CD9A00D74B01055F238E9 /* NCErrorContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCErrorContext.swift; sourceTree = "<group>"; };
CE2A4CC67E2712B70FCFC090 /* NCLoginServerErrorClassifierTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCLoginServerErrorClassifierTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
29 changes: 29 additions & 0 deletions Tests/NextcloudUnitTests/NCReceivedShareRootTests.swift
Original file line number Diff line number Diff line change
@@ -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))
}
}
13 changes: 12 additions & 1 deletion iOSClient/Main/Collection Common/Cell/NCListCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
24 changes: 19 additions & 5 deletions iOSClient/Menu/NCContextMenuMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions iOSClient/Share/NCMetadataPermissions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions iOSClient/Supporting Files/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading