Przeglądaj źródła

Merge pull request #1247 from vnidens/resharing_permissions

UX: Enhance Resharing dialogs are respecting resharing permissions
Andy Scherzinger 7 lat temu
rodzic
commit
0f02b1d8f7

+ 14 - 7
src/main/java/com/owncloud/android/datamodel/OCFile.java

@@ -1,4 +1,4 @@
-/**
+/*
  *   ownCloud Android client application
  *
  *   @author Bartek Przybylski
@@ -56,6 +56,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     };
 
     private final static String PERMISSION_SHARED_WITH_ME = "S";    // TODO move to better location
+    private final static String PERMISSION_CAN_RESHARE = "R";
 
     public static final String PATH_SEPARATOR = "/";
     public static final String ROOT_PATH = PATH_SEPARATOR;
@@ -103,7 +104,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Exportable URI to the local path of the file contents, if stored in the device.
-     *
+     * <p>
      * Cached after first call, until changed.
      */
     private Uri mExposedFileUri;
@@ -111,7 +112,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * Create new {@link OCFile} with given path.
-     * <p/>
+     * <p>
      * The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'.
      *
      * @param path The remote path of the file.
@@ -285,15 +286,15 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
             if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
                 // TODO - use FileProvider with any Android version, with deeper testing -> 2.2.0
                 mExposedFileUri = Uri.parse(
-                    ContentResolver.SCHEME_FILE + "://" + WebdavUtils.encodePath(mLocalPath)
+                        ContentResolver.SCHEME_FILE + "://" + WebdavUtils.encodePath(mLocalPath)
                 );
             } else {
                 // Use the FileProvider to get a content URI
                 try {
                     mExposedFileUri = FileProvider.getUriForFile(
-                        context,
-                        context.getString(R.string.file_provider_authority),
-                        new File(mLocalPath)
+                            context,
+                            context.getString(R.string.file_provider_authority),
+                            new File(mLocalPath)
                     );
                 } catch (IllegalArgumentException e) {
                     Log_OC.e(TAG, "File can't be exported");
@@ -502,6 +503,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     /**
      * get remote path of parent file
+     *
      * @return remote path
      */
     public String getParentRemotePath() {
@@ -687,4 +689,9 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         return (permissions != null && permissions.contains(PERMISSION_SHARED_WITH_ME));
     }
 
+    public boolean canReshare() {
+        String permissions = getPermissions();
+        return permissions != null && permissions.contains(PERMISSION_CAN_RESHARE);
+    }
+
 }

+ 48 - 23
src/main/java/com/owncloud/android/ui/fragment/EditShareFragment.java

@@ -1,22 +1,21 @@
-/**
- *   ownCloud Android client application
+/*
+ * ownCloud Android client application
  *
- *   @author masensio
- *   @author David A. Velasco
- *   Copyright (C) 2015 ownCloud Inc.
+ * @author masensio
+ * @author David A. Velasco
+ * Copyright (C) 2015 ownCloud Inc.
  *
- *   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License version 2,
- *   as published by the Free Software Foundation.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 package com.owncloud.android.ui.fragment;
@@ -43,6 +42,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.resources.shares.OCShare;
 import com.owncloud.android.lib.resources.shares.SharePermissionsBuilder;
 import com.owncloud.android.lib.resources.shares.ShareType;
+import com.owncloud.android.lib.resources.status.OCCapability;
 import com.owncloud.android.lib.resources.status.OwnCloudVersion;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.utils.AnalyticsUtils;
@@ -75,9 +75,14 @@ public class EditShareFragment extends Fragment {
     /** Account of the shared file, received as a parameter in construction time */
     private Account mAccount;
 
+    /**
+     * Capabilities of the server.
+     */
+    private OCCapability mCapabilities;
+
     /** Listener for changes on privilege checkboxes */
     private CompoundButton.OnCheckedChangeListener mOnPrivilegeChangeListener;
-    
+
     /**
      * Public factory method to create new EditShareFragment instances.
      *
@@ -109,6 +114,9 @@ public class EditShareFragment extends Fragment {
             /* OC account holding the shared file, received as a parameter in construction time */
             mAccount = getArguments().getParcelable(ARG_ACCOUNT);
         }
+
+        FileDataStorageManager storageManager = new FileDataStorageManager(mAccount, getContext().getContentResolver());
+        mCapabilities = storageManager.getCapability(mAccount.name);
     }
 
 
@@ -132,7 +140,7 @@ public class EditShareFragment extends Fragment {
         // Inflate the layout for this fragment
         View view = inflater.inflate(R.layout.edit_share_layout, container, false);
 
-        ((TextView)view.findViewById(R.id.editShareTitle)).setText(
+        ((TextView) view.findViewById(R.id.editShareTitle)).setText(
                 getResources().getString(R.string.share_with_edit_title, mShare.getSharedWithDisplayName()));
 
         View headerDivider = view.findViewById(R.id.share_header_divider);
@@ -144,6 +152,20 @@ public class EditShareFragment extends Fragment {
         return view;
     }
 
+    /**
+     * Get known server capabilities from DB
+     * <p/>
+     * Depends on the parent Activity provides a {@link com.owncloud.android.datamodel.FileDataStorageManager}
+     * instance ready to use. If not ready, does nothing.
+     */
+    public void refreshCapabilitiesFromDB() {
+        if (getActivity() instanceof FileActivity) {
+            FileActivity fileActivity = ((FileActivity) getActivity());
+            if (fileActivity.getStorageManager() != null) {
+                mCapabilities = fileActivity.getStorageManager().getCapability(mAccount.name);
+            }
+        }
+    }
 
     /**
      * Updates the UI with the current permissions in the edited {@OCShare}
@@ -167,7 +189,10 @@ public class EditShareFragment extends Fragment {
 
             if (isFederated) {
                 shareSwitch.setVisibility(View.INVISIBLE);
+            } else if (mCapabilities != null && mCapabilities.getFilesSharingResharing().isFalse()) {
+                shareSwitch.setVisibility(View.GONE);
             }
+
             shareSwitch.setChecked((sharePermissions & OCShare.SHARE_PERMISSION_FLAG) > 0);
 
             SwitchCompat switchCompat = (SwitchCompat) editShareView.findViewById(R.id.canEditSwitch);
@@ -260,7 +285,7 @@ public class EditShareFragment extends Fragment {
             /// else, getView() cannot be NULL
 
             CompoundButton subordinate;
-            switch(compound.getId()) {
+            switch (compound.getId()) {
                 case R.id.canShareSwitch:
                     Log_OC.v(TAG, "canShareCheckBox toggled to " + isChecked);
                     updatePermissionsToShare();
@@ -279,7 +304,7 @@ public class EditShareFragment extends Fragment {
                                     subordinate = (CompoundButton) getView().findViewById(sSubordinateCheckBoxIds[i]);
                                     subordinate.setVisibility(View.VISIBLE);
                                     if (!subordinate.isChecked() &&
-                                        !mFile.isSharedWithMe()) {          // see (1)
+                                            !mFile.isSharedWithMe()) {          // see (1)
                                         toggleDisablingListener(subordinate);
                                     }
                                 }
@@ -304,8 +329,8 @@ public class EditShareFragment extends Fragment {
                         }
                     }
 
-                    if(!(mFile.isFolder() && isChecked && mFile.isSharedWithMe())       // see (1)
-                        || isFederated ) {
+                    if (!(mFile.isFolder() && isChecked && mFile.isSharedWithMe())       // see (1)
+                            || isFederated) {
                         updatePermissionsToShare();
                     }
 
@@ -356,7 +381,7 @@ public class EditShareFragment extends Fragment {
                 }
             } else {
                 boolean allDisabled = true;
-                for (int i=0; allDisabled && i<sSubordinateCheckBoxIds.length; i++) {
+                for (int i = 0; allDisabled && i < sSubordinateCheckBoxIds.length; i++) {
                     allDisabled &=
                             sSubordinateCheckBoxIds[i] == subordinateCheckBoxView.getId() ||
                                     !((CheckBox) getView().findViewById(sSubordinateCheckBoxIds[i])).isChecked()
@@ -364,7 +389,7 @@ public class EditShareFragment extends Fragment {
                 }
                 if (canEditCompound.isChecked() && allDisabled) {
                     toggleDisablingListener(canEditCompound);
-                    for (int i=0; i<sSubordinateCheckBoxIds.length; i++) {
+                    for (int i = 0; i < sSubordinateCheckBoxIds.length; i++) {
                         getView().findViewById(sSubordinateCheckBoxIds[i]).setVisibility(View.GONE);
                     }
                 }

+ 9 - 0
src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -283,6 +283,15 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
             item.setVisible(false);
             item.setEnabled(false);
         }
+
+        if(getFile().isSharedWithMe() && !getFile().canReshare()){
+            // additional restriction for this fragment
+            item = menu.findItem(R.id.action_share_file);
+            if(item != null){
+                item.setVisible(false);
+                item.setEnabled(false);
+            }
+        }
     }
 
 

+ 6 - 1
src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -37,6 +37,7 @@ import android.preference.PreferenceManager;
 import android.support.annotation.Nullable;
 import android.support.annotation.StringRes;
 import android.support.design.widget.BottomNavigationView;
+import android.support.design.widget.Snackbar;
 import android.support.v4.widget.DrawerLayout;
 import android.support.v4.widget.SwipeRefreshLayout;
 import android.util.SparseBooleanArray;
@@ -912,7 +913,11 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
             OCFile singleFile = checkedFiles.get(0);
             switch (menuId) {
                 case R.id.action_share_file: {
-                    mContainerActivity.getFileOperationsHelper().showShareFile(singleFile);
+                    if(singleFile.isSharedWithMe() && !singleFile.canReshare()){
+                        Snackbar.make(getView(), R.string.resharing_is_not_allowed, Snackbar.LENGTH_LONG).show();
+                    } else {
+                        mContainerActivity.getFileOperationsHelper().showShareFile(singleFile);
+                    }
                     return true;
                 }
                 case R.id.action_open_file_with: {

+ 9 - 0
src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java

@@ -332,6 +332,15 @@ public class PreviewImageFragment extends FileFragment {
             item.setEnabled(false);
         }
 
+        if(getFile().isSharedWithMe() && !getFile().canReshare()){
+            // additional restriction for this fragment
+            item = menu.findItem(R.id.action_share_file);
+            if(item != null){
+                item.setVisible(false);
+                item.setEnabled(false);
+            }
+        }
+
     }
 
 

+ 9 - 0
src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java

@@ -401,6 +401,15 @@ public class PreviewMediaFragment extends FileFragment implements
             item.setEnabled(false);
         }
 
+        if(getFile().isSharedWithMe() && !getFile().canReshare()){
+            // additional restriction for this fragment
+            item = menu.findItem(R.id.action_share_file);
+            if(item != null){
+                item.setVisible(false);
+                item.setEnabled(false);
+            }
+        }
+
     }
 
 

+ 9 - 0
src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.java

@@ -351,6 +351,15 @@ public class PreviewTextFragment extends FileFragment {
             item.setEnabled(false);
         }
 
+        if(getFile().isSharedWithMe() && !getFile().canReshare()){
+            // additional restriction for this fragment
+            item = menu.findItem(R.id.action_share_file);
+            if(item != null){
+                item.setVisible(false);
+                item.setEnabled(false);
+            }
+        }
+
     }
 
     /**

+ 1 - 0
src/main/res/values/strings.xml

@@ -697,4 +697,5 @@
     <string name="empty" translatable="false"/>
     <string name="test_server_button">Test server connection</string>
     <string name="info_separator" translatable="false">,</string>
+    <string name="resharing_is_not_allowed">Resharing is not allowed</string>
 </resources>