mirror of https://github.com/nextcloud/android
Remove GetSharesForFileOperation class used only by tests
Signed-off-by: Dariusz Olszewski <starypatyk@users.noreply.github.com>
This commit is contained in:
parent
9fd027fbd6
commit
1503908ad3
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<OCShare>).size)
|
||||
}
|
||||
}
|
|
@ -1285,25 +1285,6 @@ public class FileDataStorageManager {
|
|||
}
|
||||
}
|
||||
|
||||
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 class FileDataStorageManager {
|
|||
}
|
||||
}
|
||||
|
||||
public void saveSharesDB(List<OCShare> shares) {
|
||||
ArrayList<ContentProviderOperation> 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<ContentProviderOperation> 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<OCShare> shares, OCFile folder) {
|
||||
resetShareFlagsInFolder(folder);
|
||||
|
@ -1510,24 +1438,6 @@ public class FileDataStorageManager {
|
|||
return preparedOperations;
|
||||
}
|
||||
|
||||
private ArrayList<ContentProviderOperation> prepareRemoveSharesInFile(
|
||||
String filePath, ArrayList<ContentProviderOperation> 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<OCShare> getSharesWithForAFile(String filePath, String accountName) {
|
||||
String selection = ProviderTableMeta.OCSHARES_PATH + AND
|
||||
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + AND
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
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<OCShare> shares = new ArrayList<OCShare>();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -70,7 +70,6 @@ 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.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 abstract class FileActivity extends DrawerActivity
|
|||
} 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) {
|
||||
|
|
|
@ -40,7 +40,6 @@ import com.owncloud.android.lib.common.utils.Log_OC;
|
|||
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 @@ public class ShareActivity extends FileActivity {
|
|||
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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue