diff --git a/ownCloud/Client/Actions/Actions+Extensions/DeleteAction.swift b/ownCloud/Client/Actions/Actions+Extensions/DeleteAction.swift index 02c651b82..ddba13769 100644 --- a/ownCloud/Client/Actions/Actions+Extensions/DeleteAction.swift +++ b/ownCloud/Client/Actions/Actions+Extensions/DeleteAction.swift @@ -26,7 +26,17 @@ class DeleteAction : Action { // MARK: - Extension matching override class func applicablePosition(forContext: ActionContext) -> ActionPosition { - return (forContext.items.sharedWithUser.count != 0) ? .none : .last + let sharedWithUser = forContext.items.sharedWithUser + + if let core = forContext.core { + for sharedItem in sharedWithUser { + if sharedItem.isShareRootItem(from: core) { + return .none + } + } + } + + return .last } // MARK: - Action implementation diff --git a/ownCloud/Client/Actions/Actions+Extensions/UnshareAction.swift b/ownCloud/Client/Actions/Actions+Extensions/UnshareAction.swift index dd50f80a6..ccd68c6ac 100644 --- a/ownCloud/Client/Actions/Actions+Extensions/UnshareAction.swift +++ b/ownCloud/Client/Actions/Actions+Extensions/UnshareAction.swift @@ -32,7 +32,21 @@ class UnshareAction : Action { // MARK: - Extension matching override class func applicablePosition(forContext: ActionContext) -> ActionPosition { - return (forContext.items.sharedWithUser.count != forContext.items.count) ? .none : .last + let sharedWithUser = forContext.items.sharedWithUser + + if forContext.items.count != sharedWithUser.count { + return .none + } + + if let core = forContext.core { + for sharedItem in sharedWithUser { + if !sharedItem.isShareRootItem(from: core) { + return .none + } + } + } + + return .last } // MARK: - Action implementation diff --git a/ownCloud/SDK Extensions/OCItem+Extension.swift b/ownCloud/SDK Extensions/OCItem+Extension.swift index d9174c7ec..315abf0e1 100644 --- a/ownCloud/SDK Extensions/OCItem+Extension.swift +++ b/ownCloud/SDK Extensions/OCItem+Extension.swift @@ -191,7 +191,7 @@ extension OCItem { return iconName } - func iconName() -> String? { + var iconName : String? { var iconName = OCItem.iconName(for: self.mimeType) if iconName == nil { @@ -206,7 +206,7 @@ extension OCItem { } func icon(fitInSize: CGSize) -> UIImage? { - if let iconName = self.iconName() { + if let iconName = self.iconName { return Theme.shared.image(for: iconName, size: fitInSize) } @@ -267,6 +267,34 @@ extension OCItem { return false } + func shareRootItem(from core: OCCore) -> OCItem? { + var shareRootItem : OCItem? + + if self.isSharedWithUser { + var parentItem : OCItem? = self + + shareRootItem = self + + repeat { + parentItem = parentItem?.parentItem(from: core) + + if parentItem != nil, parentItem?.isSharedWithUser == true { + shareRootItem = parentItem + } + } while ((parentItem != nil) && (parentItem?.isSharedWithUser == true)) + } + + return shareRootItem + } + + func isShareRootItem(from core: OCCore) -> Bool { + if let shareRootItem = shareRootItem(from: core) { + return shareRootItem.localID == localID + } + + return false + } + func parentItem(from core: OCCore, completionHandler: ((_ error: Error?, _ parentItem: OCItem?) -> Void)? = nil) -> OCItem? { var parentItem : OCItem?