Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit f2a324d9 authored by Tobias Kaminsky's avatar Tobias Kaminsky Committed by GitHub
Browse files

Merge pull request #772 from nextcloud/createShareWithNote

Create share directly with note
parents 13088876 c899f2de
Loading
Loading
Loading
Loading
+80 −0
Original line number Diff line number Diff line
/* 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)
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -69,7 +69,8 @@ class UpdateShareRemoteOperationIT : AbstractIT() {
            false,
            "",
            OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER,
            true
            true,
            ""
        ).execute(client)

        assertTrue(createOperationResult.isSuccess)
+38 −5
Original line number Diff line number Diff line
@@ -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;
@@ -34,6 +36,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.Utf8PostMethod;

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

/**
@@ -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;
@@ -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
@@ -86,7 +91,8 @@ public class CreateShareRemoteOperation extends RemoteOperation<List<OCShare>> {
            boolean publicUpload,
            String password,
            int permissions,
            boolean getShareDetails
            boolean getShareDetails,
            String note
    ) {
        this.remoteFilePath = remoteFilePath;
        this.shareType = shareType;
@@ -95,6 +101,7 @@ public class CreateShareRemoteOperation extends RemoteOperation<List<OCShare>> {
        this.password = password;
        this.permissions = permissions;
        this.getShareDetails = getShareDetails;        // defaults to false for backwards compatibility
        this.note = note;
    }

    public CreateShareRemoteOperation(
@@ -104,7 +111,29 @@ public class CreateShareRemoteOperation extends RemoteOperation<List<OCShare>> {
            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() {
@@ -141,6 +170,10 @@ public class CreateShareRemoteOperation extends RemoteOperation<List<OCShare>> {
                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);
@@ -166,7 +199,7 @@ public class CreateShareRemoteOperation extends RemoteOperation<List<OCShare>> {
                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);

+1 −1

File changed.

Contains only whitespace changes.