Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create share directly with note #772

Merged
merged 3 commits into from
Apr 19, 2023
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
@@ -0,0 +1,80 @@
/* Nextcloud Android Library is available under MIT license
*
* @author Tobias Kaminsky
* Copyright (C) 2021 Tobias Kaminsky
* Copyright (C) 2021 Nextcloud GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

package com.owncloud.android.lib.resources.shares

import com.owncloud.android.AbstractIT
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation
import com.owncloud.android.lib.resources.status.GetStatusRemoteOperation
import com.owncloud.android.lib.resources.status.NextcloudVersion
import com.owncloud.android.lib.resources.status.OwnCloudVersion
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Assume
import org.junit.Before
import org.junit.Test

class CreateShareRemoteOperationIT : AbstractIT() {
@Before
fun before() {
val result = GetStatusRemoteOperation(context).execute(client)
Assert.assertTrue(result.isSuccess)
val data = result.data as ArrayList<Any>
val ownCloudVersion = data[0] as OwnCloudVersion
Assume.assumeTrue(ownCloudVersion.isNewerOrEqual(NextcloudVersion.nextcloud_24))
}

@Test
fun createShareWithNote() {
val note = "This is the note"

Assert.assertTrue(
CreateFolderRemoteOperation(
"/share/",
true
).execute(client).isSuccess
)

// share folder to user "admin"
val sut = CreateShareRemoteOperation(
"/share/",
ShareType.USER,
"admin",
false,
"",
OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER,
true,
note
).execute(client)

junit.framework.Assert.assertTrue(sut.isSuccess)

val share = sut.resultData[0]

assertEquals(note, share.note)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class UpdateShareRemoteOperationIT : AbstractIT() {
false,
"",
OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER,
true
true,
""
).execute(client)

assertTrue(createOperationResult.isSuccess)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

package com.owncloud.android.lib.resources.shares;

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 @@ -34,6 +36,7 @@
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.Utf8PostMethod;

import java.io.IOException;
import java.util.List;

/**
Expand All @@ -49,6 +52,7 @@ public class CreateShareRemoteOperation extends RemoteOperation<List<OCShare>> {
private static final String PARAM_PUBLIC_UPLOAD = "publicUpload";
private static final String PARAM_PASSWORD = "password";
private static final String PARAM_PERMISSIONS = "permissions";
private static final String PARAM_NOTE = "note";

private final String remoteFilePath;
private final ShareType shareType;
Expand All @@ -57,6 +61,7 @@ public class CreateShareRemoteOperation extends RemoteOperation<List<OCShare>> {
private final String password;
private final int permissions;
private boolean getShareDetails;
private String note;

/**
* Constructor
Expand Down Expand Up @@ -86,15 +91,17 @@ public CreateShareRemoteOperation(
boolean publicUpload,
String password,
int permissions,
boolean getShareDetails
) {
boolean getShareDetails,
String note
) {
this.remoteFilePath = remoteFilePath;
this.shareType = shareType;
this.shareWith = shareWith;
this.publicUpload = publicUpload;
this.password = password;
this.permissions = permissions;
this.getShareDetails = getShareDetails; // defaults to false for backwards compatibility
this.note = note;
}

public CreateShareRemoteOperation(
Expand All @@ -104,7 +111,29 @@ public CreateShareRemoteOperation(
boolean publicUpload,
String password,
int permissions) {
this(remoteFilePath, shareType, shareWith, publicUpload, password, permissions, false);
this(remoteFilePath, shareType, shareWith, publicUpload, password, permissions, false, "");
}

public CreateShareRemoteOperation(
String remoteFilePath,
ShareType shareType,
String shareWith,
boolean publicUpload,
String password,
int permissions,
String note) {
this(remoteFilePath, shareType, shareWith, publicUpload, password, permissions, false, note);
}

public CreateShareRemoteOperation(
String remoteFilePath,
ShareType shareType,
String shareWith,
boolean publicUpload,
String password,
int permissions,
boolean getShareDetails) {
this(remoteFilePath, shareType, shareWith, publicUpload, password, permissions, getShareDetails, "");
}

public boolean isGettingShareDetails() {
Expand Down Expand Up @@ -141,6 +170,10 @@ protected RemoteOperationResult<List<OCShare>> run(OwnCloudClient client) {
post.addParameter(PARAM_PERMISSIONS, Integer.toString(permissions));
}

if (!TextUtils.isEmpty(note)) {
post.addParameter(PARAM_NOTE, note);
}

post.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);

status = client.executeMethod(post);
Expand All @@ -149,7 +182,7 @@ protected RemoteOperationResult<List<OCShare>> run(OwnCloudClient client) {
String response = post.getResponseBodyAsString();

ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser(
new ShareXMLParser()
new ShareXMLParser()
);
parser.setOneOrMoreSharesRequired(true);
parser.setServerBaseUri(client.getBaseUri());
Expand All @@ -166,7 +199,7 @@ protected RemoteOperationResult<List<OCShare>> run(OwnCloudClient client) {
result = new RemoteOperationResult<>(false, post);
}

} catch (Exception e) {
} catch (IOException e) {
result = new RemoteOperationResult<>(e);
Log_OC.e(TAG, "Exception while Creating New Share", e);

Expand Down
2 changes: 1 addition & 1 deletion scripts/analysis/findbugs-results.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
140
140