mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 02:17:43 +03:00
Dinamycally find out the maximum permissions to reshare
This commit is contained in:
parent
81b8918939
commit
3b4b8ceadd
6 changed files with 64 additions and 17 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 249cb901ebd392373d0ef812b8f0a2489705c0ea
|
Subproject commit 275c042f7884f8a56cb4b5cb94ef9be98884e698
|
|
@ -228,8 +228,9 @@ public class FileOperationsHelper {
|
||||||
* @param file The file to share.
|
* @param file The file to share.
|
||||||
* @param shareeName Name (user name or group name) of the target sharee.
|
* @param shareeName Name (user name or group name) of the target sharee.
|
||||||
* @param shareType The share type determines the sharee type.
|
* @param shareType The share type determines the sharee type.
|
||||||
|
* @param permissions Permissions to grant to sharee on the shared file.
|
||||||
*/
|
*/
|
||||||
public void shareFileWithSharee(OCFile file, String shareeName, ShareType shareType) {
|
public void shareFileWithSharee(OCFile file, String shareeName, ShareType shareType, int permissions) {
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
// TODO check capability?
|
// TODO check capability?
|
||||||
mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
|
mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
|
||||||
|
@ -241,6 +242,7 @@ public class FileOperationsHelper {
|
||||||
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
|
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
|
||||||
service.putExtra(OperationsService.EXTRA_SHARE_WITH, shareeName);
|
service.putExtra(OperationsService.EXTRA_SHARE_WITH, shareeName);
|
||||||
service.putExtra(OperationsService.EXTRA_SHARE_TYPE, shareType);
|
service.putExtra(OperationsService.EXTRA_SHARE_TYPE, shareType);
|
||||||
|
service.putExtra(OperationsService.EXTRA_SHARE_PERMISSIONS, permissions);
|
||||||
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
|
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -26,12 +26,16 @@ package com.owncloud.android.operations;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
|
|
||||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
import com.owncloud.android.datamodel.OCFile;
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
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.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.resources.files.FileUtils;
|
import com.owncloud.android.lib.resources.files.FileUtils;
|
||||||
import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation;
|
import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation;
|
||||||
|
import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation;
|
||||||
import com.owncloud.android.lib.resources.shares.OCShare;
|
import com.owncloud.android.lib.resources.shares.OCShare;
|
||||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||||
import com.owncloud.android.operations.common.SyncOperation;
|
import com.owncloud.android.operations.common.SyncOperation;
|
||||||
|
@ -43,6 +47,7 @@ public class CreateShareWithShareeOperation extends SyncOperation {
|
||||||
private String mPath;
|
private String mPath;
|
||||||
private String mShareeName;
|
private String mShareeName;
|
||||||
private ShareType mShareType;
|
private ShareType mShareType;
|
||||||
|
private int mPermissions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
@ -51,25 +56,49 @@ public class CreateShareWithShareeOperation extends SyncOperation {
|
||||||
* @param shareeName User or group name of the target sharee.
|
* @param shareeName User or group name of the target sharee.
|
||||||
* @param shareType Type of share determines type of sharee; {@link ShareType#USER} and {@link ShareType#GROUP}
|
* @param shareType Type of share determines type of sharee; {@link ShareType#USER} and {@link ShareType#GROUP}
|
||||||
* are the only valid values for the moment.
|
* are the only valid values for the moment.
|
||||||
|
* @param permissions Share permissions key as detailed in
|
||||||
|
* https://doc.owncloud.org/server/8.2/developer_manual/core/ocs-share-api.html .
|
||||||
|
* If < 0, maximum permissions are dynamically found out and requested. This requires
|
||||||
|
* an extra interaction with the server, and should be used only for RESHARING.
|
||||||
*/
|
*/
|
||||||
public CreateShareWithShareeOperation(String path, String shareeName, ShareType shareType) {
|
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)) {
|
||||||
throw new IllegalArgumentException("Illegal share type " + shareType);
|
throw new IllegalArgumentException("Illegal share type " + shareType);
|
||||||
}
|
}
|
||||||
mPath = path;
|
mPath = path;
|
||||||
mShareeName = shareeName;
|
mShareeName = shareeName;
|
||||||
mShareType = shareType;
|
mShareType = shareType;
|
||||||
|
mPermissions = permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
// Check if the share link already exists
|
int permissions = mPermissions;
|
||||||
// TODO or not
|
if (permissions < 0) {
|
||||||
/*
|
// find out maximum permissions
|
||||||
RemoteOperation operation = new GetRemoteSharesForFileOperation(mPath, false, false);
|
RemoteOperation operation = new GetRemoteSharesForFileOperation(mPath, true, false);
|
||||||
RemoteOperationResult result = operation.execute(client);
|
RemoteOperationResult result = operation.execute(client);
|
||||||
if (!result.isSuccess() || result.getData().size() <= 0) {
|
if (!result.isSuccess()) {
|
||||||
*/
|
return result;
|
||||||
|
} else {
|
||||||
|
OCShare share = null;
|
||||||
|
Account account = getStorageManager().getAccount();
|
||||||
|
String userId = account.name.substring(0, account.name.lastIndexOf("@"));
|
||||||
|
// TODO OcAccount needed everywhere :(
|
||||||
|
boolean sharedWithMe = false;
|
||||||
|
|
||||||
|
for (int i=0; i<result.getData().size() && !sharedWithMe; i++) {
|
||||||
|
share = (OCShare) result.getData().get(i);
|
||||||
|
sharedWithMe = userId.equals(share.getShareWith());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (share != null && sharedWithMe) {
|
||||||
|
permissions = share.getPermissions();
|
||||||
|
} else {
|
||||||
|
permissions = OCShare.DEFAULT_PERMISSION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CreateRemoteShareOperation operation = new CreateRemoteShareOperation(
|
CreateRemoteShareOperation operation = new CreateRemoteShareOperation(
|
||||||
mPath,
|
mPath,
|
||||||
|
@ -77,7 +106,7 @@ public class CreateShareWithShareeOperation extends SyncOperation {
|
||||||
mShareeName,
|
mShareeName,
|
||||||
false,
|
false,
|
||||||
"",
|
"",
|
||||||
OCShare.DEFAULT_PERMISSION
|
permissions
|
||||||
);
|
);
|
||||||
operation.setGetShareDetails(true);
|
operation.setGetShareDetails(true);
|
||||||
RemoteOperationResult result = operation.execute(client);
|
RemoteOperationResult result = operation.execute(client);
|
||||||
|
|
|
@ -69,7 +69,6 @@ import com.owncloud.android.operations.UpdateShareViaLinkOperation;
|
||||||
import com.owncloud.android.operations.common.SyncOperation;
|
import com.owncloud.android.operations.common.SyncOperation;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
@ -598,11 +597,13 @@ public class OperationsService extends Service {
|
||||||
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
|
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
|
||||||
String shareeName = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
|
String shareeName = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
|
||||||
ShareType shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE);
|
ShareType shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE);
|
||||||
|
int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
|
||||||
if (remotePath.length() > 0) {
|
if (remotePath.length() > 0) {
|
||||||
operation = new CreateShareWithShareeOperation(
|
operation = new CreateShareWithShareeOperation(
|
||||||
remotePath,
|
remotePath,
|
||||||
shareeName,
|
shareeName,
|
||||||
shareType
|
shareType,
|
||||||
|
permissions
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,10 +122,25 @@ public class ShareActivity extends FileActivity
|
||||||
getFileOperationsHelper().shareFileWithSharee(
|
getFileOperationsHelper().shareFileWithSharee(
|
||||||
getFile(),
|
getFile(),
|
||||||
shareeName,
|
shareeName,
|
||||||
(isGroup ? ShareType.GROUP : ShareType.USER)
|
(isGroup ? ShareType.GROUP : ShareType.USER),
|
||||||
|
getMaximumPermissions()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private int getMaximumPermissions() {
|
||||||
|
if (getFile().isSharedWithMe()) {
|
||||||
|
return -1; // maximum permissions will be requested dynamically
|
||||||
|
|
||||||
|
} else if (getFile().isFolder()) {
|
||||||
|
return OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER;
|
||||||
|
|
||||||
|
} else { // isFile
|
||||||
|
return OCShare.MAXIMUM_PERMISSIONS_FOR_FILE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showSearchUsersAndGroups() {
|
public void showSearchUsersAndGroups() {
|
||||||
// replace ShareFragment with SearchFragment on demand
|
// replace ShareFragment with SearchFragment on demand
|
||||||
|
|
|
@ -130,7 +130,7 @@ public class EditShareFragment extends Fragment {
|
||||||
View view = inflater.inflate(R.layout.edit_share_layout, container, false);
|
View view = inflater.inflate(R.layout.edit_share_layout, container, false);
|
||||||
|
|
||||||
// Setup layout
|
// Setup layout
|
||||||
initPrivileges(view);
|
initPermissions(view);
|
||||||
initUnshareButton(view);
|
initUnshareButton(view);
|
||||||
initDoneButton(view);
|
initDoneButton(view);
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ public class EditShareFragment extends Fragment {
|
||||||
*
|
*
|
||||||
* @param editShareView Root view in the fragment.
|
* @param editShareView Root view in the fragment.
|
||||||
*/
|
*/
|
||||||
private void initPrivileges(View editShareView) {
|
private void initPermissions(View editShareView) {
|
||||||
boolean setListener = false;
|
boolean setListener = false;
|
||||||
if (mOnPrivilegeChangeListener == null) {
|
if (mOnPrivilegeChangeListener == null) {
|
||||||
mOnPrivilegeChangeListener = new OnPrivilegeChangeListener();
|
mOnPrivilegeChangeListener = new OnPrivilegeChangeListener();
|
||||||
|
@ -213,7 +213,7 @@ public class EditShareFragment extends Fragment {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (getView() != null) {
|
if (getView() != null) {
|
||||||
initPrivileges(getView());
|
initPermissions(getView());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue