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

Commit e7891c4a authored by David A. Velasco's avatar David A. Velasco
Browse files

Merge pull request #113 from owncloud/edit_public_share_permission

Edit public share permission
parents cf3baa6c 573afa15
Loading
Loading
Loading
Loading
+59 −37
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ package com.owncloud.android.lib.resources.shares;

/**
 * Updates parameters of an existing Share resource, known its remote ID.
 *
 * <p/>
 * Allow updating several parameters, triggering a request to the server per parameter.
 */

@@ -57,23 +57,37 @@ 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 PARAM_PUBLIC_UPLOAD = "publicUpload";
    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";


    /** Identifier of the share to update */
    /**
     * Identifier of the share to update
     */
    private long mRemoteId;

    /** Password to set for the public link */
    /**
     * Password to set for the public link
     */
    private String mPassword;

    /** Expiration date to set for the public link */
    /**
     * Expiration date to set for the public link
     */
    private long mExpirationDateInMillis;

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

    /**
     * Upload permissions for the public link (only folders)
     */
    private Boolean mPublicUpload;


    /**
     * Constructor. No update is initialized by default, need to be applied with setters below.
@@ -84,6 +98,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
        mRemoteId = remoteId;
        mPassword = null;               // no update
        mExpirationDateInMillis = 0;    // no update
        mPublicUpload = null;
    }


@@ -115,13 +130,22 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
    /**
     * Set permissions to update in Share resource.
     *
     * @param permissions       Permissions date to set to the target share.
     * @param permissions Permissions to set to the target share.
     *                    Values <= 0 result in no update applied to the permissions.
     */
    public void setPermissions(int permissions) {
        mPermissions = permissions;
    }

    /**
     * Enable upload permissions to update in Share resource.
     *
     * @param publicUpload Upload Permission to set to the target share.
     */
    public void setPublicUpload(boolean publicUpload) {
        mPublicUpload = publicUpload;
    }

    @Override
    protected RemoteOperationResult run(OwnCloudClient client) {
        RemoteOperationResult result = null;
@@ -150,11 +174,9 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
            parametersToUpdate.add(new Pair(PARAM_PERMISSIONS, Integer.toString(mPermissions)));
        }

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

        /// perform required PUT requests
        PutMethod put = null;
+46 −5
Original line number Diff line number Diff line
@@ -64,13 +64,18 @@ public class UpdatePublicShareTest extends RemoteTest {
	/* File to share and update.*/
	private static final String FILE_TO_SHARE = "/fileToShare.txt";
	
	/* Folder to share and update */
	private static final String FOLDER_TO_SHARE = "/folderToShare";
	
	// Data for tests 
	private static final String PASSWORD = "password";
	private static final String PASS_SPECIAL_CHARS = "p@ssw�rd";
	
	private String mFullPath2FileToShare;
	private String mFullPath2FolderToShare;
	
	private OCShare mShare;
	private OCShare mFolderShare;
	
	String mServerUri, mUser, mPass;
	OwnCloudClient mClient = null;
@@ -107,7 +112,7 @@ public class UpdatePublicShareTest extends RemoteTest {
	    
	    Log.v(LOG_TAG, "Setting up the remote fixture...");
	    
	    // Upload the files
	    // Upload the file
	    mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE;
	    
	    File textFile = getActivity().extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
@@ -126,15 +131,39 @@ public class UpdatePublicShareTest extends RemoteTest {
				"", 
				false, 
				"", 
				1);
				OCShare.READ_PERMISSION_FLAG);

	    if (result.isSuccess()){
	    	mShare = (OCShare) result.getData().get(0);
	    } else{
	    	mShare = null;
	    	Utils.logAndThrow(LOG_TAG, result);
	    }
	    
	    // Create the folder
 		mFullPath2FolderToShare = mBaseFolderPath + FOLDER_TO_SHARE;
 		result = getActivity().createFolder(
 				mFullPath2FolderToShare,
 				true);
 		if (!result.isSuccess()) {
 			Utils.logAndThrow(LOG_TAG, result);
 		}

 		// Share the folder publicly via link
 		result = getActivity().createShare(
 				mFullPath2FolderToShare,
 				ShareType.PUBLIC_LINK,
 				"",
 				false,
 				"",
 				OCShare.READ_PERMISSION_FLAG);

 		if (result.isSuccess()){
 			mFolderShare = (OCShare) result.getData().get(0);
 		} else{
 			Utils.logAndThrow(LOG_TAG, result);
 		}
	    
		Log.v(LOG_TAG, "Remote fixture created.");
		Log.v(LOG_TAG, "Remote fixtures created.");
		
	}
	
@@ -165,6 +194,12 @@ public class UpdatePublicShareTest extends RemoteTest {
			result = updateShare.execute(mClient);
			assertTrue(result.isSuccess());

			// Update the Folder Share with edit permission
			updateShare = new UpdateRemoteShareOperation(mFolderShare.getRemoteId());
			updateShare.setPublicUpload(true);
			result = updateShare.execute(mClient);
			assertTrue(result.isSuccess());

			// unsuccessful test
			// Update Share with expiration date in the past
			updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId());
@@ -174,6 +209,12 @@ public class UpdatePublicShareTest extends RemoteTest {
			result = updateShare.execute(mClient);
			assertFalse(result.isSuccess());
			
			// Try to update the file Share with edit permission
			updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId());
			updateShare.setPublicUpload(true);
			result = updateShare.execute(mClient);
			assertFalse(result.isSuccess());

			// Unshare the file before the unsuccessful tests
			RemoveRemoteShareOperation unshare = new RemoveRemoteShareOperation((int) mShare.getRemoteId());
			result = unshare.execute(mClient);