Browse Source

Fix share permission with restricted reshare permissions

- Don't allow creating shares if reshaping is disabled

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 years ago
parent
commit
6df4786156

+ 1 - 1
iOSClient/Menu/NCShare+Menu.swift

@@ -28,7 +28,7 @@ extension NCShare {
 
         var actions = [NCMenuAction]()
 
-        if share.shareType == 3 {
+        if share.shareType == 3, canReshare {
             actions.append(
                 NCMenuAction(
                     title: NSLocalizedString("_share_add_sharelink_", comment: ""),

+ 4 - 2
iOSClient/Share/Advanced/NCShareAdvancePermission.swift

@@ -99,7 +99,9 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg
 
     override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
         if section == 0 {
-            return shareConfig.parentPermission != 31 ? shareConfig.permissions.count + 1 : shareConfig.permissions.count
+            // check reshare permission, if restricted add note
+            let maxPermission = metadata.directory ? NCGlobal.shared.permissionMaxFolderShare : NCGlobal.shared.permissionMaxFileShare
+            return shareConfig.parentPermission != maxPermission ? shareConfig.permissions.count + 1 : shareConfig.permissions.count
         } else if section == 1 {
             return shareConfig.advanced.count
         } else { return 0 }
@@ -108,7 +110,7 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg
     override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         guard let cell = shareConfig.cellFor(indexPath: indexPath) else {
             let noteCell = UITableViewCell(style: .subtitle, reuseIdentifier: "noteCell")
-            noteCell.detailTextLabel?.text = "Reshare permissions restricted"
+            noteCell.detailTextLabel?.text = NSLocalizedString("_share_reshare_restricted_", comment: "")
             noteCell.detailTextLabel?.isEnabled = false
             noteCell.isUserInteractionEnabled = false
             return noteCell

+ 2 - 2
iOSClient/Share/NCShare.storyboard

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Ts3-RO-A9l">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Ts3-RO-A9l">
     <device id="retina5_5" orientation="portrait" appearance="light"/>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
         <capability name="Safe area layout guides" minToolsVersion="9.0"/>
         <capability name="System colors in document resources" minToolsVersion="11.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>

+ 14 - 3
iOSClient/Share/NCShare.swift

@@ -49,6 +49,11 @@ class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent
     public var sharingEnabled = true
     public var height: CGFloat = 0
 
+    var canReshare: Bool {
+        guard let metadata = metadata else { return true }
+        return ((metadata.sharePermissionsCollaborationServices & NCGlobal.shared.permissionShareShare) != 0)
+    }
+
     var shares: (firstShareLink: tableShare?, share: [tableShare]?) = (nil, nil)
 
     private var dropDown = DropDown()
@@ -111,13 +116,18 @@ class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent
     func checkSharedWithYou() {
         guard let appDelegate = self.appDelegate, let metadata = metadata, !metadata.ownerId.isEmpty, metadata.ownerId != appDelegate.userId else { return }
 
+        if !canReshare {
+            searchField.isEnabled = false
+            searchField.placeholder = NSLocalizedString("_share_reshare_disabled_", comment: "")
+        }
+
         searchFieldTopConstraint.constant = 65
         sharedWithYouByView.isHidden = false
         sharedWithYouByLabel.text = NSLocalizedString("_shared_with_you_by_", comment: "") + " " + metadata.ownerDisplayName
         sharedWithYouByImage.image = NCUtility.shared.loadUserImage(
             for: metadata.ownerId,
-               displayName: metadata.ownerDisplayName,
-               userBaseUrl: appDelegate)
+            displayName: metadata.ownerDisplayName,
+            userBaseUrl: appDelegate)
         let shareAction = UITapGestureRecognizer(target: self, action: #selector(openShareProfile))
         sharedWithYouByImage.addGestureRecognizer(shareAction)
         let shareLabelAction = UITapGestureRecognizer(target: self, action: #selector(openShareProfile))
@@ -289,7 +299,8 @@ extension NCShare: UITableViewDataSource {
     }
 
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        guard section != 0 else { return 2 }
+        // don't allow link creation if reshare is disabled
+        guard section != 0 else { return shares.firstShareLink != nil || canReshare ? 2 : 1 }
         return shares.share?.count ?? 0
     }
 

+ 3 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -611,6 +611,9 @@
 "_share_unshare_"               = "Unshare";
 "_share_internal_link_"         = "Internal link";
 "_share_internal_link_des_"     = "Only works for users with access to this folder";
+"_share_reshare_disabled_"      = "You are not allowed to reshare this file / folder";
+"_share_reshare_restricted_"    = "Note: You only have limited prmission to reshare this file / folder";
+
 "_no_transfer_"                     = "No transfers yet";
 "_no_transfer_sub_"                 = "Uploads and downloads from this device will show up here";
 "_no_activity_"                     = "No activity yet";