123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import Foundation
- extension NCShare {
- func toggleShareMenu(for share: tableShare) {
- var actions = [NCMenuAction]()
- if share.shareType == 3, canReshare {
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_share_add_sharelink_", comment: ""),
- icon: NCUtility.shared.loadImage(named: "shareAdd"),
- action: { _ in
- self.makeNewLinkShare()
- }
- )
- )
- }
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_details_", comment: ""),
- icon: NCUtility.shared.loadImage(named: "pencil"),
- action: { _ in
- guard
- let advancePermission = UIStoryboard(name: "NCShare", bundle: nil).instantiateViewController(withIdentifier: "NCShareAdvancePermission") as? NCShareAdvancePermission,
- let navigationController = self.navigationController, !share.isInvalidated else { return }
- advancePermission.networking = self.networking
- advancePermission.share = tableShare(value: share)
- advancePermission.oldTableShare = tableShare(value: share)
- advancePermission.metadata = self.metadata
- navigationController.pushViewController(advancePermission, animated: true)
- }
- )
- )
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_share_unshare_", comment: ""),
- icon: NCUtility.shared.loadImage(named: "trash"),
- action: { _ in
- self.networking?.unShare(idShare: share.idShare)
- }
- )
- )
- self.presentMenu(with: actions)
- }
- func toggleUserPermissionMenu(isDirectory: Bool, tableShare: tableShare) {
- var actions = [NCMenuAction]()
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_share_read_only_", comment: ""),
- icon: NCUtility.shared.loadImage(named: "eye"),
- selected: tableShare.permissions == (NCGlobal.shared.permissionReadShare + NCGlobal.shared.permissionShareShare) || tableShare.permissions == NCGlobal.shared.permissionReadShare,
- on: false,
- action: { _ in
- let canShare = CCUtility.isPermission(toCanShare: tableShare.permissions)
- let permissions = CCUtility.getPermissionsValue(byCanEdit: false, andCanCreate: false, andCanChange: false, andCanDelete: false, andCanShare: canShare, andIsFolder: isDirectory)
- self.updateSharePermissions(share: tableShare, permissions: permissions)
- }
- )
- )
- actions.append(
- NCMenuAction(
- title: isDirectory ? NSLocalizedString("_share_allow_upload_", comment: "") : NSLocalizedString("_share_editing_", comment: ""),
- icon: NCUtility.shared.loadImage(named: "pencil"),
- selected: hasUploadPermission(tableShare: tableShare),
- on: false,
- action: { _ in
- let canShare = CCUtility.isPermission(toCanShare: tableShare.permissions)
- let permissions = CCUtility.getPermissionsValue(byCanEdit: true, andCanCreate: true, andCanChange: true, andCanDelete: true, andCanShare: canShare, andIsFolder: isDirectory)
- self.updateSharePermissions(share: tableShare, permissions: permissions)
- }
- )
- )
- self.presentMenu(with: actions)
- }
- fileprivate func hasUploadPermission(tableShare: tableShare) -> Bool {
- let uploadPermissions = [
- NCGlobal.shared.permissionMaxFileShare,
- NCGlobal.shared.permissionMaxFolderShare,
- NCGlobal.shared.permissionDefaultFileRemoteShareNoSupportShareOption,
- NCGlobal.shared.permissionDefaultFolderRemoteShareNoSupportShareOption]
- return uploadPermissions.contains(tableShare.permissions)
- }
- func updateSharePermissions(share: tableShare, permissions: Int) {
- let updatedShare = tableShare(value: share)
- updatedShare.permissions = permissions
- networking?.updateShare(option: updatedShare)
- }
- }
|