Skip to content

Commit

Permalink
- Added new OCItem.shareRootItem(from: core) and OCItem.isShareRootIt…
Browse files Browse the repository at this point in the history
…em(from: core) methods

- Adapted DeleteAction and UnshareAction so that deletion is available inside shared folders where the owner allowed deletion
  • Loading branch information
felix-schwarz committed Jun 7, 2019
1 parent 2982081 commit c06f6b9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
12 changes: 11 additions & 1 deletion ownCloud/Client/Actions/Actions+Extensions/DeleteAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion ownCloud/Client/Actions/Actions+Extensions/UnshareAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 30 additions & 2 deletions ownCloud/SDK Extensions/OCItem+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ extension OCItem {
return iconName
}

func iconName() -> String? {
var iconName : String? {
var iconName = OCItem.iconName(for: self.mimeType)

if iconName == nil {
Expand All @@ -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)
}

Expand Down Expand Up @@ -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?

Expand Down

0 comments on commit c06f6b9

Please sign in to comment.