mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 10:27:45 +00:00 
			
		
		
		
	Added support to update share permissions
This commit is contained in:
		
							parent
							
								
									dad5cd115a
								
							
						
					
					
						commit
						249cb901eb
					
				| @ -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()); | ||||||
|         } |         } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user