NCShareQuickStatusMenu.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // NCShareQuickStatusMenu.swift
  3. // Nextcloud
  4. //
  5. // Created by TSI-mc on 30/06/21.
  6. // Copyright © 2021 Marino Faggiana. All rights reserved.
  7. //
  8. import UIKit
  9. class NCShareQuickStatusMenu: NSObject {
  10. func toggleMenu(viewController: UIViewController, directory: Bool, tableShare: tableShare) {
  11. print(tableShare.permissions)
  12. let menuViewController = UIStoryboard(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
  13. var actions = [NCMenuAction]()
  14. actions.append(
  15. NCMenuAction(
  16. title: NSLocalizedString("_share_read_only_", comment: ""),
  17. icon: UIImage(),
  18. selected: tableShare.permissions == (NCGlobal.shared.permissionReadShare + NCGlobal.shared.permissionShareShare) || tableShare.permissions == NCGlobal.shared.permissionReadShare,
  19. on: false,
  20. action: { _ in
  21. let canShare = CCUtility.isPermission(toCanShare: tableShare.permissions)
  22. let permissions = CCUtility.getPermissionsValue(byCanEdit: false, andCanCreate: false, andCanChange: false, andCanDelete: false, andCanShare: canShare, andIsFolder: directory)
  23. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShareChangePermissions, userInfo: ["idShare": tableShare.idShare, "permissions": permissions, "hideDownload": tableShare.hideDownload])
  24. }
  25. )
  26. )
  27. actions.append(
  28. NCMenuAction(
  29. title: directory ? NSLocalizedString("_share_allow_upload_", comment: "") : NSLocalizedString("_share_editing_", comment: ""),
  30. icon: UIImage(),
  31. selected: hasUploadPermission(tableShare: tableShare),
  32. on: false,
  33. action: { _ in
  34. let canShare = CCUtility.isPermission(toCanShare: tableShare.permissions)
  35. let permissions = CCUtility.getPermissionsValue(byCanEdit: true, andCanCreate: true, andCanChange: true, andCanDelete: true, andCanShare: canShare, andIsFolder: directory)
  36. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShareChangePermissions, userInfo: ["idShare": tableShare.idShare, "permissions": permissions, "hideDownload": tableShare.hideDownload])
  37. }
  38. )
  39. )
  40. menuViewController.actions = actions
  41. let menuPanelController = NCMenuPanelController()
  42. menuPanelController.parentPresenter = viewController
  43. menuPanelController.delegate = menuViewController
  44. menuPanelController.set(contentViewController: menuViewController)
  45. menuPanelController.track(scrollView: menuViewController.tableView)
  46. viewController.present(menuPanelController, animated: true, completion: nil)
  47. }
  48. fileprivate func hasUploadPermission(tableShare: tableShare) -> Bool {
  49. let uploadPermissions = [
  50. NCGlobal.shared.permissionMaxFileShare,
  51. NCGlobal.shared.permissionMaxFolderShare,
  52. NCGlobal.shared.permissionDefaultFileRemoteShareNoSupportShareOption,
  53. NCGlobal.shared.permissionDefaultFolderRemoteShareNoSupportShareOption]
  54. return uploadPermissions.contains(tableShare.permissions)
  55. }
  56. }