mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 10:27:45 +00:00 
			
		
		
		
	Merge pull request #105 from owncloud/share__edit_privileges
Share edit privileges
This commit is contained in:
		
						commit
						95919c9005
					
				
							
								
								
									
										28
									
								
								.travis.yml
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								.travis.yml
									
									
									
									
									
								
							| @ -6,8 +6,7 @@ android: | |||||||
|   - android-19 |   - android-19 | ||||||
| branches: | branches: | ||||||
|   only: |   only: | ||||||
|     - master |   - master | ||||||
| 
 |  | ||||||
| before_install: | before_install: | ||||||
| - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI | - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI | ||||||
|   -c 20M |   -c 20M | ||||||
| @ -25,21 +24,22 @@ script: | |||||||
| - ./gradlew clean build | - ./gradlew clean build | ||||||
| env: | env: | ||||||
|   global: |   global: | ||||||
|   - secure: a21NrzTCQnkTKtRGo7B1lyF2WWbpBT2N64V2Tf+oUcRLOUx3XM/mDi60mAdGd0WXV9tHD8GGmu0tQ7LGZ2VsIxixVxjzEYwX4HRTodewYez6WxBMjVEHHy+3jmc1zU4k3AAqr+uW7L4BKa5r9tH+nq9ecJMDMgW8o9MKXuP7Vso= |   # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created | ||||||
|   - secure: UVnaC5Qzat2C8WlMMb8aycz1ChZKjP8Kz89qBbVcqYK+PLAGKpUNxFa39/2oA5jkMyyOcXYC9bX1ZYzHLH7nJ8LbQgaxXMT4gvgvN0l6KezjDavIW60idD9BbugkwzNj/cjoU/DdxBykPsTn4vSRaESVNTdEbM27YU4FBPzTANY= |   #   via the "travis encrypt" command using the project repo's public key | ||||||
|   - secure: XEQY8s7p65lWWOuKbVDdTh6ZJtRTJ74Zw3H/+2Ms6vjZhFZsdUJjGo66LW6YvlhmYDXgiPB9piYQGcrGgT3hXJwXoge6n1pdixnV250J0T0dIZMbXYTWTARxDsyq48+LgUuF3pgqvqDWhBcemrePWv48q7fs/mwzuFSOyc8QwLk= |   - secure: epTZ0zZGDbHL3o6vSC9uNkZsi5j5SA6O/tvQBH7QW/dluuzIJxIjfhNbZHDyBReYDleirLzUFQpdWAUdvulCMLs/qZdIzFGlYXZSpxEnvPYMGQcilwADdJcxLw8L+3+ET5hSexxhjrTGw427IljkqGUpqQTxaLwFdFu98lDWSbc= | ||||||
|    # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created |   # The next 3 declarations are the variables needed to access the test server, | ||||||
|    #   via the "travis encrypt" command using the project repo's public key |   #   added via "travis encrypt", using the repo public key | ||||||
|   - secure: "epTZ0zZGDbHL3o6vSC9uNkZsi5j5SA6O/tvQBH7QW/dluuzIJxIjfhNbZHDyBReYDleirLzUFQpdWAUdvulCMLs/qZdIzFGlYXZSpxEnvPYMGQcilwADdJcxLw8L+3+ET5hSexxhjrTGw427IljkqGUpqQTxaLwFdFu98lDWSbc=" |   - 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: |   matrix: | ||||||
|   - ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a |   - ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a | ||||||
| 
 |  | ||||||
