Set or clear password to protect public link in ShareFileFragment

This commit is contained in:
David A. Velasco 2015-11-05 13:12:38 +01:00
parent 19cf573db0
commit 729a9b7c77
12 changed files with 330 additions and 49 deletions

View file

@ -288,6 +288,8 @@
<string name="share_link_file_error">An error occurred while trying to share this file or folder</string>
<string name="unshare_link_file_no_exist">Unable to unshare. Please check whether the file exists</string>
<string name="unshare_link_file_error">An error occurred while trying to unshare this file or folder</string>
<string name="update_link_file_no_exist">Unable to update. Please check whether the file exists </string>
<string name="update_link_file_error">An error occurred while trying to update the shared link</string>
<string name="share_link_password_title">Enter a password</string>
<string name="share_link_empty_password">You must enter a password</string>
@ -309,6 +311,7 @@
<string name="forbidden_permissions_delete">to delete this file</string>
<string name="share_link_forbidden_permissions">to share this file</string>
<string name="unshare_link_forbidden_permissions">to unshare this file</string>
<string name="update_link_forbidden_permissions">to update this shared link</string>
<string name="forbidden_permissions_create">to create the file</string>
<string name="uploader_upload_forbidden_permissions">to upload in this folder</string>
<string name="downloader_download_file_not_found">The file is no longer available on the server</string>

View file

