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 @@ -1195,9 +1195,9 @@ private Cursor getShareCursorForValue(String key, String value) {
* @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 {@link OCShare} instance found in DB bound to the file in 'path'
* @return All {@link OCShare} instance found in DB bound to the file in 'path'
*/
public OCShare getFirstShareByPathAndType(String path, ShareType type, String shareWith) {
public List<OCShare> getSharesByPathAndType(String path, ShareType type, String shareWith) {
Cursor cursor;
if (shareWith == null) {
shareWith = "";
Expand Down Expand Up @@ -1246,14 +1246,18 @@ public OCShare getFirstShareByPathAndType(String path, ShareType type, String sh
}
}

OCShare share = null;
List<OCShare> shares = new ArrayList<>();
OCShare share;
if (cursor != null) {
if (cursor.moveToFirst()) {
share = createShareInstance(cursor);
do {
share = createShareInstance(cursor);
shares.add(share);
} while (cursor.moveToNext());
}
cursor.close();
}
return share;
return shares;
}

// test with null cursor?
Expand All @@ -1274,6 +1278,7 @@ private OCShare createShareInstance(Cursor cursor) {
share.setPasswordProtected(getInt(cursor, ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED) == 1);
share.setNote(getString(cursor, ProviderTableMeta.OCSHARES_NOTE));
share.setHideFileDownload(getInt(cursor, ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD) == 1);
share.setShareLink(getString(cursor, ProviderTableMeta.OCSHARES_SHARE_LINK));

return share;
}
Expand Down Expand Up @@ -1626,6 +1631,7 @@ private ArrayList<ContentProviderOperation> prepareInsertShares(
contentValues.put(ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED, share.isPasswordProtected() ? 1 : 0);
contentValues.put(ProviderTableMeta.OCSHARES_NOTE, share.getNote());
contentValues.put(ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD, share.isHideFileDownload());
contentValues.put(ProviderTableMeta.OCSHARES_SHARE_LINK, share.getShareLink());

// adding a new share resource
operations.add(ContentProviderOperation
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/owncloud/android/db/ProviderMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class ProviderMeta {
public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 57;
public static final int DB_VERSION = 58;

private ProviderMeta() {
// No instance
Expand Down Expand Up @@ -145,6 +145,7 @@ static public class ProviderTableMeta implements BaseColumns {
public static final String OCSHARES_IS_PASSWORD_PROTECTED = "is_password_protected";
public static final String OCSHARES_NOTE = "note";
public static final String OCSHARES_HIDE_DOWNLOAD = "hide_download";
public static final String OCSHARES_SHARE_LINK = "share_link";

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 @@ -23,11 +23,9 @@

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.CreateShareRemoteOperation;
import com.owncloud.android.lib.resources.shares.GetSharesForFileRemoteOperation;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.operations.common.SyncOperation;
Expand All @@ -49,45 +47,23 @@ public CreateShareViaLinkOperation(String path, String password) {

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
// Check if the share link already exists
RemoteOperation operation = new GetSharesForFileRemoteOperation(path, false, false);
RemoteOperationResult result = operation.execute(client);

// Create public link if doesn't exist yet
boolean publicShareExists = false;
if (result.isSuccess()) {
OCShare share;
for (int i=0 ; i<result.getData().size(); i++) {
share = (OCShare) result.getData().get(i);
if (ShareType.PUBLIC_LINK.equals(share.getShareType())) {
publicShareExists = true;
break;
}
}
}
if (!publicShareExists) {
CreateShareRemoteOperation createOp = new CreateShareRemoteOperation(
path,
ShareType.PUBLIC_LINK,
"",
false,
password,
OCShare.DEFAULT_PERMISSION
);
createOp.setGetShareDetails(true);
result = createOp.execute(client);
}
CreateShareRemoteOperation createOp = new CreateShareRemoteOperation(path,
ShareType.PUBLIC_LINK,
"",
false,
password,
OCShare.DEFAULT_PERMISSION);
createOp.setGetShareDetails(true);
RemoteOperationResult result = createOp.execute(client);

if (result.isSuccess()) {
if (result.getData().size() > 0) {
Object item = result.getData().get(0);
if (item instanceof OCShare) {
if (item instanceof OCShare) {
updateData((OCShare) item);
} else {
ArrayList<Object> data = result.getData();
result = new RemoteOperationResult(
RemoteOperationResult.ResultCode.SHARE_NOT_FOUND
);
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
result.setData(data);
}
} else {
Expand All @@ -110,8 +86,8 @@ private void updateData(OCShare share) {
getStorageManager().saveShare(share);

// Update OCFile with data from share: ShareByLink and publicLink
OCFile file = getStorageManager().getFileByPath(path);
if (file!=null) {
OCFile file = getStorageManager().getFileByEncryptedRemotePath(path);
if (file != null) {
file.setPublicLink(share.getShareLink());
file.setSharedViaLink(true);
getStorageManager().saveFile(file);
Expand Down
47 changes: 15 additions & 32 deletions src/main/java/com/owncloud/android/operations/UnshareOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

package com.owncloud.android.operations;

import android.content.Context;

import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
Expand All @@ -46,44 +44,37 @@ public class UnshareOperation extends SyncOperation {
private static final int SINGLY_SHARED = 1;

private String mRemotePath;
private ShareType mShareType;
private String mShareWith;
private Context mContext;
private long shareId;

public UnshareOperation(String remotePath, ShareType shareType, String shareWith,
Context context) {
public UnshareOperation(String remotePath, long shareId) {
mRemotePath = remotePath;
mShareType = shareType;
mShareWith = shareWith;
mContext = context;
this.shareId = shareId;
}

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
RemoteOperationResult result;

// Get Share for a file
OCShare share = getStorageManager().getFirstShareByPathAndType(mRemotePath,
mShareType, mShareWith);
OCShare share = getStorageManager().getShareById(shareId);

if (share != null) {
OCFile file = getStorageManager().getFileByPath(mRemotePath);
RemoveShareRemoteOperation operation =
new RemoveShareRemoteOperation((int) share.getRemoteId());
OCFile file = getStorageManager().getFileByEncryptedRemotePath(mRemotePath);
RemoveShareRemoteOperation operation = new RemoveShareRemoteOperation(share.getRemoteId());
result = operation.execute(client);

if (result.isSuccess()) {
Log_OC.d(TAG, "Share id = " + share.getRemoteId() + " deleted");

if (ShareType.PUBLIC_LINK.equals(mShareType)) {
if (ShareType.PUBLIC_LINK.equals(share.getShareType())) {
file.setSharedViaLink(false);
file.setPublicLink("");
} else if (ShareType.USER.equals(mShareType) || ShareType.GROUP.equals(mShareType)
|| ShareType.FEDERATED.equals(mShareType)){
} else if (ShareType.USER.equals(share.getShareType()) || ShareType.GROUP.equals(share.getShareType())
|| ShareType.FEDERATED.equals(share.getShareType())) {
// Check if it is the last share
List <OCShare> sharesWith = getStorageManager().
getSharesWithForAFile(mRemotePath,
getStorageManager().getAccount().name);
List<OCShare> sharesWith = getStorageManager().
getSharesWithForAFile(mRemotePath,
getStorageManager().getAccount().name);
if (sharesWith.size() == SINGLY_SHARED) {
file.setSharedWithSharee(false);
}
Expand All @@ -104,15 +95,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
return result;
}

private boolean existsFile(OwnCloudClient client, String remotePath){
ExistenceCheckRemoteOperation existsOperation =
new ExistenceCheckRemoteOperation(remotePath, mContext, false);
RemoteOperationResult result = existsOperation.execute(client);
return result.isSuccess();
}

public ShareType getShareType() {
return mShareType;
private boolean existsFile(OwnCloudClient client, String remotePath) {
return new ExistenceCheckRemoteOperation(remotePath, false).execute(client).isSuccess();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.shares.GetShareRemoteOperation;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.shares.UpdateShareRemoteOperation;
import com.owncloud.android.operations.common.SyncOperation;

Expand All @@ -44,25 +43,22 @@ public class UpdateShareViaLinkOperation extends SyncOperation {
private Boolean publicUploadOnFile;
private Boolean hideFileDownload;
private long expirationDateInMillis;
private long shareId;

/**
* Constructor
*
* @param path Full path of the file/folder being shared. Mandatory argument
* @param path Full path of the file/folder being shared. Mandatory argument
*/
public UpdateShareViaLinkOperation(String path) {
public UpdateShareViaLinkOperation(String path, long shareId) {
this.path = path;
expirationDateInMillis = 0;
this.shareId = shareId;
}

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
OCShare publicShare = getStorageManager().getFirstShareByPathAndType(path, ShareType.PUBLIC_LINK, "");

if (publicShare == null) {
// TODO try to get remote share before failing?
return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
}
OCShare publicShare = getStorageManager().getShareById(shareId);

UpdateShareRemoteOperation updateOp = new UpdateShareRemoteOperation(publicShare.getRemoteId());
updateOp.setPassword(password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,8 @@ private void createOCSharesTable(SQLiteDatabase db) {
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + TEXT
+ ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED + INTEGER
+ ProviderTableMeta.OCSHARES_NOTE + TEXT
+ ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD + " INTEGER );");
+ ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD + INTEGER
+ ProviderTableMeta.OCSHARES_SHARE_LINK + " TEXT );");
}

private void createCapabilitiesTable(SQLiteDatabase db) {
Expand Down Expand Up @@ -2234,6 +2235,24 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (!upgraded) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}

if (oldVersion < 58 && newVersion >= 58) {
Log_OC.i(SQL, "Entering in the #58 add public link to share table");
db.beginTransaction();
try {
db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
ADD_COLUMN + ProviderTableMeta.OCSHARES_SHARE_LINK + " TEXT ");

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

if (!upgraded) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@ private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);

if (!TextUtils.isEmpty(remotePath)) {
UpdateShareViaLinkOperation updateLinkOperation = new UpdateShareViaLinkOperation(remotePath);
UpdateShareViaLinkOperation updateLinkOperation =
new UpdateShareViaLinkOperation(remotePath, shareId);

password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
updateLinkOperation.setPassword(password);
Expand All @@ -547,7 +548,7 @@ private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
updateLinkOperation.setExpirationDateInMillis(expirationDate);

boolean hideFileDownload = operationIntent.getBooleanExtra(EXTRA_SHARE_HIDE_FILE_DOWNLOAD,
false);
false);
updateLinkOperation.setHideFileDownload(hideFileDownload);

if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_UPLOAD)) {
Expand Down Expand Up @@ -593,17 +594,16 @@ private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
if (!TextUtils.isEmpty(remotePath)) {
operation = new CreateShareWithShareeOperation(remotePath, shareeName, shareType,
permissions);
permissions);
}
break;

case ACTION_UNSHARE:
remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE);
String shareWith = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);

if (!TextUtils.isEmpty(remotePath)) {
operation = new UnshareOperation(remotePath, shareType, shareWith, this);
if (shareId > 0) {
operation = new UnshareOperation(remotePath, shareId);
}
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ private void onUpdateShareInformation(RemoteOperationResult result, @StringRes i
if (result.isSuccess()) {
updateFileFromDB();
if (sharingFragment != null) {
sharingFragment.refreshPublicShareFromDB();
sharingFragment.onUpdateShareInformation(result, getFile());
}
} else if (sharingFragment != null && sharingFragment.getView() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
*
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2020 Tobias Kaminsky
* Copyright (C) 2020 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.ui.adapter;

import android.widget.ImageView;

import com.owncloud.android.lib.resources.shares.OCShare;

public interface PublicShareInterface {
void copyLink(OCShare share);

void showLinkOverflowMenu(OCShare publicShare, ImageView overflowMenuShareLink);
}
Loading