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

Commit 95919c90 authored by Maria Asensio's avatar Maria Asensio
Browse files

Merge pull request #105 from owncloud/share__edit_privileges

Share  edit privileges
parents 1b7a5690 ac9771ea
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ android:
branches:
  only:
  - master

before_install:
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
  -c 20M
@@ -25,21 +24,22 @@ script:
- ./gradlew clean build
env:
  global:
  - secure: a21NrzTCQnkTKtRGo7B1lyF2WWbpBT2N64V2Tf+oUcRLOUx3XM/mDi60mAdGd0WXV9tHD8GGmu0tQ7LGZ2VsIxixVxjzEYwX4HRTodewYez6WxBMjVEHHy+3jmc1zU4k3AAqr+uW7L4BKa5r9tH+nq9ecJMDMgW8o9MKXuP7Vso=
  - secure: UVnaC5Qzat2C8WlMMb8aycz1ChZKjP8Kz89qBbVcqYK+PLAGKpUNxFa39/2oA5jkMyyOcXYC9bX1ZYzHLH7nJ8LbQgaxXMT4gvgvN0l6KezjDavIW60idD9BbugkwzNj/cjoU/DdxBykPsTn4vSRaESVNTdEbM27YU4FBPzTANY=
  - secure: XEQY8s7p65lWWOuKbVDdTh6ZJtRTJ74Zw3H/+2Ms6vjZhFZsdUJjGo66LW6YvlhmYDXgiPB9piYQGcrGgT3hXJwXoge6n1pdixnV250J0T0dIZMbXYTWTARxDsyq48+LgUuF3pgqvqDWhBcemrePWv48q7fs/mwzuFSOyc8QwLk=
  # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
  #   via the "travis encrypt" command using the project repo's public key
  - secure: "epTZ0zZGDbHL3o6vSC9uNkZsi5j5SA6O/tvQBH7QW/dluuzIJxIjfhNbZHDyBReYDleirLzUFQpdWAUdvulCMLs/qZdIzFGlYXZSpxEnvPYMGQcilwADdJcxLw8L+3+ET5hSexxhjrTGw427IljkqGUpqQTxaLwFdFu98lDWSbc="
  - secure: epTZ0zZGDbHL3o6vSC9uNkZsi5j5SA6O/tvQBH7QW/dluuzIJxIjfhNbZHDyBReYDleirLzUFQpdWAUdvulCMLs/qZdIzFGlYXZSpxEnvPYMGQcilwADdJcxLw8L+3+ET5hSexxhjrTGw427IljkqGUpqQTxaLwFdFu98lDWSbc=
  # The next 3 declarations are the variables needed to access the test server,
  #   added via "travis encrypt", using the repo public key
  - secure: gPCBnpGLA2sdSMtfhT+/InThmXNEU8XrrS54uuIP8iXBLvVe0yZrNl76GbMosV0ry3YtDngsmsbHwRjPPb0+3mTTdAqZ60HHzGaNPgEm6b5t0t4bpJ3LW9osLZsuf9jRsI2LD66zxblaMrK2+8hN/dUrj707ijsZHp3SPSQJ6g8=
  - secure: AnxLVarfwM7IhJ7Sca35USyRlFHFvlcBhWTt2TVDcyQ+ldDyb+U6IWXFK0Yy82QP0ZH/RCLu7FnmHK/rKG0BHNRt1Ymco1VkTQql0MZcHXP+4IKgEvgJyUn1TqYj+hSVmM6lgTA+QUjZYGSfwU8mhUFiU7644ZTdTe6ALdqa+v8=
  - secure: ezKyZbb3q1Phcv/vJntuJe0C2req+Hp4/C+tFZIWZ3o8wRO9jVI3bnED9TWQyQOOT0SoRYjJ5zqp0UcEOGCzPeWFO6bA7RWp+zA/R9sziLNcVWMVv3WXnuClQjPBHJeXRnP7YmNjxDmSfV97a14dk5d9LgJZYliTDepH4dLsxro=
  matrix:
  - ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a

addons:
  coverity_scan:
    project:
      name: "owncloud/android-library"
      description: "Build submitted via Travis CI"
      name: owncloud/android-library
      description: Build submitted via Travis CI
    notification_email: lukas@owncloud.com
    build_command_prepend: "gradle clean"
    build_command:   "gradle build"
    branch_pattern: "coverity_scan"
    build_command_prepend: gradle clean
    build_command: gradle build
    branch_pattern: coverity_scan
+6 −6
Original line number Diff line number Diff line
@@ -56,9 +56,9 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
	 * Constructor
	 * 
	 * @param remoteFilePath    Path to file or folder
	 * @param reshares			If set to false (default), only shares from the current user are
	 *                          returned
	 * 							If set to true, all shares from the given file are returned
	 * @param reshares          If set to false (default), only shares owned by the current user are
	 *                          returned.
	 *                          If set to true, shares owned by any user from the given file are returned.
	 * @param subfiles          If set to false (default), lists only the folder being shared
	 *                          If set to true, all shared files within the folder are returned.
	 */
+15 −0
Original line number Diff line number Diff line
@@ -47,6 +47,21 @@ public class OCShare implements Parcelable, Serializable {
	private static final String TAG = OCShare.class.getSimpleName();

    public static final int DEFAULT_PERMISSION = -1;
    public static final int READ_PERMISSION_FLAG = 1;
    public static final int UPDATE_PERMISSION_FLAG = 2;
    public static final int CREATE_PERMISSION_FLAG = 4;
    public static final int DELETE_PERMISSION_FLAG = 8;
    public static final int SHARE_PERMISSION_FLAG = 16;
    public static final int MAXIMUM_PERMISSIONS_FOR_FILE =
            READ_PERMISSION_FLAG +
            UPDATE_PERMISSION_FLAG +
            SHARE_PERMISSION_FLAG
    ;
    public static final int MAXIMUM_PERMISSIONS_FOR_FOLDER =
            MAXIMUM_PERMISSIONS_FOR_FILE +
            CREATE_PERMISSION_FLAG +
            DELETE_PERMISSION_FLAG
    ;

    private long mId;
    private long mFileSource;
+106 −0
Original line number Diff line number Diff line
/* ownCloud Android Library is available under MIT license
 *   @author David A. Velasco
 *   Copyright (C) 2015 ownCloud Inc.
 *
 *   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;


/**
 * Provides method to define a set of share permissions and calculate the appropiate
 * int value representing it.
 */
public class SharePermissionsBuilder {

    /** Set of permissions */
    private int mPermissions = OCShare.READ_PERMISSION_FLAG;    // READ is minimum permission

    /**
     * Sets or clears permission to reshare a file or folder.
     *
     * @param enabled       'True' to set, 'false' to clear.
     * @return              Instance to builder itself, to allow consecutive calls to setters
     */
    public SharePermissionsBuilder setSharePermission(boolean enabled) {
        updatePermission(OCShare.SHARE_PERMISSION_FLAG, enabled);
        return this;
    }

    /**
     * Sets or clears permission to update a folder or folder.
     *
     * @param enabled       'True' to set, 'false' to clear.
     * @return              Instance to builder itself, to allow consecutive calls to setters
     */
    public SharePermissionsBuilder setUpdatePermission(boolean enabled) {
        updatePermission(OCShare.UPDATE_PERMISSION_FLAG, enabled);
        return this;
    }

    /**
     * Sets or clears permission to create files in share folder.
     *
     * @param enabled       'True' to set, 'false' to clear.
     * @return              Instance to builder itself, to allow consecutive calls to setters
     */
    public SharePermissionsBuilder setCreatePermission(boolean enabled) {
        updatePermission(OCShare.CREATE_PERMISSION_FLAG, enabled);
        return this;
    }

    /**
     * Sets or clears permission to delete files in a shared folder.
     *
     * @param enabled       'True' to set, 'false' to clear.
     * @return              Instance to builder itself, to allow consecutive calls to setters
     */
    public SharePermissionsBuilder setDeletePermission(boolean enabled) {
        updatePermission(OCShare.DELETE_PERMISSION_FLAG, enabled);
        return this;
    }

    /**
     * Common code to update the value of the set of permissions.
     *
     * @param permissionsFlag       Flag for the permission to update.
     * @param enable                'True' to set, 'false' to clear.
     */
    private void updatePermission(int permissionsFlag, boolean enable) {
        if (enable) {
            // add permission
            mPermissions |= permissionsFlag;
        } else {
            // delete permission
            mPermissions &= ~permissionsFlag;
        }
    }

    /**
     * 'Builds' the int value for the accumulated set of permissions.
     *
     * @return  An int value representing the accumulated set of permissions.
     */
    public int build() {
        return mPermissions;
    }
}
+19 −4
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation {

    private static final String PARAM_PASSWORD = "password";
    private static final String PARAM_EXPIRATION_DATE = "expireDate";
    private static final String PARAM_PERMISSIONS = "permissions";
    private static final String FORMAT_EXPIRATION_DATE = "yyyy-MM-dd";
    private static final String ENTITY_CONTENT_TYPE  = "application/x-www-form-urlencoded";
    private static final String ENTITY_CHARSET = "UTF-8";
@@ -70,6 +71,9 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
    /** Expiration date to set for the public link */
    private long mExpirationDateInMillis;

    /** Access permissions for the file bound to the share */
    private int mPermissions;


    /**
     * Constructor. No update is initialized by default, need to be applied with setters below.
@@ -98,7 +102,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
    /**
     * Set expiration date to update in Share resource.
     *
     * @param expirationDateInMillis    Expiration date to set to the public link.
     * @param expirationDateInMillis    Expiration date to set to the target share.
     *                                  A negative value clears the current expiration date.
     *                                  Zero value (start-of-epoch) results in no update done on
     *                                  the expiration date.
@@ -108,6 +112,16 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
    }


    /**
     * Set permissions to update in Share resource.
     *
     * @param permissions       Permissions date to set to the target share.
     *                          Values <= 0 result in no update applied to the permissions.
     */
    public void setPermissions(int permissions) {
        mPermissions = permissions;
    }

    @Override
    protected RemoteOperationResult run(OwnCloudClient client) {
        RemoteOperationResult result = null;
@@ -131,11 +145,12 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
            parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, formattedExpirationDate));

        } // else, ignore - no update

        /* TODO complete rest of parameters
        if (mPermissions > 0) {
            parametersToUpdate.add(new Pair("permissions", Integer.toString(mPermissions)));
            // set permissions
            parametersToUpdate.add(new Pair(PARAM_PERMISSIONS, Integer.toString(mPermissions)));
        }

        /* TODO complete rest of parameters
        if (mPublicUpload != null) {
            parametersToUpdate.add(new Pair("publicUpload", mPublicUpload.toString());
        }
Loading