diff --git a/app/src/androidTest/java/com/owncloud/android/operations/GetSharesForFileOperationIT.kt b/app/src/androidTest/java/com/owncloud/android/operations/GetSharesForFileOperationIT.kt
deleted file mode 100644
index 95cf916573fb..000000000000
--- a/app/src/androidTest/java/com/owncloud/android/operations/GetSharesForFileOperationIT.kt
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- *
- * Nextcloud Android client application
- *
- * @author Tobias Kaminsky
- * Copyright (C) 2021 Tobias Kaminsky
- * Copyright (C) 2021 Nextcloud GmbH
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-package com.owncloud.android.operations
-
-import com.owncloud.android.AbstractOnServerIT
-import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation
-import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation
-import com.owncloud.android.lib.resources.shares.OCShare
-import com.owncloud.android.lib.resources.shares.ShareType
-import junit.framework.TestCase
-import org.junit.Assert.assertEquals
-import org.junit.Assert.assertTrue
-import org.junit.Test
-
-@Suppress("MagicNumber")
-class GetSharesForFileOperationIT : AbstractOnServerIT() {
- @Test
- fun shares() {
- val remotePath = "/share/"
- assertTrue(CreateFolderRemoteOperation(remotePath, true).execute(client).isSuccess)
-
- // share folder to user "admin"
- TestCase.assertTrue(
- CreateShareRemoteOperation(
- remotePath,
- ShareType.USER,
- "admin",
- false,
- "",
- OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER
- )
- .execute(client).isSuccess
- )
-
- // share folder via public link
- TestCase.assertTrue(
- CreateShareRemoteOperation(
- remotePath,
- ShareType.PUBLIC_LINK,
- "",
- true,
- "",
- OCShare.READ_PERMISSION_FLAG
- )
- .execute(client).isSuccess
- )
-
- // share folder to group
- assertTrue(
- CreateShareRemoteOperation(
- remotePath,
- ShareType.GROUP,
- "users",
- false,
- "",
- OCShare.NO_PERMISSION
- )
- .execute(client).isSuccess
- )
-
- val shareResult = GetSharesForFileOperation(remotePath, false, false, storageManager).execute(client)
- assertTrue(shareResult.isSuccess)
-
- assertEquals(3, (shareResult.data as ArrayList).size)
- }
-}
diff --git a/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java b/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java
index e7867b917650..c8cd5098aa18 100644
--- a/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java
+++ b/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java
@@ -1285,25 +1285,6 @@ private void resetShareFlagsInFolder(OCFile folder) {
}
}
- private void resetShareFlagInAFile(String filePath) {
- ContentValues contentValues = new ContentValues();
- contentValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
- contentValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE);
- String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + " = ?";
- String[] whereArgs = new String[]{user.getAccountName(), filePath};
-
- if (getContentResolver() != null) {
- getContentResolver().update(ProviderTableMeta.CONTENT_URI, contentValues, where, whereArgs);
-
- } else {
- try {
- getContentProviderClient().update(ProviderTableMeta.CONTENT_URI, contentValues, where, whereArgs);
- } catch (RemoteException e) {
- Log_OC.e(TAG, "Exception in resetShareFlagsInFolder " + e.getMessage(), e);
- }
- }
- }
-
@VisibleForTesting
public void cleanShares() {
String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
@@ -1384,59 +1365,6 @@ public void removeShare(OCShare share) {
}
}
- public void saveSharesDB(List shares) {
- ArrayList operations = new ArrayList<>();
-
- // Reset flags & Remove shares for this files
- String filePath = "";
- for (OCShare share : shares) {
- if (!filePath.equals(share.getPath())) {
- filePath = share.getPath();
- resetShareFlagInAFile(filePath);
- operations = prepareRemoveSharesInFile(filePath, operations);
- }
- }
-
- // Add operations to insert shares
- operations = prepareInsertShares(shares, operations);
-
- // apply operations in batch
- if (operations.size() > 0) {
- Log_OC.d(TAG, String.format(Locale.ENGLISH, SENDING_TO_FILECONTENTPROVIDER_MSG, operations.size()));
- try {
- if (getContentResolver() != null) {
- getContentResolver().applyBatch(MainApp.getAuthority(), operations);
-
- } else {
- getContentProviderClient().applyBatch(operations);
- }
-
- } catch (OperationApplicationException | RemoteException e) {
- Log_OC.e(TAG, EXCEPTION_MSG + e.getMessage(), e);
- }
- }
- }
-
- public void removeSharesForFile(String remotePath) {
- resetShareFlagInAFile(remotePath);
- ArrayList operations = prepareRemoveSharesInFile(remotePath, new ArrayList<>());
- // apply operations in batch
- if (operations.size() > 0) {
- Log_OC.d(TAG, String.format(Locale.ENGLISH, SENDING_TO_FILECONTENTPROVIDER_MSG, operations.size()));
- try {
- if (getContentResolver() != null) {
- getContentResolver().applyBatch(MainApp.getAuthority(), operations);
-
- } else {
- getContentProviderClient().applyBatch(operations);
- }
-
- } catch (OperationApplicationException | RemoteException e) {
- Log_OC.e(TAG, EXCEPTION_MSG + e.getMessage(), e);
- }
- }
- }
-
// TOOD check if shares can be null
public void saveSharesInFolder(ArrayList shares, OCFile folder) {
resetShareFlagsInFolder(folder);
@@ -1510,24 +1438,6 @@ private ArrayList prepareRemoveSharesInFolder(
return preparedOperations;
}
- private ArrayList prepareRemoveSharesInFile(
- String filePath, ArrayList preparedOperations) {
-
- String where = ProviderTableMeta.OCSHARES_PATH + AND
- + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " = ?";
- String[] whereArgs = new String[]{filePath, user.getAccountName()};
-
- preparedOperations.add(
- ContentProviderOperation
- .newDelete(ProviderTableMeta.CONTENT_URI_SHARE)
- .withSelection(where, whereArgs)
- .build()
- );
-
- return preparedOperations;
-
- }
-
public List getSharesWithForAFile(String filePath, String accountName) {
String selection = ProviderTableMeta.OCSHARES_PATH + AND
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + AND
diff --git a/app/src/main/java/com/owncloud/android/operations/GetSharesForFileOperation.java b/app/src/main/java/com/owncloud/android/operations/GetSharesForFileOperation.java
deleted file mode 100644
index db4b56beb50b..000000000000
--- a/app/src/main/java/com/owncloud/android/operations/GetSharesForFileOperation.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * ownCloud Android client application
- *
- * @author masensio
- * 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 .
- *
- */
-
-
-package com.owncloud.android.operations;
-
-import com.owncloud.android.datamodel.FileDataStorageManager;
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.lib.resources.shares.GetSharesForFileRemoteOperation;
-import com.owncloud.android.lib.resources.shares.OCShare;
-import com.owncloud.android.operations.common.SyncOperation;
-
-import java.util.ArrayList;
-
-/**
- * Provide a list shares for a specific file.
- */
-public class GetSharesForFileOperation extends SyncOperation {
-
- private static final String TAG = GetSharesForFileOperation.class.getSimpleName();
-
- private final String path;
- private final boolean reshares;
- private final boolean subfiles;
-
- /**
- * Constructor
- *
- * @param path Path to file or folder
- * @param reshares If set to false (default), only shares from the current user are returned If set to true, all
- * shares from the given file are returned
- * @param subfiles If set to false (default), lists only the folder being shared If set to true, all shared files
- * within the folder are returned.
- */
- public GetSharesForFileOperation(String path,
- boolean reshares,
- boolean subfiles,
- FileDataStorageManager storageManager) {
- super(storageManager);
-
- this.path = path;
- this.reshares = reshares;
- this.subfiles = subfiles;
- }
-
- @Override
- protected RemoteOperationResult run(OwnCloudClient client) {
- GetSharesForFileRemoteOperation operation = new GetSharesForFileRemoteOperation(path,
- reshares,
- subfiles);
- RemoteOperationResult result = operation.execute(client);
-
- if (result.isSuccess()) {
-
- // Update DB with the response
- Log_OC.d(TAG, "File = " + path + " Share list size " + result.getData().size());
- ArrayList shares = new ArrayList();
- for (Object obj : result.getData()) {
- shares.add((OCShare) obj);
- }
-
- getStorageManager().saveSharesDB(shares);
-
- } else if (result.getCode() == RemoteOperationResult.ResultCode.SHARE_NOT_FOUND) {
- // no share on the file - remove local shares
- getStorageManager().removeSharesForFile(path);
-
- }
-
- return result;
- }
-
-}
diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java
index 7a1b96cf4a52..e581d3c5b10c 100644
--- a/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java
+++ b/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java
@@ -70,7 +70,6 @@
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.operations.CreateShareViaLinkOperation;
import com.owncloud.android.operations.CreateShareWithShareeOperation;
-import com.owncloud.android.operations.GetSharesForFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.operations.UnshareOperation;
@@ -391,16 +390,6 @@ public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationRe
} else if (operation instanceof SynchronizeFileOperation) {
onSynchronizeFileOperationFinish((SynchronizeFileOperation) operation, result);
- } else if (operation instanceof GetSharesForFileOperation) {
- if (result.isSuccess() || result.getCode() == ResultCode.SHARE_NOT_FOUND) {
- updateFileFromDB();
-
- } else {
- DisplayUtils.showSnackMessage(this,
- ErrorMessageAdapter.getErrorCauseMessage(result,
- operation,
- getResources()));
- }
}
if (operation instanceof CreateShareViaLinkOperation) {
diff --git a/app/src/main/java/com/owncloud/android/ui/activity/ShareActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/ShareActivity.java
index 83764ae75796..71e7f6011e61 100644
--- a/app/src/main/java/com/owncloud/android/ui/activity/ShareActivity.java
+++ b/app/src/main/java/com/owncloud/android/ui/activity/ShareActivity.java
@@ -40,7 +40,6 @@
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import com.owncloud.android.lib.resources.shares.ShareType;
-import com.owncloud.android.operations.GetSharesForFileOperation;
import com.owncloud.android.ui.fragment.FileDetailSharingFragment;
import com.owncloud.android.ui.fragment.FileDetailsSharingProcessFragment;
import com.owncloud.android.utils.DisplayUtils;
@@ -160,11 +159,7 @@ protected void doShareWith(String shareeName, ShareType shareType) {
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
super.onRemoteOperationFinish(operation, result);
- if (result.isSuccess() ||
- (operation instanceof GetSharesForFileOperation &&
- result.getCode() == RemoteOperationResult.ResultCode.SHARE_NOT_FOUND
- )
- ) {
+ if (result.isSuccess()) {
Log_OC.d(TAG, "Refreshing view on successful operation or finished refresh");
refreshSharesFromStorageManager();
}