Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,8 @@ public boolean saveShare(OCShare share) {
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);

cv.put(ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED, share.isPasswordProtected() ? 1 : 0);

if (shareExistsForRemoteId(share.getRemoteId())) {// for renamed files; no more delete and create
overriden = true;
if (getContentResolver() != null) {
Expand Down Expand Up @@ -1200,6 +1202,7 @@ private OCShare createShareInstance(Cursor c) {
share.setIsFolder(c.getInt(c.getColumnIndex(ProviderTableMeta.OCSHARES_IS_DIRECTORY)) == 1);
share.setUserId(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_USER_ID)));
share.setIdRemoteShared(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED)));
share.setIsPasswordProtected(c.getInt(c.getColumnIndex(ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED)) == 1);
}
return share;
}
Expand Down Expand Up @@ -1307,6 +1310,8 @@ public void saveShares(Collection<OCShare> shares) {
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);

cv.put(ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED, share.isPasswordProtected() ? 1 : 0);

if (shareExistsForRemoteId(share.getRemoteId())) {
// updating an existing file
operations.add(
Expand Down Expand Up @@ -1588,6 +1593,8 @@ private ArrayList<ContentProviderOperation> prepareInsertShares(
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);

cv.put(ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED, share.isPasswordProtected() ? 1 : 0);

// adding a new share resource
operations.add(
ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI_SHARE).
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/owncloud/android/db/ProviderMeta.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* ownCloud Android client application
*
* @author Bartek Przybylski
Expand Down Expand Up @@ -32,7 +32,7 @@
public class ProviderMeta {

public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 31;
public static final int DB_VERSION = 32;

private ProviderMeta() {
}
Expand Down Expand Up @@ -128,6 +128,7 @@ static public class ProviderTableMeta implements BaseColumns {
public static final String OCSHARES_USER_ID = "user_id";
public static final String OCSHARES_ID_REMOTE_SHARED = "id_remote_shared";
public static final String OCSHARES_ACCOUNT_OWNER = "owner_share";
public static final String OCSHARES_IS_PASSWORD_PROTECTED = "is_password_protected";

public static final String OCSHARES_DEFAULT_SORT_ORDER = OCSHARES_FILE_SOURCE
+ " collate nocase asc";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package com.owncloud.android.operations;

import android.text.TextUtils;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
Expand All @@ -39,6 +41,7 @@ public class UpdateSharePermissionsOperation extends SyncOperation {
private long mShareId;
private int mPermissions;
private long mExpirationDateInMillis;
private String mPassword;
private String mPath;

/**
Expand All @@ -50,6 +53,18 @@ public UpdateSharePermissionsOperation(long shareId) {
mShareId = shareId;
mPermissions = -1;
mExpirationDateInMillis = 0L;
mPassword = null;
}

/**
* Set password to update in private share.
*
* @param password Password to set to the private share.
* Empty string clears the current password.
* Null results in no update applied to the password.
*/
public void setPassword(String password) {
mPassword = password;
}

/**
Expand Down Expand Up @@ -88,6 +103,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {

// Update remote share with password
UpdateRemoteShareOperation updateOp = new UpdateRemoteShareOperation(share.getRemoteId());
updateOp.setPassword(mPassword);
updateOp.setPermissions(mPermissions);
updateOp.setExpirationDate(mExpirationDateInMillis);
RemoteOperationResult result = updateOp.execute(client);
Expand All @@ -109,6 +125,10 @@ public String getPath() {
return mPath;
}

public String getPassword() {
return mPassword;
}

private void updateData(OCShare share) {
// Update DB with the response
share.setPath(mPath); // TODO - check if may be moved to UpdateRemoteShareOperation
Expand All @@ -117,8 +137,9 @@ private void updateData(OCShare share) {
} else {
share.setIsFolder(false);
}

share.setIsPasswordProtected(!TextUtils.isEmpty(mPassword));
getStorageManager().saveShare(share);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
/**
* Updates an existing public share for a given file
*/

public class UpdateShareViaLinkOperation extends SyncOperation {

private String mPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,8 @@ private void createOCSharesTable(SQLiteDatabase db) {
+ ProviderTableMeta.OCSHARES_IS_DIRECTORY + INTEGER // boolean
+ ProviderTableMeta.OCSHARES_USER_ID + INTEGER
+ ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + INTEGER
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );");
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + TEXT
+ ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED + " INTEGER );");
}

private void createCapabilitiesTable(SQLiteDatabase db) {
Expand Down Expand Up @@ -1687,6 +1688,23 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}

if (oldVersion < 32 && newVersion >= 32) {
Log_OC.i(SQL, "Entering in the #32 add ocshares.is_password_protected");
db.beginTransaction();
try {
db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
ADD_COLUMN + ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED + " INTEGER "); // boolean

upgraded = true;
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}

if (!upgraded) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ private void nextOperation() {
((UpdateSharePermissionsOperation)operation).setPermissions(permissions);
long expirationDateInMillis = operationIntent.getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0L);
((UpdateSharePermissionsOperation)operation).setExpirationDate(expirationDateInMillis);
String password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
((UpdateSharePermissionsOperation)operation).setPassword(password);
}

} else if (action.equals(ACTION_CREATE_SHARE_WITH_SHAREE)) {
Expand Down
83 changes: 72 additions & 11 deletions src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.ui.TextDrawable;
import com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment;
import com.owncloud.android.ui.fragment.util.FileDetailSharingFragmentHelper;
import com.owncloud.android.ui.fragment.util.SharingMenuHelper;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.ThemeUtils;

Expand Down Expand Up @@ -186,27 +187,52 @@ private void onOverflowIconClicked(View view, AppCompatCheckBox allowEditsCheckB
*/
private void prepareOptionsMenu(Menu menu, OCShare share) {

MenuItem editCreateItem = menu.findItem(R.id.action_can_edit_create);
MenuItem editChangeItem = menu.findItem(R.id.action_can_edit_change);
MenuItem editDeleteItem = menu.findItem(R.id.action_can_edit_delete);

MenuItem hideFileListingItem = menu.findItem(R.id.action_hide_file_listing);
MenuItem passwordItem = menu.findItem(R.id.action_password);
MenuItem expirationDateItem = menu.findItem(R.id.action_expiration_date);

MenuItem reshareItem = menu.findItem(R.id.action_can_reshare);

if (isReshareForbidden(share)) {
reshareItem.setVisible(false);
}
reshareItem.setChecked(canReshare(share));

MenuItem editCreateItem = menu.findItem(R.id.action_can_edit_create);
MenuItem editChangeItem = menu.findItem(R.id.action_can_edit_change);
MenuItem editDeleteItem = menu.findItem(R.id.action_can_edit_delete);
if (file.isFolder() && isEditOptionsAvailable(share)) {
/// TODO change areEditOptionsAvailable in order to delete !isFederated
editCreateItem.setChecked(canCreate(share));
editChangeItem.setChecked(canUpdate(share));
editDeleteItem.setChecked(canDelete(share));
} else {
if (share.getShareType() == ShareType.EMAIL) {
SharingMenuHelper.setupHideFileListingMenuItem(
hideFileListingItem,
file.isFolder(),
canEdit(share),
share.getPermissions()
);
SharingMenuHelper.setupPasswordMenuItem(passwordItem, share.isPasswordProtected());

reshareItem.setVisible(false);
editCreateItem.setVisible(false);
editChangeItem.setVisible(false);
editDeleteItem.setVisible(false);
} else {
if (file.isFolder() && isEditOptionsAvailable(share)) {
/// TODO change areEditOptionsAvailable in order to delete !isFederated
editCreateItem.setChecked(canCreate(share));
editChangeItem.setChecked(canUpdate(share));
editDeleteItem.setChecked(canDelete(share));
} else {
editCreateItem.setVisible(false);
editChangeItem.setVisible(false);
editDeleteItem.setVisible(false);
}

hideFileListingItem.setVisible(false);
passwordItem.setVisible(false);
expirationDateItem.setVisible(false);
}

FileDetailSharingFragmentHelper.setupExpirationDateMenuItem(
SharingMenuHelper.setupExpirationDateMenuItem(
menu.findItem(R.id.action_expiration_date), share.getExpirationDate(), context.getResources());
}

Expand Down Expand Up @@ -280,6 +306,20 @@ private boolean optionsItemSelected(Menu menu, MenuItem item, AppCompatCheckBox
notifyDataSetChanged();
return true;
}
case R.id.action_hide_file_listing: {
item.setChecked(!item.isChecked());
if (capabilities.getFilesFileDrop().isTrue()) {
listener.setHideFileListingPermissionsToShare(share, item.isChecked());
} else {
// not supported in ownCloud
listener.showNotSupportedByOcMessage();
}
return true;
}
case R.id.action_password: {
listener.requestPasswordForShare(share);
return true;
}
case R.id.action_expiration_date: {
ExpirationDatePickerDialogFragment dialog = ExpirationDatePickerDialogFragment.newInstance(share, -1);
dialog.show(
Expand Down Expand Up @@ -363,5 +403,26 @@ int updatePermissionsToShare(OCShare share,
boolean canEditCreate,
boolean canEditChange,
boolean canEditDelete);

/**
* show a snackbar that this feature is not supported by ownCloud.
*/
void showNotSupportedByOcMessage();

/**
* Starts a dialog that requests a password to the user to protect a share.
*
* @param share the share for which a password shall be configured/removed
*/
void requestPasswordForShare(OCShare share);

/**
* Updates a public share on a folder to set its hide file listing permission.
* Starts a request to do it in {@link OperationsService}
*
* @param share {@link OCShare} instance which permissions will be updated.
* @param hideFileListing New state of the permission for editing the folder shared via link.
*/
void setHideFileListingPermissionsToShare(OCShare share, boolean hideFileListing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import com.owncloud.android.R;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.utils.ThemeUtils;

Expand All @@ -49,10 +50,12 @@
public class SharePasswordDialogFragment extends DialogFragment implements DialogInterface.OnClickListener {

private static final String ARG_FILE = "FILE";
private static final String ARG_SHARE = "SHARE";
private static final String ARG_CREATE_SHARE = "CREATE_SHARE";
public static final String PASSWORD_FRAGMENT = "PASSWORD_FRAGMENT";

private OCFile file;
private OCShare share;
private boolean createShare;

@Override
Expand Down Expand Up @@ -84,6 +87,20 @@ public static SharePasswordDialogFragment newInstance(OCFile file, boolean creat
return frag;
}

/**
* Public factory method to create new SharePasswordDialogFragment instances.
*
* @param share OCFile bound to the public share that which password will be set or updated
* @return Dialog ready to show.
*/
public static SharePasswordDialogFragment newInstance(OCShare share) {
SharePasswordDialogFragment frag = new SharePasswordDialogFragment();
Bundle args = new Bundle();
args.putParcelable(ARG_SHARE, share);
frag.setArguments(args);
return frag;
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Expand All @@ -94,6 +111,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
file = getArguments().getParcelable(ARG_FILE);
share = getArguments().getParcelable(ARG_SHARE);
createShare = getArguments().getBoolean(ARG_CREATE_SHARE, false);

// Inflate the layout for the dialog
Expand Down Expand Up @@ -136,9 +154,17 @@ public void onClick(DialogInterface dialog, int which) {
return;
}

setPassword(createShare, file, password);
if (share == null) {
setPassword(createShare, file, password);
} else {
setPassword(share, password);
}
} else if (which == AlertDialog.BUTTON_NEUTRAL) {
setPassword(createShare, file, null);
if (share == null) {
setPassword(createShare, file, null);
} else {
setPassword(share, null);
}
}
}

Expand All @@ -149,4 +175,8 @@ private void setPassword(boolean createShare, OCFile file, String password) {
((FileActivity) getActivity()).getFileOperationsHelper().setPasswordToShareViaLink(file, password);
}
}

private void setPassword(OCShare share, String password) {
((FileActivity) getActivity()).getFileOperationsHelper().setPasswordToShare(share, password);
}
}
Loading