Эх сурвалжийг харах

Send the right ShareType to the share operation if it is FEDERATED

Juan Carlos González Cabrero 9 жил өмнө
parent
commit
f60aa06c2d

+ 1 - 1
src/com/owncloud/android/operations/CreateShareWithShareeOperation.java

@@ -60,7 +60,7 @@ public class CreateShareWithShareeOperation extends SyncOperation {
      *                      https://doc.owncloud.org/server/8.2/developer_manual/core/ocs-share-api.html .
      */
     public CreateShareWithShareeOperation(String path, String shareeName, ShareType shareType, int permissions) {
-        if (!ShareType.USER.equals(shareType) && !ShareType.GROUP.equals(shareType)) {
+        if (!ShareType.USER.equals(shareType) && !ShareType.GROUP.equals(shareType) && !ShareType.FEDERATED.equals(shareType)) {
             throw new IllegalArgumentException("Illegal share type " + shareType);
         }
         mPath = path;

+ 9 - 3
src/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java

@@ -40,6 +40,7 @@ import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.resources.shares.GetRemoteShareesOperation;
+import com.owncloud.android.lib.resources.shares.ShareType;
 import com.owncloud.android.utils.ErrorMessageAdapter;
 
 import org.json.JSONException;
@@ -70,9 +71,14 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
 
     public static final String AUTHORITY = UsersAndGroupsSearchProvider.class.getCanonicalName();
     public static final String ACTION_SHARE_WITH = AUTHORITY + ".action.SHARE_WITH";
-    public static final String DATA_USER = AUTHORITY + ".data.user";
-    public static final String DATA_GROUP = AUTHORITY + ".data.group";
-    public static final String DATA_REMOTE = AUTHORITY + ".data.remote";
+
+    public static final String USER = "user";
+    public static final String GROUP = "group";
+    public static final String REMOTE = "remote";
+
+    public static final String DATA_USER = AUTHORITY + ".data." + USER;
+    public static final String DATA_GROUP = AUTHORITY + ".data." + GROUP;
+    public static final String DATA_REMOTE = AUTHORITY + ".data." + REMOTE;
 
     private UriMatcher mUriMatcher;
 

+ 50 - 35
src/com/owncloud/android/ui/activity/ShareActivity.java

@@ -1,22 +1,21 @@
 /**
- *   ownCloud Android client application
- *
- *   @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 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/>.
+ * ownCloud Android client application
  *
+ * @author masensio
+ * @author David A. Velasco
+ * Copyright (C) 2015 ownCloud Inc.
+ * <p/>
+ * 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.
+ * <p/>
+ * 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.
+ * <p/>
+ * 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.activity;
@@ -30,18 +29,17 @@ import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentTransaction;
 
 import com.owncloud.android.R;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.lib.common.operations.RemoteOperation;
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.lib.resources.shares.OCShare;
+import com.owncloud.android.lib.resources.shares.ShareType;
 import com.owncloud.android.operations.CreateShareViaLinkOperation;
 import com.owncloud.android.operations.GetSharesForFileOperation;
 import com.owncloud.android.operations.UnshareOperation;
 import com.owncloud.android.operations.UpdateSharePermissionsOperation;
 import com.owncloud.android.providers.UsersAndGroupsSearchProvider;
-
-import com.owncloud.android.lib.common.operations.RemoteOperation;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.lib.resources.shares.OCShare;
-import com.owncloud.android.lib.resources.shares.ShareType;
 import com.owncloud.android.ui.dialog.ShareLinkToDialog;
 import com.owncloud.android.ui.fragment.EditShareFragment;
 import com.owncloud.android.ui.fragment.SearchShareesFragment;
@@ -63,7 +61,9 @@ public class ShareActivity extends FileActivity
     private static final String TAG_SEARCH_FRAGMENT = "SEARCH_USER_AND_GROUPS_FRAGMENT";
     private static final String TAG_EDIT_SHARE_FRAGMENT = "EDIT_SHARE_FRAGMENT";
 
-    /** Tag for dialog */
+    /**
+     * Tag for dialog
+     */
     private static final String FTAG_CHOOSER_DIALOG = "CHOOSER_DIALOG";
 
     @Override
@@ -108,7 +108,7 @@ public class ShareActivity extends FileActivity
             String shareWith = dataString.substring(dataString.lastIndexOf('/') + 1);
             doShareWith(
                     shareWith,
-                    UsersAndGroupsSearchProvider.DATA_GROUP.equals(data.getAuthority())
+                    data.getAuthority()
             );
 
         } else {
@@ -116,11 +116,26 @@ public class ShareActivity extends FileActivity
         }
     }
 
-    private void doShareWith(String shareeName, boolean isGroup) {
+    private void doShareWith(String shareeName, String dataAuthority) {
+
+        int lastPointIndex = dataAuthority.lastIndexOf(".");
+        String type = dataAuthority.substring(lastPointIndex + 1);
+        ShareType shareType = null;
+        switch (type) {
+            case UsersAndGroupsSearchProvider.USER:
+                shareType = ShareType.USER;
+                break;
+            case UsersAndGroupsSearchProvider.GROUP:
+                shareType = ShareType.GROUP;
+                break;
+            case UsersAndGroupsSearchProvider.REMOTE:
+                shareType = ShareType.FEDERATED;
+                break;
+        }
         getFileOperationsHelper().shareFileWithSharee(
                 getFile(),
                 shareeName,
-                (isGroup ? ShareType.GROUP : ShareType.USER),
+                shareType,
                 getAppropiatePermissions()
         );
     }
@@ -191,10 +206,10 @@ public class ShareActivity extends FileActivity
         super.onRemoteOperationFinish(operation, result);
 
         if (result.isSuccess() ||
-            (operation instanceof GetSharesForFileOperation &&
-                result.getCode() == RemoteOperationResult.ResultCode.SHARE_NOT_FOUND
-            )
-        ) {
+                (operation instanceof GetSharesForFileOperation &&
+                        result.getCode() == RemoteOperationResult.ResultCode.SHARE_NOT_FOUND
+                )
+                ) {
             Log_OC.d(TAG, "Refreshing view on successful operation or finished refresh");
             refreshSharesFromStorageManager();
         }
@@ -245,7 +260,7 @@ public class ShareActivity extends FileActivity
 
         EditShareFragment editShareFragment = getEditShareFragment();
         if (editShareFragment != null &&
-                editShareFragment.isAdded())    {
+                editShareFragment.isAdded()) {
             editShareFragment.refreshUiFromDB();
         }
 
@@ -254,7 +269,7 @@ public class ShareActivity extends FileActivity
     /**
      * Shortcut to get access to the {@link ShareFileFragment} instance, if any
      *
-     * @return  A {@link ShareFileFragment} instance, or null
+     * @return A {@link ShareFileFragment} instance, or null
      */
     private ShareFileFragment getShareFileFragment() {
         return (ShareFileFragment) getSupportFragmentManager().findFragmentByTag(TAG_SHARE_FRAGMENT);
@@ -263,7 +278,7 @@ public class ShareActivity extends FileActivity
     /**
      * Shortcut to get access to the {@link SearchShareesFragment} instance, if any
      *
-     * @return  A {@link SearchShareesFragment} instance, or null
+     * @return A {@link SearchShareesFragment} instance, or null
      */
     private SearchShareesFragment getSearchFragment() {
         return (SearchShareesFragment) getSupportFragmentManager().findFragmentByTag(TAG_SEARCH_FRAGMENT);
@@ -272,7 +287,7 @@ public class ShareActivity extends FileActivity
     /**
      * Shortcut to get access to the {@link EditShareFragment} instance, if any
      *
-     * @return  A {@link EditShareFragment} instance, or null
+     * @return A {@link EditShareFragment} instance, or null
      */
     private EditShareFragment getEditShareFragment() {
         return (EditShareFragment) getSupportFragmentManager().findFragmentByTag(TAG_EDIT_SHARE_FRAGMENT);