@ -47,7 +47,6 @@ import android.provider.MediaStore;
import com.owncloud.android.MainApp;
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.status.CapabilityBooleanType;
@ -935,20 +934,20 @@ public class FileDataStorageManager {
);
cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getIdRemoteShared());
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
if (shareExists(share.getIdRemoteShared())) {// for renamed files; no more delete and create
if (shareExists(share.getRemoteId())) {// for renamed files; no more delete and create
overriden = true;
if (getContentResolver() != null) {
getContentResolver().update(ProviderTableMeta.CONTENT_URI_SHARE, cv,
ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?",
new String[]{String.valueOf(share.getIdRemoteShared())});
new String[]{String.valueOf(share.getRemoteId())});
} else {
try {
getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_SHARE,
cv, ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?",
new String[]{String.valueOf(share.getIdRemoteShared())});
new String[]{String.valueOf(share.getRemoteId())});
} catch (RemoteException e) {
Log_OC.e(TAG,
"Fail to insert insert file to database "
@ -981,16 +980,42 @@ public class FileDataStorageManager {
}
/**
* Get first share bound to a file with a known path and given {@link ShareType}.
*
* @param path Path of the file.
* @param type Type of the share to get
* @param shareWith Target of the share. Ignored in type is {@link ShareType#PUBLIC_LINK}
* @return First {@OCShare} instance found in DB bound to the file in 'path'
*/
public OCShare getFirstShareByPathAndType(String path, ShareType type, String shareWith) {
Cursor c = null;
if (shareWith == null) {
shareWith = "";
}
String selection = ProviderTableMeta.OCSHARES_PATH + "=? AND "
+ ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND "
+ ProviderTableMeta.OCSHARES_SHARE_WITH + "=? AND "
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" ;
if (!ShareType.PUBLIC_LINK.equals(type)) {
selection += ProviderTableMeta.OCSHARES_SHARE_WITH + "=? AND ";
}
String [] selectionArgs = new String[]{path, Integer.toString(type.getValue()),
shareWith, mAccount.name};
String [] selectionArgs;
if (ShareType.PUBLIC_LINK.equals(type)) {
selectionArgs = new String[]{
path,
Integer.toString(type.getValue()),
mAccount.name
};
} else {
selectionArgs = new String[]{
path,
Integer.toString(type.getValue()),
mAccount.name,
shareWith
};
}
if (getContentResolver() != null) {
c = getContentResolver().query(
@ -1190,16 +1215,16 @@ public class FileDataStorageManager {
);
cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getIdRemoteShared());
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
if (shareExists(share.getIdRemoteShared())) {
if (shareExists(share.getRemoteId())) {
// updating an existing file
operations.add(
ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI_SHARE).
withValues(cv).
withSelection(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?",
new String[]{String.valueOf(share.getIdRemoteShared())})
new String[]{String.valueOf(share.getRemoteId())})
.build());
} else {
// adding a new file
@ -1463,7 +1488,7 @@ public class FileDataStorageManager {
);
cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getIdRemoteShared());
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
// adding a new share resource

View file

@ -46,6 +46,7 @@ import com.owncloud.android.services.observer.FileObserverService;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.ShareActivity;
import com.owncloud.android.ui.dialog.ShareLinkToDialog;
import com.owncloud.android.ui.dialog.SharePasswordDialogFragment;
import org.apache.http.protocol.HTTP;
@ -283,7 +284,7 @@ public class FileOperationsHelper {
unshareService.putExtra(OperationsService.EXTRA_SHARE_TYPE, ShareType.PUBLIC_LINK);
unshareService.putExtra(OperationsService.EXTRA_SHARE_WITH, "");
unshareFile(unshareService);
queueShareIntent(unshareService);
}
public void unshareFileWithUserOrGroup(OCFile file, ShareType shareType, String userOrGroup){
@ -296,15 +297,15 @@ public class FileOperationsHelper {
unshareService.putExtra(OperationsService.EXTRA_SHARE_TYPE, shareType);
unshareService.putExtra(OperationsService.EXTRA_SHARE_WITH, userOrGroup);
unshareFile(unshareService);
queueShareIntent(unshareService);
}
private void unshareFile(Intent unshareService){
private void queueShareIntent(Intent shareIntent){
if (isSharedSupported()) {
// Unshare the file
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().
queueNewOperation(unshareService);
queueNewOperation(shareIntent);
mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
getString(R.string.wait_a_moment));
@ -333,6 +334,46 @@ public class FileOperationsHelper {
}
/**
* Starts a dialog that requests a password to the user to protect a share link.
*
* @param file File which public share will be protected by the requested password
*/
public void requestPasswordForShareViaLink(OCFile file) {
SharePasswordDialogFragment dialog =
SharePasswordDialogFragment.newInstance(
file,
null
);
dialog.show(
mFileActivity.getSupportFragmentManager(),
SharePasswordDialogFragment.PASSWORD_FRAGMENT
);
}
/**
* Updates a public share on a file to set its password.
* Starts a request to do it in {@link OperationsService}
*
* @param file File which public share will be protected with a password.
* @param password Password to set for the public link; null or empty string to clear
* the current password
*/
public void setPasswordToShareViaLink(OCFile file, String password) {
// Set password updating share
Intent updateShareIntent = new Intent(mFileActivity, OperationsService.class);
updateShareIntent.setAction(OperationsService.ACTION_UPDATE_SHARE);
updateShareIntent.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
updateShareIntent.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
updateShareIntent.putExtra(
OperationsService.EXTRA_PASSWORD_SHARE,
(password == null) ? "" : password
);
queueShareIntent(updateShareIntent);
}
/**
* @return 'True' if the server supports the Search Users API
*/

View file

@ -30,7 +30,6 @@ import android.content.Context;
import android.content.Intent;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
@ -44,8 +43,6 @@ import com.owncloud.android.operations.common.SyncOperation;
public class CreateShareViaLinkOperation extends SyncOperation {
protected FileDataStorageManager mStorageManager;
private String mPath;
private String mPassword;
private Intent mSendIntent;

View file

@ -69,11 +69,11 @@ public class UnshareOperation extends SyncOperation {
if (share != null) {
OCFile file = getStorageManager().getFileByPath(mRemotePath);
RemoveRemoteShareOperation operation =
new RemoveRemoteShareOperation((int) share.getIdRemoteShared());
new RemoveRemoteShareOperation((int) share.getRemoteId());
result = operation.execute(client);
if (result.isSuccess()) {
Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted");
Log_OC.d(TAG, "Share id = " + share.getRemoteId() + " deleted");
if (mShareType == ShareType.PUBLIC_LINK) {
file.setShareViaLink(false);

View file

@ -0,0 +1,136 @@
/**
* ownCloud Android client application
*
* @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/>.
*
*/
package com.owncloud.android.operations;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.shares.GetRemoteShareOperation;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation;
import com.owncloud.android.operations.common.SyncOperation;
/**
* Updates an existing public share for a given file
*/
public class UpdateShareViaLinkOperation extends SyncOperation {
private String mPath;
private String mPassword;
/**
* Constructor
* @param path Full path of the file/folder being shared. Mandatory argument
* @param password Password to protect a public link share.
*/
public UpdateShareViaLinkOperation(
String path,
String password
) {
mPath = path;
mPassword = password;
}
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
OCShare publicShare = getStorageManager().getFirstShareByPathAndType(
mPath,
ShareType.PUBLIC_LINK,
""
);
if (publicShare == null) {
// TODO try to get remote?
}
// Update remote share with password
RemoteOperation operation = new UpdateRemoteShareOperation(
publicShare.getRemoteId()
);
((UpdateRemoteShareOperation)operation).setPassword(mPassword);
RemoteOperationResult result = operation.execute(client);
/*
if (!result.isSuccess() || result.getData().size() <= 0) {
operation = new CreateRemoteShareOperation(
mPath,
ShareType.PUBLIC_LINK,
"",
false,
mPassword,
OCShare.DEFAULT_PERMISSION
);
result = operation.execute(client);
}
*/
if (result.isSuccess()) {
// Retrieve updated share / save directly with password? -> no; the password is not be saved
operation = new GetRemoteShareOperation(publicShare.getRemoteId());
result = operation.execute(client);
if (result.isSuccess()) {
OCShare share = (OCShare) result.getData().get(0);
updateData(share);
}
}
return result;
}
public String getPath() {
return mPath;
}
public String getPassword() {
return mPassword;
}
private void updateData(OCShare share) {
// Update DB with the response
share.setPath(mPath);
if (mPath.endsWith(FileUtils.PATH_SEPARATOR)) {
share.setIsFolder(true);
} else {
share.setIsFolder(false);
}
getStorageManager().saveShare(share); // TODO info about having a password? ask to Gonzalo
// Update OCFile with data from share: ShareByLink and publicLink
// TODO check & remove if not needed
OCFile file = getStorageManager().getFileByPath(mPath);
if (file != null) {
file.setPublicLink(share.getShareLink());
file.setShareViaLink(true);
getStorageManager().saveFile(file);
}
}
}

View file

@ -64,6 +64,7 @@ import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.operations.UnshareOperation;
import com.owncloud.android.operations.UpdateShareViaLinkOperation;
import com.owncloud.android.operations.common.SyncOperation;
import java.io.IOException;
@ -97,6 +98,7 @@ public class OperationsService extends Service {
public static final String ACTION_CREATE_SHARE_VIA_LINK = "CREATE_SHARE_VIA_LINK";
public static final String ACTION_CREATE_SHARE_WITH_SHAREE = "CREATE_SHARE_WITH_SHAREE";
public static final String ACTION_UNSHARE = "UNSHARE";
public static final String ACTION_UPDATE_SHARE = "UPDATE_SHARE";
public static final String ACTION_GET_SERVER_INFO = "GET_SERVER_INFO";
public static final String ACTION_OAUTH2_GET_ACCESS_TOKEN = "OAUTH2_GET_ACCESS_TOKEN";
public static final String ACTION_GET_USER_NAME = "GET_USER_NAME";
@ -563,6 +565,13 @@ public class OperationsService extends Service {
);
}
} else if (ACTION_UPDATE_SHARE.equals(action)) {
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String password = operationIntent.getStringExtra(EXTRA_PASSWORD_SHARE);
if (remotePath.length() > 0) {
operation = new UpdateShareViaLinkOperation(remotePath, password);
}
} else if (action.equals(ACTION_CREATE_SHARE_WITH_SHAREE)) { // Create private share with user or group
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
String shareeName = operationIntent.getStringExtra(EXTRA_SHARE_WITH);

View file

@ -73,6 +73,7 @@ import com.owncloud.android.operations.GetSharesForFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.operations.UnshareOperation;
import com.owncloud.android.operations.UpdateShareViaLinkOperation;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
import com.owncloud.android.ui.NavigationDrawerItem;
@ -735,7 +736,8 @@ public class FileActivity extends AppCompatActivity
} else if (operation == null ||
operation instanceof CreateShareWithShareeOperation ||
operation instanceof UnshareOperation ||
operation instanceof SynchronizeFolderOperation
operation instanceof SynchronizeFolderOperation ||
operation instanceof UpdateShareViaLinkOperation
) {
if (result.isSuccess()) {
updateFileFromDB();

View file

@ -154,7 +154,7 @@ public class ShareActivity extends FileActivity
super.onRemoteOperationFinish(operation, result);
if (result.isSuccess()) {
Log_OC.d(TAG, "Refreshing lists on successful sync");
Log_OC.d(TAG, "Refreshing lists on successful operation");
refreshSharesFromStorageManager();
}

View file

@ -113,8 +113,14 @@ public class SharePasswordDialogFragment extends DialogFragment
}
// Share the file
if (mSendIntent == null) {
((FileActivity) getActivity()).getFileOperationsHelper().
setPasswordToShareViaLink(mFile, password);
} else { // TODO remove old flow
((FileActivity) getActivity()).getFileOperationsHelper()
.shareFileWithLinkToApp(mFile, password, mSendIntent);
}
} else {
// Disable the flag "Share again"

View file

@ -95,6 +95,9 @@ public class ShareFileFragment extends Fragment
/** Listener for changes on switch to share / unshare publicly */
private CompoundButton.OnCheckedChangeListener mOnShareViaLinkSwitchCheckedChangeListener;
/** Listener for changes on switch to set / clear password on public link */
private CompoundButton.OnCheckedChangeListener mOnPasswordSwitchCheckedChangeListener;
/**
* Public factory method to create new ShareFileFragment instances.
@ -181,15 +184,19 @@ public class ShareFileFragment extends Fragment
mOnShareViaLinkSwitchCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isResumed()) {
if (!isResumed()) {
// very important, setCheched(...) is called automatically during
// Fragment recreation on device rotations
return;
}
if (isChecked) {
((FileActivity) getActivity()).getFileOperationsHelper().shareFileViaLink(mFile);
((FileActivity) getActivity()).getFileOperationsHelper().
shareFileViaLink(mFile);
} else {
((FileActivity) getActivity()).getFileOperationsHelper().unshareFileViaLink(mFile);
((FileActivity) getActivity()).getFileOperationsHelper().
unshareFileViaLink(mFile);
}
} // else, nothing; very important, setCheched(...) is called automatically during Fragment
// recreation on device rotations
}
};
Switch shareViaLinkSwitch = (Switch) view.findViewById(R.id.shareViaLinkSectionSwitch);
@ -200,6 +207,11 @@ public class ShareFileFragment extends Fragment
shareViaLinkExpirationSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (!isResumed()) {
// very important, setCheched(...) is called automatically during
// Fragment recreation on device rotations
return;
}
if (isChecked) {
// TODO real implementation: update share with expiration date
// show value of expiration date
@ -214,23 +226,25 @@ public class ShareFileFragment extends Fragment
});
// Switch for password
Switch shareViaLinkPasswordSwitch = (Switch) view.findViewById(R.id.shareViaLinkPasswordSwitch);
shareViaLinkPasswordSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
mOnPasswordSwitchCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (!isResumed()) {
// very important, setCheched(...) is called automatically during
// Fragment recreation on device rotations
return;
}
if (isChecked) {
// TODO real implementation: update share with password
// show
getExpirationPasswordValue().setVisibility(View.VISIBLE);
((FileActivity) getActivity()).getFileOperationsHelper().
requestPasswordForShareViaLink(mFile);
} else {
// TODO real implementation: update share without password
// empty value
getExpirationPasswordValue().setVisibility(View.INVISIBLE);
((FileActivity) getActivity()).getFileOperationsHelper().
setPasswordToShareViaLink(mFile, ""); // "" clears
}
}
});
};
Switch shareViaLinkPasswordSwitch = (Switch) view.findViewById(R.id.shareViaLinkPasswordSwitch);
shareViaLinkPasswordSwitch.setOnCheckedChangeListener(mOnShareViaLinkSwitchCheckedChangeListener);
return view;
}
@ -342,12 +356,12 @@ public class ShareFileFragment extends Fragment
*/
private void updatePublicShareSection() {
if (mPublicShare != null && ShareType.PUBLIC_LINK.equals(mPublicShare.getShareType())) {
// public share bound -> expand section
/// public share bound -> expand section
Switch shareViaLinkSwitch = getShareViaLinkSwitch();
if (!shareViaLinkSwitch.isChecked()) {
// set null listener before setChecked() to prevent infinite loop of calls
shareViaLinkSwitch.setOnCheckedChangeListener(null);
getShareViaLinkSwitch().setChecked(true);
shareViaLinkSwitch.setChecked(true);
shareViaLinkSwitch.setOnCheckedChangeListener(
mOnShareViaLinkSwitchCheckedChangeListener
);
@ -356,8 +370,29 @@ public class ShareFileFragment extends Fragment
getPasswordSection().setVisibility(View.VISIBLE);
getGetLinkButton().setVisibility(View.VISIBLE);
/// update state of password switch and message depending on password protection
Switch passwordSwitch = getPasswordSwitch();
// set null listener before setChecked() to prevent infinite loop of calls
passwordSwitch.setOnCheckedChangeListener(null);
if (mPublicShare.isPasswordProtected()) {
if (!passwordSwitch.isChecked()) {
passwordSwitch.toggle();
}
getPasswordValue().setVisibility(View.VISIBLE);
} else {
// no public share -> collapse section
if (passwordSwitch.isChecked()) {
passwordSwitch.toggle();
}
getPasswordValue().setVisibility(View.INVISIBLE);
}
// recover listener
passwordSwitch.setOnCheckedChangeListener(
mOnPasswordSwitchCheckedChangeListener
);
} else {
/// no public share -> collapse section
Switch shareViaLinkSwitch = getShareViaLinkSwitch();
if (shareViaLinkSwitch.isChecked()) {
shareViaLinkSwitch.setOnCheckedChangeListener(null);
@ -372,6 +407,8 @@ public class ShareFileFragment extends Fragment
}
}
/// BEWARE: next methods will failed with NullPointerException if called before onCreateView() finishes
private Switch getShareViaLinkSwitch() {
return (Switch) getView().findViewById(R.id.shareViaLinkSectionSwitch);
}
@ -388,7 +425,11 @@ public class ShareFileFragment extends Fragment
return getView().findViewById(R.id.shareViaLinkPasswordSection);
}
private TextView getExpirationPasswordValue() {
private Switch getPasswordSwitch() {
return (Switch) getView().findViewById(R.id.shareViaLinkPasswordSwitch);
}
private TextView getPasswordValue() {
return (TextView) getView().findViewById(R.id.shareViaLinkPasswordValue);
}

View file

@ -27,6 +27,7 @@ import com.owncloud.android.R;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation;
import com.owncloud.android.operations.CopyFileOperation;
import com.owncloud.android.operations.CreateFolderOperation;
import com.owncloud.android.operations.CreateShareViaLinkOperation;
@ -38,6 +39,7 @@ import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.operations.SynchronizeFolderOperation;
import com.owncloud.android.operations.UnshareOperation;
import com.owncloud.android.operations.UpdateShareViaLinkOperation;
import com.owncloud.android.operations.UploadFileOperation;
import org.apache.commons.httpclient.ConnectTimeoutException;
@ -201,6 +203,25 @@ public class ErrorMessageAdapter {
// Show a Message, operation finished without success
message = res.getString(R.string.unshare_link_file_error);
}
} else if (operation instanceof UpdateShareViaLinkOperation) {
if (result.getData() != null && result.getData().size() > 0) {
message = (String) result.getData().get(0); // share API sends its own error messages
} else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
message = res.getString(R.string.update_link_file_no_exist);
} else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
// Error --> No permissions
message = String.format(res.getString(R.string.forbidden_permissions),
res.getString(R.string.update_link_forbidden_permissions));
} else { // Generic error
// Show a Message, operation finished without success
message = res.getString(R.string.update_link_file_error);
}
} else if (operation instanceof MoveFileOperation) {
if (result.getCode() == ResultCode.FILE_NOT_FOUND) {