Adapt UnshareLinkOperation to support also ShareType: USER or GROUP. UnshareLinkOperation --> UnshareOperation

This commit is contained in:
masensio 2015-10-20 13:36:09 +02:00 committed by David A. Velasco
parent 043d2128ad
commit a00b272903
8 changed files with 63 additions and 33 deletions

View file

@ -974,26 +974,29 @@ public class FileDataStorageManager {
} }
public OCShare getFirstShareByPathAndType(String path, ShareType type) { public OCShare getFirstShareByPathAndType(String path, ShareType type, String shareWith) {
Cursor c = null; Cursor c = null;
String selection = ProviderTableMeta.OCSHARES_PATH + "=? AND "
+ ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND "
+ ProviderTableMeta.OCSHARES_SHARE_WITH + "=? AND "
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" ;
String [] selectionArgs = new String[]{path, Integer.toString(type.getValue()),
shareWith, mAccount.name};
if (getContentResolver() != null) { if (getContentResolver() != null) {
c = getContentResolver().query( c = getContentResolver().query(
ProviderTableMeta.CONTENT_URI_SHARE, ProviderTableMeta.CONTENT_URI_SHARE,
null, null,
ProviderTableMeta.OCSHARES_PATH + "=? AND " selection, selectionArgs,
+ ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND "
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
new String[]{path, Integer.toString(type.getValue()), mAccount.name},
null); null);
} else { } else {
try { try {
c = getContentProviderClient().query( c = getContentProviderClient().query(
ProviderTableMeta.CONTENT_URI_SHARE, ProviderTableMeta.CONTENT_URI_SHARE,
null, null,
ProviderTableMeta.OCSHARES_PATH + "=? AND " selection, selectionArgs,
+ ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND "
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
new String[]{path, Integer.toString(type.getValue()), mAccount.name},
null); null);
} catch (RemoteException e) { } catch (RemoteException e) {

View file

@ -39,6 +39,7 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.network.WebdavUtils;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.services.OperationsService; import com.owncloud.android.services.OperationsService;
import com.owncloud.android.services.observer.FileObserverService; import com.owncloud.android.services.observer.FileObserverService;
@ -212,6 +213,8 @@ public class FileOperationsHelper {
service.setAction(OperationsService.ACTION_UNSHARE); service.setAction(OperationsService.ACTION_UNSHARE);
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
service.putExtra(OperationsService.EXTRA_SHARE_TYPE, ShareType.PUBLIC_LINK);
service.putExtra(OperationsService.EXTRA_SHARE_WITH, "");
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service); mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext(). mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().

View file

@ -35,20 +35,26 @@ import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.operations.common.SyncOperation;
import java.util.ArrayList;
/** /**
* Unshare file/folder * Unshare file/folder
* Save the data in Database * Save the data in Database
*/ */
public class UnshareLinkOperation extends SyncOperation { public class UnshareOperation extends SyncOperation {
private static final String TAG = UnshareLinkOperation.class.getSimpleName(); private static final String TAG = UnshareOperation.class.getSimpleName();
private String mRemotePath; private String mRemotePath;
private ShareType mShareType;
private String mShareWith;
private Context mContext; private Context mContext;
public UnshareOperation(String remotePath, ShareType shareType, String shareWith,
public UnshareLinkOperation(String remotePath, Context context) { Context context) {
mRemotePath = remotePath; mRemotePath = remotePath;
mShareType = shareType;
mShareWith = shareWith;
mContext = context; mContext = context;
} }
@ -58,7 +64,7 @@ public class UnshareLinkOperation extends SyncOperation {
// Get Share for a file // Get Share for a file
OCShare share = getStorageManager().getFirstShareByPathAndType(mRemotePath, OCShare share = getStorageManager().getFirstShareByPathAndType(mRemotePath,
ShareType.PUBLIC_LINK); mShareType, mShareWith);
if (share != null) { if (share != null) {
RemoveRemoteShareOperation operation = RemoveRemoteShareOperation operation =
@ -69,8 +75,19 @@ public class UnshareLinkOperation extends SyncOperation {
Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted"); Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted");
OCFile file = getStorageManager().getFileByPath(mRemotePath); OCFile file = getStorageManager().getFileByPath(mRemotePath);
if (mShareType == ShareType.PUBLIC_LINK) {
file.setShareViaLink(false); file.setShareViaLink(false);
file.setPublicLink(""); file.setPublicLink("");
} else if (mShareType == ShareType.USER || mShareType == ShareType.GROUP){
// Check if it is the last share
ArrayList <OCShare> sharesWith = getStorageManager().
getSharesWithForAFile(mRemotePath,
getStorageManager().getAccount().name);
if (sharesWith.size() == 1) {
file.setShareViaUsers(false);
}
}
getStorageManager().saveFile(file); getStorageManager().saveFile(file);
getStorageManager().removeShare(share); getStorageManager().removeShare(share);

View file

@ -62,7 +62,7 @@ import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.SynchronizeFolderOperation; import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.operations.UnshareOperation;
import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.operations.common.SyncOperation;
import java.io.IOException; import java.io.IOException;
@ -88,6 +88,8 @@ public class OperationsService extends Service {
public static final String EXTRA_NEW_PARENT_PATH = "NEW_PARENT_PATH"; public static final String EXTRA_NEW_PARENT_PATH = "NEW_PARENT_PATH";
public static final String EXTRA_FILE = "FILE"; public static final String EXTRA_FILE = "FILE";
public static final String EXTRA_PASSWORD_SHARE = "PASSWORD_SHARE"; public static final String EXTRA_PASSWORD_SHARE = "PASSWORD_SHARE";
public static final String EXTRA_SHARE_TYPE = "SHARE_TYPE";
public static final String EXTRA_SHARE_WITH = "SHARE_WITH";
public static final String EXTRA_COOKIE = "COOKIE"; public static final String EXTRA_COOKIE = "COOKIE";
@ -560,9 +562,14 @@ public class OperationsService extends Service {
} else if (action.equals(ACTION_UNSHARE)) { // Unshare file } else if (action.equals(ACTION_UNSHARE)) { // Unshare file
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
ShareType shareType = (ShareType) operationIntent.
getSerializableExtra(EXTRA_SHARE_TYPE);
String shareWith = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
if (remotePath.length() > 0) { if (remotePath.length() > 0) {
operation = new UnshareLinkOperation( operation = new UnshareOperation(
remotePath, remotePath,
shareType,
shareWith,
OperationsService.this); OperationsService.this);
} }

View file

@ -71,7 +71,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.operations.CreateShareOperation; import com.owncloud.android.operations.CreateShareOperation;
import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.SynchronizeFolderOperation; import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.operations.UnshareOperation;
import com.owncloud.android.services.OperationsService; import com.owncloud.android.services.OperationsService;
import com.owncloud.android.services.OperationsService.OperationsServiceBinder; import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
import com.owncloud.android.ui.NavigationDrawerItem; import com.owncloud.android.ui.NavigationDrawerItem;
@ -732,8 +732,8 @@ public class FileActivity extends AppCompatActivity
} else if (operation instanceof CreateShareOperation) { } else if (operation instanceof CreateShareOperation) {
onCreateShareOperationFinish((CreateShareOperation) operation, result); onCreateShareOperationFinish((CreateShareOperation) operation, result);
} else if (operation instanceof UnshareLinkOperation) { } else if (operation instanceof UnshareOperation) {
onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result); onUnshareLinkOperationFinish((UnshareOperation)operation, result);
} else if (operation instanceof SynchronizeFolderOperation) { } else if (operation instanceof SynchronizeFolderOperation) {
onSynchronizeFolderOperationFinish((SynchronizeFolderOperation)operation, result); onSynchronizeFolderOperationFinish((SynchronizeFolderOperation)operation, result);
@ -790,7 +790,7 @@ public class FileActivity extends AppCompatActivity
} }
private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, private void onUnshareLinkOperationFinish(UnshareOperation operation,
RemoteOperationResult result) { RemoteOperationResult result) {
dismissLoadingDialog(); dismissLoadingDialog();

View file

@ -85,7 +85,7 @@ import com.owncloud.android.operations.RefreshFolderOperation;
import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.operations.UnshareOperation;
import com.owncloud.android.services.observer.FileObserverService; import com.owncloud.android.services.observer.FileObserverService;
import com.owncloud.android.syncadapter.FileSyncAdapter; import com.owncloud.android.syncadapter.FileSyncAdapter;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
@ -1361,8 +1361,8 @@ public class FileDisplayActivity extends HookActivity
} else if (operation instanceof CreateShareOperation) { } else if (operation instanceof CreateShareOperation) {
onCreateShareOperationFinish((CreateShareOperation) operation, result); onCreateShareOperationFinish((CreateShareOperation) operation, result);
} else if (operation instanceof UnshareLinkOperation) { } else if (operation instanceof UnshareOperation) {
onUnshareLinkOperationFinish((UnshareLinkOperation) operation, result); onUnshareLinkOperationFinish((UnshareOperation) operation, result);
} else if (operation instanceof MoveFileOperation) { } else if (operation instanceof MoveFileOperation) {
onMoveFileOperationFinish((MoveFileOperation) operation, result); onMoveFileOperationFinish((MoveFileOperation) operation, result);
@ -1380,7 +1380,7 @@ public class FileDisplayActivity extends HookActivity
} }
} }
private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, private void onUnshareLinkOperationFinish(UnshareOperation operation,
RemoteOperationResult result) { RemoteOperationResult result) {
if (result.isSuccess()) { if (result.isSuccess()) {
refreshShowDetails(); refreshShowDetails();

View file

@ -56,7 +56,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.operations.CreateShareOperation; import com.owncloud.android.operations.CreateShareOperation;
import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.operations.UnshareOperation;
import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.activity.ShareActivity; import com.owncloud.android.ui.activity.ShareActivity;
@ -232,8 +232,8 @@ public class PreviewImageActivity extends FileActivity implements
if (operation instanceof CreateShareOperation) { if (operation instanceof CreateShareOperation) {
onCreateShareOperationFinish((CreateShareOperation) operation, result); onCreateShareOperationFinish((CreateShareOperation) operation, result);
} else if (operation instanceof UnshareLinkOperation) { } else if (operation instanceof UnshareOperation) {
onUnshareLinkOperationFinish((UnshareLinkOperation) operation, result); onUnshareLinkOperationFinish((UnshareOperation) operation, result);
} else if (operation instanceof RemoveFileOperation) { } else if (operation instanceof RemoveFileOperation) {
finish(); finish();
@ -244,7 +244,7 @@ public class PreviewImageActivity extends FileActivity implements
} }
private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, private void onUnshareLinkOperationFinish(UnshareOperation operation,
RemoteOperationResult result) { RemoteOperationResult result) {
if (result.isSuccess()) { if (result.isSuccess()) {
OCFile file = getStorageManager().getFileByPath(getFile().getRemotePath()); OCFile file = getStorageManager().getFileByPath(getFile().getRemotePath());

View file

@ -36,7 +36,7 @@ import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.SynchronizeFolderOperation; import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.operations.UnshareOperation;
import com.owncloud.android.operations.UploadFileOperation; import com.owncloud.android.operations.UploadFileOperation;
import org.apache.commons.httpclient.ConnectTimeoutException; import org.apache.commons.httpclient.ConnectTimeoutException;
@ -187,7 +187,7 @@ public class ErrorMessageAdapter {
message = res.getString(R.string.share_link_file_error); message = res.getString(R.string.share_link_file_error);
} }
} else if (operation instanceof UnshareLinkOperation) { } else if (operation instanceof UnshareOperation) {
if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND
message = res.getString(R.string.unshare_link_file_no_exist); message = res.getString(R.string.unshare_link_file_no_exist);