| addons: | addons: | ||||||
|   coverity_scan: |   coverity_scan: | ||||||
|     project: |     project: | ||||||
|       name: "owncloud/android-library" |       name: owncloud/android-library | ||||||
|       description: "Build submitted via Travis CI" |       description: Build submitted via Travis CI | ||||||
|     notification_email: lukas@owncloud.com |     notification_email: lukas@owncloud.com | ||||||
|     build_command_prepend: "gradle clean" |     build_command_prepend: gradle clean | ||||||
|     build_command:   "gradle build" |     build_command: gradle build | ||||||
|     branch_pattern: "coverity_scan" |     branch_pattern: coverity_scan | ||||||
|  | |||||||
| @ -55,12 +55,12 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation { | |||||||
| 	/** | 	/** | ||||||
| 	 * Constructor | 	 * Constructor | ||||||
| 	 *  | 	 *  | ||||||
| 	 * @param remoteFilePath	Path to file or folder | 	 * @param remoteFilePath    Path to file or folder | ||||||
| 	 * @param reshares			If set to false (default), only shares from the current user are | 	 * @param reshares          If set to false (default), only shares owned by the current user are | ||||||
| 	 *                          returned | 	 *                          returned. | ||||||
| 	 * 							If set to true, all shares from the given file 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 | 	 * @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. | 	 *                          If set to true, all shared files within the folder are returned. | ||||||
| 	 */ | 	 */ | ||||||
| 	public GetRemoteSharesForFileOperation(String remoteFilePath, boolean reshares, | 	public GetRemoteSharesForFileOperation(String remoteFilePath, boolean reshares, | ||||||
| 										   boolean subfiles) { | 										   boolean subfiles) { | ||||||
|  | |||||||
| @ -47,6 +47,21 @@ public class OCShare implements Parcelable, Serializable { | |||||||
| 	private static final String TAG = OCShare.class.getSimpleName(); | 	private static final String TAG = OCShare.class.getSimpleName(); | ||||||
| 
 | 
 | ||||||
|     public static final int DEFAULT_PERMISSION = -1; |     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 mId; | ||||||
|     private long mFileSource; |     private long mFileSource; | ||||||
|  | |||||||
| @ -0,0 +1,106 @@ | |||||||
|  | /* 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; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -56,6 +56,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation { | |||||||
| 
 | 
 | ||||||
|     private static final String PARAM_PASSWORD = "password"; |     private static final String PARAM_PASSWORD = "password"; | ||||||
|     private static final String PARAM_EXPIRATION_DATE = "expireDate"; |     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 FORMAT_EXPIRATION_DATE = "yyyy-MM-dd"; | ||||||
|     private static final String ENTITY_CONTENT_TYPE  = "application/x-www-form-urlencoded"; |     private static final String ENTITY_CONTENT_TYPE  = "application/x-www-form-urlencoded"; | ||||||
|     private static final String ENTITY_CHARSET = "UTF-8"; |     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 */ |     /** Expiration date to set for the public link */ | ||||||
|     private long mExpirationDateInMillis; |     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. |      * 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. |      * 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. |      *                                  A negative value clears the current expiration date. | ||||||
|      *                                  Zero value (start-of-epoch) results in no update done on |      *                                  Zero value (start-of-epoch) results in no update done on | ||||||
|      *                                  the expiration date. |      *                                  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 |     @Override | ||||||
|     protected RemoteOperationResult run(OwnCloudClient client) { |     protected RemoteOperationResult run(OwnCloudClient client) { | ||||||
|         RemoteOperationResult result = null; |         RemoteOperationResult result = null; | ||||||
| @ -131,11 +145,12 @@ public class UpdateRemoteShareOperation extends RemoteOperation { | |||||||
|             parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, formattedExpirationDate)); |             parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, formattedExpirationDate)); | ||||||
| 
 | 
 | ||||||
|         } // else, ignore - no update |         } // else, ignore - no update | ||||||
|  |         if (mPermissions > 0) { | ||||||
|  |             // set permissions | ||||||
|  |             parametersToUpdate.add(new Pair(PARAM_PERMISSIONS, Integer.toString(mPermissions))); | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         /* TODO complete rest of parameters |         /* TODO complete rest of parameters | ||||||
|         if (mPermissions > 0) { |  | ||||||
|             parametersToUpdate.add(new Pair("permissions", Integer.toString(mPermissions))); |  | ||||||
|         } |  | ||||||
|         if (mPublicUpload != null) { |         if (mPublicUpload != null) { | ||||||
|             parametersToUpdate.add(new Pair("publicUpload", mPublicUpload.toString()); |             parametersToUpdate.add(new Pair("publicUpload", mPublicUpload.toString()); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -127,9 +127,9 @@ public class GetShareesTest extends RemoteTest { | |||||||
| 		JSONObject value; | 		JSONObject value; | ||||||
| 		byte type; | 		byte type; | ||||||
| 		int userCount = 0, groupCount = 0; | 		int userCount = 0, groupCount = 0; | ||||||
| 		assertTrue(result.isSuccess() && result.getData().size() == 3); | 		assertTrue(result.isSuccess() && result.getData().size() > 0); | ||||||
| 		try { | 		try { | ||||||
| 			for (int i=0; i<3; i++) { | 			for (int i=0; i<result.getData().size(); i++) { | ||||||
| 				resultItem = (JSONObject) result.getData().get(i); | 				resultItem = (JSONObject) result.getData().get(i); | ||||||
| 	            value = resultItem.getJSONObject(GetRemoteShareesOperation.NODE_VALUE); | 	            value = resultItem.getJSONObject(GetRemoteShareesOperation.NODE_VALUE); | ||||||
| 	            type = (byte) value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE); | 	            type = (byte) value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE); | ||||||
| @ -139,15 +139,15 @@ public class GetShareesTest extends RemoteTest { | |||||||
| 					userCount++; | 					userCount++; | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 			assertEquals(userCount, 2); | 			assertTrue(userCount > 0); | ||||||
| 			assertEquals(groupCount, 1); | 			assertTrue(groupCount > 0); | ||||||
| 		} catch (JSONException e) { | 		} catch (JSONException e) { | ||||||
| 			AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage()); | 			AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage()); | ||||||
| 			afe.setStackTrace(e.getStackTrace()); | 			afe.setStackTrace(e.getStackTrace()); | ||||||
| 			throw afe; | 			throw afe; | ||||||
| 		} | 		} | ||||||
| 		 | 
 | ||||||
| 		// search for sharees including "ad" | 		// search for sharees including "ad" - expecting user "admin" & group "admin" | ||||||
| 		getShareesOperation = new GetRemoteShareesOperation("ad", 1, 50); | 		getShareesOperation = new GetRemoteShareesOperation("ad", 1, 50); | ||||||
| 		result = getShareesOperation.execute(mClient); | 		result = getShareesOperation.execute(mClient); | ||||||
| 		assertTrue(result.isSuccess() && result.getData().size() == 2); | 		assertTrue(result.isSuccess() && result.getData().size() == 2); | ||||||
| @ -172,8 +172,8 @@ public class GetShareesTest extends RemoteTest { | |||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		 | 		 | ||||||
| 		// search for sharees including "b" | 		// search for sharees including "bd" - expecting 0 results | ||||||
| 		getShareesOperation = new GetRemoteShareesOperation("b", 1, 50); | 		getShareesOperation = new GetRemoteShareesOperation("bd", 1, 50); | ||||||
| 		result = getShareesOperation.execute(mClient); | 		result = getShareesOperation.execute(mClient); | ||||||
| 		assertTrue(result.isSuccess() && result.getData().size() == 0); | 		assertTrue(result.isSuccess() && result.getData().size() == 0); | ||||||
| 		 | 		 | ||||||
|  | |||||||
| @ -0,0 +1,259 @@ | |||||||
|  | /* ownCloud Android Library is available under MIT license | ||||||
|  |  *   @author masensio | ||||||
|  |  *   @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.test_project.test; | ||||||
|  | 
 | ||||||
|  | import java.io.File; | ||||||
|  | import java.security.GeneralSecurityException; | ||||||
|  | import java.util.Calendar; | ||||||
|  | 
 | ||||||
|  | import junit.framework.AssertionFailedError; | ||||||
|  | 
 | ||||||
|  | import org.apache.commons.httpclient.protocol.Protocol; | ||||||
|  | import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; | ||||||
|  | 
 | ||||||
|  | import android.content.Context; | ||||||
|  | import android.net.Uri; | ||||||
|  | import android.util.Log; | ||||||
|  | 
 | ||||||
|  | import com.owncloud.android.lib.common.OwnCloudClient; | ||||||
|  | import com.owncloud.android.lib.common.OwnCloudClientFactory; | ||||||
|  | import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; | ||||||
|  | import com.owncloud.android.lib.common.network.NetworkUtils; | ||||||
|  | import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||||||
|  | import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; | ||||||
|  | import com.owncloud.android.lib.resources.shares.OCShare; | ||||||
|  | import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation; | ||||||
|  | import com.owncloud.android.lib.resources.shares.ShareType; | ||||||
|  | import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation; | ||||||
|  | import com.owncloud.android.lib.test_project.R; | ||||||
|  | import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory; | ||||||
|  | import com.owncloud.android.lib.test_project.TestActivity; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Class to test UpdateRemoteShareOperation | ||||||
|  |  * with private shares | ||||||
|  |  * | ||||||
|  |  */ | ||||||
|  | public class UpdatePrivateShareTest extends RemoteTest { | ||||||
|  | 	private static final String LOG_TAG = UpdatePrivateShareTest.class.getCanonicalName(); | ||||||
|  | 	 | ||||||
|  | 	/* 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"; | ||||||
|  | 
 | ||||||
|  | 	/* Sharees */ | ||||||
|  | 	private static final String USER_SHAREE = "admin"; | ||||||
|  | 	private static final String GROUP_SHAREE = "admin"; | ||||||
|  | 
 | ||||||
|  | 	private String mFullPath2FileToShare; | ||||||
|  | 	private String mFullPath2FolderToShare; | ||||||
|  | 
 | ||||||
|  | 	private OCShare mFileShare; | ||||||
|  | 	private OCShare mFolderShare; | ||||||
|  | 
 | ||||||
|  | 	String mServerUri, mUser, mPass; | ||||||
|  | 	OwnCloudClient mClient = null; | ||||||
|  | 	 | ||||||
|  | 	public UpdatePrivateShareTest(){ | ||||||
|  | 		super(); | ||||||
|  | 		 | ||||||
|  | 		Protocol pr = Protocol.getProtocol("https"); | ||||||
|  | 		if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { | ||||||
|  | 			try { | ||||||
|  | 				ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); | ||||||
|  | 				Protocol.registerProtocol( | ||||||
|  | 						"https", | ||||||
|  | 						new Protocol("https", psf, 443)); | ||||||
|  | 				 | ||||||
|  | 			} catch (GeneralSecurityException e) { | ||||||
|  | 				throw new AssertionFailedError( | ||||||
|  | 						"Self-signed confident SSL context could not be loaded"); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	protected Context getContext() { | ||||||
|  | 		return getActivity(); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	@Override | ||||||
|  | 	protected void setUp() throws Exception { | ||||||
|  | 	    super.setUp(); | ||||||
|  | 
 | ||||||
|  | 	    // Next initialization cannot be done in the constructor because getContext() is not  | ||||||
|  | 	    // ready yet, returns NULL. | ||||||
|  | 	    initAccessToServer(getContext()); | ||||||
|  | 	     | ||||||
|  | 	    Log.v(LOG_TAG, "Setting up the remote fixture..."); | ||||||
|  | 	     | ||||||
|  | 	    // Upload the file | ||||||
|  | 	    mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE; | ||||||
|  | 	     | ||||||
|  | 	    File textFile = getActivity().extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); | ||||||
|  | 		RemoteOperationResult result = getActivity().uploadFile( | ||||||
|  | 				textFile.getAbsolutePath(),  | ||||||
|  | 				mFullPath2FileToShare,  | ||||||
|  | 				"txt/plain"); | ||||||
|  | 		if (!result.isSuccess()) { | ||||||
|  | 			Utils.logAndThrow(LOG_TAG, result); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		// Share the file privately with other user | ||||||
|  | 		result = getActivity().createShare( | ||||||
|  | 				mFullPath2FileToShare,  | ||||||
|  | 				ShareType.USER, | ||||||
|  | 				USER_SHAREE, | ||||||
|  | 				false,  | ||||||
|  | 				"",  | ||||||
|  | 				OCShare.MAXIMUM_PERMISSIONS_FOR_FILE); | ||||||
|  | 
 | ||||||
|  | 	    if (result.isSuccess()){ | ||||||
|  | 	    	mFileShare = (OCShare) result.getData().get(0); | ||||||
|  | 	    } else{ | ||||||
|  | 	    	mFileShare = null; | ||||||
|  | 	    } | ||||||
|  | 
 | ||||||
|  | 		// Create the folder | ||||||
|  | 		mFullPath2FolderToShare = mBaseFolderPath + FOLDER_TO_SHARE; | ||||||
|  | 		result = getActivity().createFolder( | ||||||
|  | 				mFullPath2FolderToShare, | ||||||
|  | 				true); | ||||||
|  | 		if (!result.isSuccess()) { | ||||||
|  | 			Utils.logAndThrow(LOG_TAG, result); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		// Share the folder privately with a group | ||||||
|  | 		result = getActivity().createShare( | ||||||
|  | 				mFullPath2FolderToShare, | ||||||
|  | 				ShareType.GROUP, | ||||||
|  | 				GROUP_SHAREE, | ||||||
|  | 				false, | ||||||
|  | 				"", | ||||||
|  | 				OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER); | ||||||
|  | 
 | ||||||
|  | 		if (result.isSuccess()){ | ||||||
|  | 			mFolderShare = (OCShare) result.getData().get(0); | ||||||
|  | 		} else{ | ||||||
|  | 			mFolderShare = null; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		Log.v(LOG_TAG, "Remote fixture created."); | ||||||
|  | 		 | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public void testUpdateSharePermissions() { | ||||||
|  | 		Log.v(LOG_TAG, "testUpdateSharePermissions in"); | ||||||
|  | 		 | ||||||
|  | 		if (mFileShare != null) { | ||||||
|  | 			/// successful tests | ||||||
|  | 			// Update Share permissions on a shared file | ||||||
|  | 			UpdateRemoteShareOperation updateShare = new UpdateRemoteShareOperation( | ||||||
|  | 					mFileShare.getRemoteId() | ||||||
|  | 			); | ||||||
|  | 			updateShare.setPermissions(OCShare.READ_PERMISSION_FLAG);	// minimum permissions | ||||||
|  | 			RemoteOperationResult result = updateShare.execute(mClient); | ||||||
|  | 			assertTrue(result.isSuccess()); | ||||||
|  | 
 | ||||||
|  | 			// Update Share permissions on a shared folder | ||||||
|  | 			updateShare = new UpdateRemoteShareOperation(mFolderShare.getRemoteId()); | ||||||
|  | 			updateShare.setPermissions(OCShare.READ_PERMISSION_FLAG + OCShare.DELETE_PERMISSION_FLAG); | ||||||
|  | 			result = updateShare.execute(mClient); | ||||||
|  | 			assertTrue(result.isSuccess()); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 			/// unsuccessful tests | ||||||
|  | 			// Update Share with invalid permissions | ||||||
|  | 			updateShare = new UpdateRemoteShareOperation(mFileShare.getRemoteId()); | ||||||
|  | 			// greater than maximum value | ||||||
|  | 			updateShare.setPermissions(OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER + 1); | ||||||
|  | 			result = updateShare.execute(mClient); | ||||||
|  | 			assertFalse(result.isSuccess()); | ||||||
|  | 
 | ||||||
|  | 			// Unshare the file before next unsuccessful tests | ||||||
|  | 			RemoveRemoteShareOperation unshare = new RemoveRemoteShareOperation( | ||||||
|  | 					(int) mFileShare.getRemoteId() | ||||||
|  | 			); | ||||||
|  | 			result = unshare.execute(mClient); | ||||||
|  | 			 | ||||||
|  | 			if (result.isSuccess()) {				 | ||||||
|  | 				// Update Share permissions on unknown share | ||||||
|  | 				UpdateRemoteShareOperation updateNoShare = new UpdateRemoteShareOperation( | ||||||
|  | 						mFileShare.getRemoteId() | ||||||
|  | 				); | ||||||
|  | 				updateShare.setPermissions(OCShare.READ_PERMISSION_FLAG);	// minimum permissions | ||||||
|  | 				result = updateShare.execute(mClient); | ||||||
|  | 				assertFalse(result.isSuccess()); | ||||||
|  | 			} | ||||||
|  | 				 | ||||||
|  | 		} 		 | ||||||
|  | 		 | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	protected void tearDown() throws Exception { | ||||||
|  | 	    Log.v(LOG_TAG, "Deleting remote fixture..."); | ||||||
|  | 		if (mFullPath2FileToShare != null) { | ||||||
|  | 			RemoteOperationResult removeResult = getActivity().removeFile(mFullPath2FileToShare); | ||||||
|  | 			if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { | ||||||
|  | 				Utils.logAndThrow(LOG_TAG, removeResult); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		super.tearDown(); | ||||||
|  | 	    Log.v(LOG_TAG, "Remote fixture delete."); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	 | ||||||
|  | 	private void initAccessToServer(Context context) { | ||||||
|  | 	    Log.v(LOG_TAG, "Setting up client instance to access OC server..."); | ||||||
|  | 		 | ||||||
|  | 		mServerUri = context.getString(R.string.server_base_url); | ||||||
|  | 		mUser = context.getString(R.string.username); | ||||||
|  | 		mPass = context.getString(R.string.password); | ||||||
|  | 		 | ||||||
|  | 		mClient = new OwnCloudClient( | ||||||
|  | 				Uri.parse(mServerUri),  | ||||||
|  | 				NetworkUtils.getMultiThreadedConnManager() | ||||||
|  | 		); | ||||||
|  | 		mClient.setDefaultTimeouts( | ||||||
|  | 				OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,  | ||||||
|  | 				OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT); | ||||||
|  | 		mClient.setFollowRedirects(true); | ||||||
|  | 		mClient.setCredentials( | ||||||
|  | 				OwnCloudCredentialsFactory.newBasicCredentials( | ||||||
|  | 						mUser,  | ||||||
|  | 						mPass | ||||||
|  | 				) | ||||||
|  | 		); | ||||||
|  | 		 | ||||||
|  | 	    Log.v(LOG_TAG, "Client instance set up."); | ||||||
|  | 	     | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -1,5 +1,6 @@ | |||||||
| /* ownCloud Android Library is available under MIT license | /* ownCloud Android Library is available under MIT license | ||||||
|  *   @author masensio |  *   @author masensio | ||||||
|  |  *   @author David A. Velasco | ||||||
|  *   Copyright (C) 2015 ownCloud Inc. |  *   Copyright (C) 2015 ownCloud Inc. | ||||||
|  *    |  *    | ||||||
|  *   Permission is hereby granted, free of charge, to any person obtaining a copy |  *   Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| @ -54,17 +55,18 @@ import com.owncloud.android.lib.test_project.TestActivity; | |||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Class to test UpdateRemoteShareOperation |  * Class to test UpdateRemoteShareOperation | ||||||
|  |  * with public shares | ||||||
|  * |  * | ||||||
|  */ |  */ | ||||||
| public class UpdateShareTest extends RemoteTest { | public class UpdatePublicShareTest extends RemoteTest { | ||||||
| 	private static final String LOG_TAG = UpdateShareTest.class.getCanonicalName(); | 	private static final String LOG_TAG = UpdatePublicShareTest.class.getCanonicalName(); | ||||||
| 	 | 	 | ||||||
| 	/* File to share and update.*/ | 	/* File to share and update.*/ | ||||||
| 	private static final String FILE_TO_SHARE = "/fileToShare.txt"; | 	private static final String FILE_TO_SHARE = "/fileToShare.txt"; | ||||||
| 	 | 	 | ||||||
| 	// Data for tests  | 	// Data for tests  | ||||||
| 	private static final String PASSWORD = "password"; | 	private static final String PASSWORD = "password"; | ||||||
| 	private static final String PASS_SPECIAL_CHARS = "p@sswórd"; | 	private static final String PASS_SPECIAL_CHARS = "p@ssw<EFBFBD>rd"; | ||||||
| 	 | 	 | ||||||
| 	private String mFullPath2FileToShare; | 	private String mFullPath2FileToShare; | ||||||
| 	 | 	 | ||||||
| @ -73,7 +75,7 @@ public class UpdateShareTest extends RemoteTest { | |||||||
| 	String mServerUri, mUser, mPass; | 	String mServerUri, mUser, mPass; | ||||||
| 	OwnCloudClient mClient = null; | 	OwnCloudClient mClient = null; | ||||||
| 	 | 	 | ||||||
| 	public UpdateShareTest(){ | 	public UpdatePublicShareTest(){ | ||||||
| 		super(); | 		super(); | ||||||
| 		 | 		 | ||||||
| 		Protocol pr = Protocol.getProtocol("https"); | 		Protocol pr = Protocol.getProtocol("https"); | ||||||
| @ -117,7 +119,7 @@ public class UpdateShareTest extends RemoteTest { | |||||||
| 			Utils.logAndThrow(LOG_TAG, result); | 			Utils.logAndThrow(LOG_TAG, result); | ||||||
| 		}	     | 		}	     | ||||||
| 		 | 		 | ||||||
| 		// Share the file | 		// Share the file with a public link | ||||||
| 		result = getActivity().createShare( | 		result = getActivity().createShare( | ||||||
| 				mFullPath2FileToShare,  | 				mFullPath2FileToShare,  | ||||||
| 				ShareType.PUBLIC_LINK,  | 				ShareType.PUBLIC_LINK,  | ||||||
| @ -137,8 +139,8 @@ public class UpdateShareTest extends RemoteTest { | |||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
| 	public void testUpdateRemoteShareOperation() { | 	public void testUpdatePublicShare() { | ||||||
| 		Log.v(LOG_TAG, "testUpdateShare in"); | 		Log.v(LOG_TAG, "testUpdatePublicShare in"); | ||||||
| 		 | 		 | ||||||
| 		if (mShare != null) { | 		if (mShare != null) { | ||||||
| 			// successful tests | 			// successful tests | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user