mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	2nd code review changes
Apply pending change
This commit is contained in:
		
							parent
							
								
									af6b18e042
								
							
						
					
					
						commit
						c2d8e68ecc
					
				| @ -33,6 +33,7 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.PostMethod | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperation | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||||
| import com.owncloud.android.lib.common.utils.Log_OC | ||||
| import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.INIT_EXPIRATION_DATE_IN_MILLIS | ||||
| import okhttp3.FormBody | ||||
| import java.net.URL | ||||
| import java.text.SimpleDateFormat | ||||
| @ -75,7 +76,7 @@ class CreateRemoteShareOperation | ||||
|     var password: String?, // Password to set for the public link | ||||
|     var permissions: Int // Access permissions for the file bound to the share | ||||
| ) : RemoteOperation<ShareParserResult>() { | ||||
|     var getShareDetails: Boolean = false | ||||
|     var getShareDetails: Boolean = false // To retrieve more info about the just created share | ||||
| 
 | ||||
|     /** | ||||
|      * Name to set for the public link | ||||
| @ -85,7 +86,7 @@ class CreateRemoteShareOperation | ||||
|     /** | ||||
|      * Expiration date to set for the public link | ||||
|      */ | ||||
|     var expirationDateInMillis: Long = INITIAL_EXPIRATION_DATE_IN_MILLIS | ||||
|     var expirationDateInMillis: Long = INIT_EXPIRATION_DATE_IN_MILLIS | ||||
| 
 | ||||
|     init { | ||||
|         getShareDetails = false        // defaults to false for backwards compatibility | ||||
| @ -104,7 +105,7 @@ class CreateRemoteShareOperation | ||||
|                 formBodyBuilder.add(PARAM_NAME, name) | ||||
|             } | ||||
| 
 | ||||
|             if (expirationDateInMillis > INITIAL_EXPIRATION_DATE_IN_MILLIS) { | ||||
|             if (expirationDateInMillis > INIT_EXPIRATION_DATE_IN_MILLIS) { | ||||
|                 val dateFormat = SimpleDateFormat(FORMAT_EXPIRATION_DATE, Locale.getDefault()) | ||||
|                 val expirationDate = Calendar.getInstance() | ||||
|                 expirationDate.timeInMillis = expirationDateInMillis | ||||
| @ -116,7 +117,7 @@ class CreateRemoteShareOperation | ||||
|                 formBodyBuilder.add(PARAM_PUBLIC_UPLOAD, publicUpload.toString()) | ||||
|             } | ||||
|             if (!password.isNullOrEmpty()) { | ||||
|                 formBodyBuilder.add(PARAM_PASSWORD, password!!) | ||||
|                 formBodyBuilder.add(PARAM_PASSWORD, password) | ||||
|             } | ||||
|             if (RemoteShare.DEFAULT_PERMISSION != permissions) { | ||||
|                 formBodyBuilder.add(PARAM_PERMISSIONS, Integer.toString(permissions)) | ||||
| @ -168,24 +169,19 @@ class CreateRemoteShareOperation | ||||
|         return result | ||||
|     } | ||||
| 
 | ||||
|     private fun isSuccess(status: Int): Boolean { | ||||
|         return status == HttpConstants.HTTP_OK | ||||
|     } | ||||
|     private fun isSuccess(status: Int): Boolean = status == HttpConstants.HTTP_OK | ||||
| 
 | ||||
|     companion object { | ||||
| 
 | ||||
|         private val TAG = CreateRemoteShareOperation::class.java.simpleName | ||||
| 
 | ||||
|         private val PARAM_NAME = "name" | ||||
|         private val PARAM_PASSWORD = "password" | ||||
|         private val PARAM_EXPIRATION_DATE = "expireDate" | ||||
|         private val PARAM_PUBLIC_UPLOAD = "publicUpload" | ||||
|         private val PARAM_PATH = "path" | ||||
|         private val PARAM_SHARE_TYPE = "shareType" | ||||
|         private val PARAM_SHARE_WITH = "shareWith" | ||||
|         private val PARAM_PERMISSIONS = "permissions" | ||||
|         private val FORMAT_EXPIRATION_DATE = "yyyy-MM-dd" | ||||
| 
 | ||||
|         const val INITIAL_EXPIRATION_DATE_IN_MILLIS : Long = 0 | ||||
|         private const val PARAM_NAME = "name" | ||||
|         private const val PARAM_PASSWORD = "password" | ||||
|         private const val PARAM_EXPIRATION_DATE = "expireDate" | ||||
|         private const val PARAM_PUBLIC_UPLOAD = "publicUpload" | ||||
|         private const val PARAM_PATH = "path" | ||||
|         private const val PARAM_SHARE_TYPE = "shareType" | ||||
|         private const val PARAM_SHARE_WITH = "shareWith" | ||||
|         private const val PARAM_PERMISSIONS = "permissions" | ||||
|         private const val FORMAT_EXPIRATION_DATE = "yyyy-MM-dd" | ||||
|     } | ||||
| } | ||||
| @ -1,124 +0,0 @@ | ||||
| /* ownCloud Android Library is available under MIT license | ||||
|  *   @author masensio | ||||
|  *   @author David A. Velasco | ||||
|  *   @author David González Verdugo | ||||
|  *   Copyright (C) 2019 ownCloud 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 android.net.Uri; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.OwnCloudClient; | ||||
| import com.owncloud.android.lib.common.http.HttpConstants; | ||||
| import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod; | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperation; | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| 
 | ||||
| import java.net.URL; | ||||
| 
 | ||||
| /** | ||||
|  * Provide a list shares for a specific file. | ||||
|  * The input is the full path of the desired file. | ||||
|  * The output is a list of everyone who has the file shared with them. | ||||
|  * | ||||
|  * @author masensio | ||||
|  * @author David A. Velasco | ||||
|  * @author David González Verdugo | ||||
|  */ | ||||
| public class GetRemoteSharesForFileOperation extends RemoteOperation<ShareParserResult> { | ||||
| 
 | ||||
|     private static final String TAG = GetRemoteSharesForFileOperation.class.getSimpleName(); | ||||
| 
 | ||||
|     private static final String PARAM_PATH = "path"; | ||||
|     private static final String PARAM_RESHARES = "reshares"; | ||||
|     private static final String PARAM_SUBFILES = "subfiles"; | ||||
| 
 | ||||
|     private String mRemoteFilePath; | ||||
|     private boolean mReshares; | ||||
|     private boolean mSubfiles; | ||||
| 
 | ||||
|     /** | ||||
|      * Constructor | ||||
|      * | ||||
|      * @param remoteFilePath Path to file or folder | ||||
|      * @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. | ||||
|      */ | ||||
|     public GetRemoteSharesForFileOperation(String remoteFilePath, boolean reshares, | ||||
|                                            boolean subfiles) { | ||||
|         mRemoteFilePath = remoteFilePath; | ||||
|         mReshares = reshares; | ||||
|         mSubfiles = subfiles; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected RemoteOperationResult<ShareParserResult> run(OwnCloudClient client) { | ||||
|         RemoteOperationResult<ShareParserResult> result; | ||||
| 
 | ||||
|         try { | ||||
| 
 | ||||
|             Uri requestUri = client.getBaseUri(); | ||||
|             Uri.Builder uriBuilder = requestUri.buildUpon(); | ||||
|             uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH); | ||||
|             uriBuilder.appendQueryParameter(PARAM_PATH, mRemoteFilePath); | ||||
|             uriBuilder.appendQueryParameter(PARAM_RESHARES, String.valueOf(mReshares)); | ||||
|             uriBuilder.appendQueryParameter(PARAM_SUBFILES, String.valueOf(mSubfiles)); | ||||
| 
 | ||||
|             GetMethod getMethod = new GetMethod(new URL(uriBuilder.build().toString())); | ||||
| 
 | ||||
|             getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||||
| 
 | ||||
|             int status = client.executeHttpMethod(getMethod); | ||||
| 
 | ||||
|             if (isSuccess(status)) { | ||||
|                 // Parse xml response and obtain the list of shares | ||||
|                 ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||
|                         new ShareXMLParser() | ||||
|                 ); | ||||
|                 parser.setOwnCloudVersion(client.getOwnCloudVersion()); | ||||
|                 parser.setServerBaseUri(client.getBaseUri()); | ||||
|                 result = parser.parse(getMethod.getResponseBodyAsString()); | ||||
| 
 | ||||
|                 if (result.isSuccess()) { | ||||
|                     Log_OC.d(TAG, "Got " + result.getData().getShares().size() + " shares"); | ||||
|                 } | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult<>(getMethod); | ||||
|             } | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult<>(e); | ||||
|             Log_OC.e(TAG, "Exception while getting shares", e); | ||||
|         } | ||||
| 
 | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
|     private boolean isSuccess(int status) { | ||||
|         return (status == HttpConstants.HTTP_OK); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,115 @@ | ||||
| /* ownCloud Android Library is available under MIT license | ||||
|  *   @author masensio | ||||
|  *   @author David A. Velasco | ||||
|  *   @author David González Verdugo | ||||
|  *   Copyright (C) 2019 ownCloud 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.lib.common.OwnCloudClient | ||||
| import com.owncloud.android.lib.common.http.HttpConstants | ||||
| import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperation | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||||
| import com.owncloud.android.lib.common.utils.Log_OC | ||||
| import java.net.URL | ||||
| 
 | ||||
| /** | ||||
|  * Provide a list shares for a specific file. | ||||
|  * The input is the full path of the desired file. | ||||
|  * The output is a list of everyone who has the file shared with them. | ||||
|  * | ||||
|  * @author masensio | ||||
|  * @author David A. Velasco | ||||
|  * @author David González Verdugo | ||||
|  */ | ||||
| 
 | ||||
| /** | ||||
|  * Constructor | ||||
|  * | ||||
|  * @param remoteFilePath Path to file or folder | ||||
|  * @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. | ||||
|  */ | ||||
| class GetRemoteSharesForFileOperation( | ||||
|     private val remoteFilePath: String, | ||||
|     private val reshares: Boolean, | ||||
|     private val subfiles: Boolean | ||||
| ) : RemoteOperation<ShareParserResult>() { | ||||
| 
 | ||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<ShareParserResult> { | ||||
|         var result: RemoteOperationResult<ShareParserResult> | ||||
| 
 | ||||
|         try { | ||||
| 
 | ||||
|             val requestUri = client.baseUri | ||||
|             val uriBuilder = requestUri.buildUpon() | ||||
|             uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH) | ||||
|             uriBuilder.appendQueryParameter(PARAM_PATH, remoteFilePath) | ||||
|             uriBuilder.appendQueryParameter(PARAM_RESHARES, reshares.toString()) | ||||
|             uriBuilder.appendQueryParameter(PARAM_SUBFILES, subfiles.toString()) | ||||
| 
 | ||||
|             val getMethod = GetMethod(URL(uriBuilder.build().toString())) | ||||
| 
 | ||||
|             getMethod.addRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE) | ||||
| 
 | ||||
|             val status = client.executeHttpMethod(getMethod) | ||||
| 
 | ||||
|             if (isSuccess(status)) { | ||||
|                 // Parse xml response and obtain the list of shares | ||||
|                 val parser = ShareToRemoteOperationResultParser( | ||||
|                     ShareXMLParser() | ||||
|                 ) | ||||
|                 parser.ownCloudVersion = client.ownCloudVersion | ||||
|                 parser.serverBaseUri = client.baseUri | ||||
|                 result = parser.parse(getMethod.responseBodyAsString) | ||||
| 
 | ||||
|                 if (result.isSuccess) { | ||||
|                     Log_OC.d(TAG, "Got " + result.data.shares.size + " shares") | ||||
|                 } | ||||
|             } else { | ||||
|                 result = RemoteOperationResult(getMethod) | ||||
|             } | ||||
|         } catch (e: Exception) { | ||||
|             result = RemoteOperationResult(e) | ||||
|             Log_OC.e(TAG, "Exception while getting shares", e) | ||||
|         } | ||||
| 
 | ||||
|         return result | ||||
|     } | ||||
| 
 | ||||
|     private fun isSuccess(status: Int): Boolean = status == HttpConstants.HTTP_OK | ||||
| 
 | ||||
|     companion object { | ||||
| 
 | ||||
|         private val TAG = GetRemoteSharesForFileOperation::class.java.simpleName | ||||
| 
 | ||||
|         private const val PARAM_PATH = "path" | ||||
|         private const val PARAM_RESHARES = "reshares" | ||||
|         private const val PARAM_SUBFILES = "subfiles" | ||||
|     } | ||||
| } | ||||
| @ -48,13 +48,12 @@ class RemoteShare : Parcelable, Serializable { | ||||
|     var fileSource: Long = 0 | ||||
|     var itemSource: Long = 0 | ||||
|     var shareType: ShareType? = null | ||||
|     var permissions: Int = 0 | ||||
|     var sharedDate: Long = 0 | ||||
|     var expirationDate: Long = 0 | ||||
|     var permissions: Int = INIT_PERMISSION | ||||
|     var sharedDate: Long = INIT_SHARED_DATE | ||||
|     var expirationDate: Long = INIT_EXPIRATION_DATE_IN_MILLIS | ||||
|     var isFolder: Boolean = false | ||||
|     var userId: Long = 0 | ||||
|     var remoteId: Long = 0 | ||||
|         private set | ||||
| 
 | ||||
|     val isPasswordProtected: Boolean | ||||
|         get() = ShareType.PUBLIC_LINK == shareType && shareWith.isNotEmpty() | ||||
| @ -65,7 +64,7 @@ class RemoteShare : Parcelable, Serializable { | ||||
| 
 | ||||
|     constructor(path: String?) { | ||||
|         resetData() | ||||
|         if (path == null || path.isEmpty() || !path.startsWith(FileUtils.PATH_SEPARATOR)) { | ||||
|         if (path.isNullOrEmpty() || !path.startsWith(FileUtils.PATH_SEPARATOR)) { | ||||
|             Log_OC.e(TAG, "Trying to create a RemoteShare with a non valid path") | ||||
|             throw IllegalArgumentException("Trying to create a RemoteShare with a non valid path: " + path!!) | ||||
|         } | ||||
| @ -87,18 +86,14 @@ class RemoteShare : Parcelable, Serializable { | ||||
|         itemSource = 0 | ||||
|         shareType = ShareType.NO_SHARED | ||||
|         permissions = DEFAULT_PERMISSION | ||||
|         sharedDate = 0 | ||||
|         expirationDate = 0 | ||||
|         sharedDate = INIT_SHARED_DATE | ||||
|         expirationDate = INIT_EXPIRATION_DATE_IN_MILLIS | ||||
|         sharedWithAdditionalInfo = "" | ||||
|         isFolder = false | ||||
|         userId = -1 | ||||
|         remoteId = -1 | ||||
|     } | ||||
| 
 | ||||
|     fun setIdRemoteShared(remoteId: Long) { | ||||
|         this.remoteId = remoteId | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Reconstruct from parcel | ||||
|      * | ||||
| @ -131,9 +126,7 @@ class RemoteShare : Parcelable, Serializable { | ||||
|         remoteId = source.readLong() | ||||
|     } | ||||
| 
 | ||||
|     override fun describeContents(): Int { | ||||
|         return this.hashCode() | ||||
|     } | ||||
|     override fun describeContents(): Int = this.hashCode() | ||||
| 
 | ||||
|     override fun writeToParcel(dest: Parcel, flags: Int) { | ||||
|         dest.writeString(shareWith) | ||||
| @ -145,7 +138,7 @@ class RemoteShare : Parcelable, Serializable { | ||||
|         dest.writeString(shareLink) | ||||
|         dest.writeLong(fileSource) | ||||
|         dest.writeLong(itemSource) | ||||
|         dest.writeString(if (shareType == null) "" else shareType!!.name) | ||||
|         dest.writeString(shareType?.name ?: "") | ||||
|         dest.writeInt(permissions) | ||||
|         dest.writeLong(sharedDate) | ||||
|         dest.writeLong(expirationDate) | ||||
| @ -163,29 +156,34 @@ class RemoteShare : Parcelable, Serializable { | ||||
| 
 | ||||
|         private val TAG = RemoteShare::class.java.simpleName | ||||
| 
 | ||||
|         val DEFAULT_PERMISSION = -1 | ||||
|         val READ_PERMISSION_FLAG = 1 | ||||
|         val UPDATE_PERMISSION_FLAG = 2 | ||||
|         val CREATE_PERMISSION_FLAG = 4 | ||||
|         val DELETE_PERMISSION_FLAG = 8 | ||||
|         val SHARE_PERMISSION_FLAG = 16 | ||||
|         val MAXIMUM_PERMISSIONS_FOR_FILE = READ_PERMISSION_FLAG + | ||||
|         const val INIT_PERMISSION = 0 | ||||
|         const val DEFAULT_PERMISSION = -1 | ||||
|         const val READ_PERMISSION_FLAG = 1 | ||||
|         const val UPDATE_PERMISSION_FLAG = 2 | ||||
|         const val CREATE_PERMISSION_FLAG = 4 | ||||
|         const val DELETE_PERMISSION_FLAG = 8 | ||||
|         const val SHARE_PERMISSION_FLAG = 16 | ||||
|         const val MAXIMUM_PERMISSIONS_FOR_FILE = READ_PERMISSION_FLAG + | ||||
|                 UPDATE_PERMISSION_FLAG + | ||||
|                 SHARE_PERMISSION_FLAG | ||||
|         val MAXIMUM_PERMISSIONS_FOR_FOLDER = MAXIMUM_PERMISSIONS_FOR_FILE + | ||||
|         const val MAXIMUM_PERMISSIONS_FOR_FOLDER = MAXIMUM_PERMISSIONS_FOR_FILE + | ||||
|                 CREATE_PERMISSION_FLAG + | ||||
|                 DELETE_PERMISSION_FLAG | ||||
|         val FEDERATED_PERMISSIONS_FOR_FILE_UP_TO_OC9 = READ_PERMISSION_FLAG + UPDATE_PERMISSION_FLAG | ||||
|         val FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9 = READ_PERMISSION_FLAG + | ||||
|         const val FEDERATED_PERMISSIONS_FOR_FILE_UP_TO_OC9 = READ_PERMISSION_FLAG + UPDATE_PERMISSION_FLAG | ||||
|         const val FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9 = READ_PERMISSION_FLAG + | ||||
|                 UPDATE_PERMISSION_FLAG + | ||||
|                 SHARE_PERMISSION_FLAG | ||||
|         val FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 = READ_PERMISSION_FLAG + | ||||
|         const val FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 = READ_PERMISSION_FLAG + | ||||
|                 UPDATE_PERMISSION_FLAG + | ||||
|                 CREATE_PERMISSION_FLAG + | ||||
|                 DELETE_PERMISSION_FLAG | ||||
|         val FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 = | ||||
|         const val FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 = | ||||
|             FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 + SHARE_PERMISSION_FLAG | ||||
| 
 | ||||
| 
 | ||||
|         const val INIT_EXPIRATION_DATE_IN_MILLIS : Long = 0 | ||||
|         const val INIT_SHARED_DATE : Long = 0 | ||||
| 
 | ||||
|         /** | ||||
|          * Parcelable Methods | ||||
|          */ | ||||
|  | ||||
| @ -43,13 +43,12 @@ import java.net.URL | ||||
|  * @author David González Verdugo | ||||
|  */ | ||||
| 
 | ||||
| class RemoveRemoteShareOperation | ||||
| /** | ||||
|  * Constructor | ||||
|  * | ||||
|  * @param remoteShareId Share ID | ||||
|  */ | ||||
|     (private val mRemoteShareId: Long) : RemoteOperation<ShareParserResult>() { | ||||
| class RemoveRemoteShareOperation(private val remoteShareId: Long) : RemoteOperation<ShareParserResult>() { | ||||
| 
 | ||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<ShareParserResult> { | ||||
|         var result: RemoteOperationResult<ShareParserResult> | ||||
| @ -58,7 +57,7 @@ class RemoveRemoteShareOperation | ||||
|             val requestUri = client.baseUri | ||||
|             val uriBuilder = requestUri.buildUpon() | ||||
|             uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH) | ||||
|             uriBuilder.appendEncodedPath(mRemoteShareId.toString()) | ||||
|             uriBuilder.appendEncodedPath(remoteShareId.toString()) | ||||
| 
 | ||||
|             val deleteMethod = DeleteMethod( | ||||
|                 URL(uriBuilder.build().toString()) | ||||
| @ -76,7 +75,7 @@ class RemoveRemoteShareOperation | ||||
|                 ) | ||||
|                 result = parser.parse(deleteMethod.responseBodyAsString) | ||||
| 
 | ||||
|                 Log_OC.d(TAG, "Unshare " + mRemoteShareId + ": " + result.logMessage) | ||||
|                 Log_OC.d(TAG, "Unshare " + remoteShareId + ": " + result.logMessage) | ||||
| 
 | ||||
|             } else { | ||||
|                 result = RemoteOperationResult(deleteMethod) | ||||
|  | ||||
| @ -32,7 +32,7 @@ package com.owncloud.android.lib.resources.shares | ||||
| class SharePermissionsBuilder { | ||||
| 
 | ||||
|     /** Set of permissions  */ | ||||
|     private var mPermissions = RemoteShare.READ_PERMISSION_FLAG    // READ is minimum permission | ||||
|     private var permissions = RemoteShare.READ_PERMISSION_FLAG    // READ is minimum permission | ||||
| 
 | ||||
|     /** | ||||
|      * Sets or clears permission to reshare a file or folder. | ||||
| @ -87,10 +87,10 @@ class SharePermissionsBuilder { | ||||
|     private fun updatePermission(permissionsFlag: Int, enable: Boolean) { | ||||
|         if (enable) { | ||||
|             // add permission | ||||
|             mPermissions = mPermissions or permissionsFlag | ||||
|             permissions = permissions or permissionsFlag | ||||
|         } else { | ||||
|             // delete permission | ||||
|             mPermissions = mPermissions and permissionsFlag.inv() | ||||
|             permissions = permissions and permissionsFlag.inv() | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @ -99,7 +99,5 @@ class SharePermissionsBuilder { | ||||
|      * | ||||
|      * @return An int value representing the accumulated set of permissions. | ||||
|      */ | ||||
|     fun build(): Int { | ||||
|         return mPermissions | ||||
|     } | ||||
|     fun build(): Int = permissions | ||||
| } | ||||
|  | ||||
| @ -47,7 +47,7 @@ class ShareToRemoteOperationResultParser(private var shareXmlParser: ShareXMLPar | ||||
|         } | ||||
| 
 | ||||
|         var result: RemoteOperationResult<ShareParserResult> | ||||
|         val resultData = ArrayList<RemoteShare>() | ||||
|         var resultData: List<RemoteShare>? | ||||
| 
 | ||||
|         try { | ||||
|             // Parse xml response and obtain the list of shares | ||||
| @ -61,25 +61,25 @@ class ShareToRemoteOperationResultParser(private var shareXmlParser: ShareXMLPar | ||||
|             if (shareXmlParser?.isSuccess!!) { | ||||
|                 if (!shares.isNullOrEmpty() || !oneOrMoreSharesRequired) { | ||||
|                     result = RemoteOperationResult(RemoteOperationResult.ResultCode.OK) | ||||
|                     if (shares != null) { | ||||
|                         for (share in shares) { | ||||
|                             resultData.add(share) | ||||
|                             // build the share link if not in the response | ||||
|                             // (needed for OC servers < 9.0.0, see ShareXMLParser.java#line256) | ||||
|                             if (share.shareType == ShareType.PUBLIC_LINK | ||||
|                                 && share.shareLink.isEmpty() | ||||
|                                 && share.token.isNotEmpty() | ||||
|                             ) { | ||||
| 
 | ||||
|                     resultData  = shares?.map { share -> | ||||
|                         if (share.shareType != ShareType.PUBLIC_LINK || | ||||
|                             share.shareLink.isNotEmpty() || | ||||
|                             share.token.isEmpty()) { | ||||
|                             return@map share | ||||
|                         } | ||||
| 
 | ||||
|                         if (serverBaseUri != null) { | ||||
|                             val sharingLinkPath = ShareUtils.getSharingLinkPath(ownCloudVersion) | ||||
|                             share.shareLink = serverBaseUri.toString() + sharingLinkPath + share.token | ||||
|                         }  else { | ||||
|                             Log_OC.e(TAG, "Couldn't build link for public share :(") | ||||
|                         } | ||||
| 
 | ||||
|                         share | ||||
|                     } | ||||
|                         } | ||||
|                     } | ||||
|                     result.setData(ShareParserResult(resultData, "")) | ||||
| 
 | ||||
|                     result.setData(ShareParserResult(ArrayList(resultData), "")) | ||||
| 
 | ||||
|                 } else { | ||||
|                     result = RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE) | ||||
|  | ||||
| @ -179,7 +179,7 @@ class ShareXMLParser { | ||||
|             } else if (name.equals(NODE_ID, ignoreCase = true)) {// Parse Create XML Response | ||||
|                 share = RemoteShare() | ||||
|                 val value = readNode(parser, NODE_ID) | ||||
|                 share.setIdRemoteShared(Integer.parseInt(value).toLong()) | ||||
|                 share.remoteId = Integer.parseInt(value).toLong() | ||||
| 
 | ||||
|             } else if (name.equals(NODE_URL, ignoreCase = true)) { | ||||
|                 // NOTE: this field is received in all the public shares from OC 9.0.0 | ||||
| @ -235,7 +235,7 @@ class ShareXMLParser { | ||||
|                 readElement(parser, shares) | ||||
| 
 | ||||
|             } else if (name.equals(NODE_ID, ignoreCase = true)) { | ||||
|                 share.setIdRemoteShared(Integer.parseInt(readNode(parser, NODE_ID)).toLong()) | ||||
|                 share.remoteId = Integer.parseInt(readNode(parser, NODE_ID)).toLong() | ||||
| 
 | ||||
|             } else if (name.equals(NODE_ITEM_TYPE, ignoreCase = true)) { | ||||
|                 share.isFolder = readNode(parser, NODE_ITEM_TYPE).equals(TYPE_FOLDER, ignoreCase = true) | ||||
|  | ||||
| @ -31,6 +31,7 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.PutMethod | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperation | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||||
| import com.owncloud.android.lib.common.utils.Log_OC | ||||
| import com.owncloud.android.lib.resources.shares.RemoteShare.Companion.INIT_PERMISSION | ||||
| import okhttp3.FormBody | ||||
| import java.net.URL | ||||
| import java.text.SimpleDateFormat | ||||
| @ -53,84 +54,34 @@ class UpdateRemoteShareOperation | ||||
|  * | ||||
|  * @param remoteId Identifier of the share to update. | ||||
|  */ | ||||
|     ( | ||||
|     /** | ||||
|      * Identifier of the share to update | ||||
|      */ | ||||
|     private val remoteId: Long | ||||
| ) : RemoteOperation<ShareParserResult>() { | ||||
|     (private val remoteId: Long) : RemoteOperation<ShareParserResult>() { | ||||
| 
 | ||||
|     /** | ||||
|      * Password to set for the public link | ||||
|      */ | ||||
|     private var password: String? = null | ||||
| 
 | ||||
|     /** | ||||
|      * Expiration date to set for the public link | ||||
|      */ | ||||
|     private var expirationDateInMillis: Long = 0 | ||||
| 
 | ||||
|     /** | ||||
|      * Access permissions for the file bound to the share | ||||
|      */ | ||||
|     private var permissions: Int = 0 | ||||
| 
 | ||||
|     /** | ||||
|      * Upload permissions for the public link (only folders) | ||||
|      */ | ||||
|     private var publicUpload: Boolean? = null | ||||
|     private var name: String? = null | ||||
| 
 | ||||
|     init { | ||||
|         password = null               // no update | ||||
|         expirationDateInMillis = 0    // no update | ||||
|         publicUpload = null | ||||
|         permissions = RemoteShare.DEFAULT_PERMISSION | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Set name to update in Share resource. Ignored by servers previous to version 10.0.0 | ||||
|      * | ||||
|      * @param name Name to set to the target share. | ||||
|      * Empty string clears the current name. | ||||
|      * Null results in no update applied to the name. | ||||
|      */ | ||||
|     fun setName(name: String) { | ||||
|         this.name = name | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Set password to update in Share resource. | ||||
|      * Password to update in Share resource. | ||||
|      * | ||||
|      * @param password Password to set to the target share. | ||||
|      * Empty string clears the current password. | ||||
|      * Null results in no update applied to the password. | ||||
|      */ | ||||
|     fun setPassword(password: String) { | ||||
|         this.password = password | ||||
|     } | ||||
|     var password: String? = null | ||||
| 
 | ||||
|     /** | ||||
|      * Set expiration date to update in Share resource. | ||||
|      * Expiration date to update in Share resource. | ||||
|      * | ||||
|      * @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. | ||||
|      */ | ||||
|     fun setExpirationDate(expirationDateInMillis: Long) { | ||||
|         this.expirationDateInMillis = expirationDateInMillis | ||||
|     } | ||||
|     var expirationDateInMillis: Long = INITIAL_EXPIRATION_DATE_IN_MILLIS | ||||
| 
 | ||||
|     /** | ||||
|      * Set permissions to update in Share resource. | ||||
|      * Permissions to update in Share resource. | ||||
|      * | ||||
|      * @param permissions Permissions to set to the target share. | ||||
|      * Values <= 0 result in no update applied to the permissions. | ||||
|      */ | ||||
|     fun setPermissions(permissions: Int) { | ||||
|         this.permissions = permissions | ||||
|     } | ||||
|     var permissions: Int = INIT_PERMISSION | ||||
| 
 | ||||
|     /** | ||||
|      * Enable upload permissions to update in Share resource. | ||||
| @ -138,8 +89,21 @@ class UpdateRemoteShareOperation | ||||
|      * @param publicUpload Upload permission to set to the target share. | ||||
|      * Null results in no update applied to the upload permission. | ||||
|      */ | ||||
|     fun setPublicUpload(publicUpload: Boolean?) { | ||||
|         this.publicUpload = publicUpload | ||||
|     var publicUpload: Boolean? = null | ||||
|     /** | ||||
|      * Name to update in Share resource. Ignored by servers previous to version 10.0.0 | ||||
|      * | ||||
|      * @param name Name to set to the target share. | ||||
|      * Empty string clears the current name. | ||||
|      * Null results in no update applied to the name. | ||||
|      */ | ||||
|     var name: String? = null | ||||
| 
 | ||||
|     init { | ||||
|         password = null               // no update | ||||
|         expirationDateInMillis = INITIAL_EXPIRATION_DATE_IN_MILLIS    // no update | ||||
|         publicUpload = null | ||||
|         permissions = RemoteShare.DEFAULT_PERMISSION | ||||
|     } | ||||
| 
 | ||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<ShareParserResult> { | ||||
| @ -153,11 +117,11 @@ class UpdateRemoteShareOperation | ||||
|                 formBodyBuilder.add(PARAM_NAME, name!!) | ||||
|             } | ||||
| 
 | ||||
|             if (expirationDateInMillis < 0) { | ||||
|             if (expirationDateInMillis < INITIAL_EXPIRATION_DATE_IN_MILLIS) { | ||||
|                 // clear expiration date | ||||
|                 formBodyBuilder.add(PARAM_EXPIRATION_DATE, "") | ||||
| 
 | ||||
|             } else if (expirationDateInMillis > 0) { | ||||
|             } else if (expirationDateInMillis > INITIAL_EXPIRATION_DATE_IN_MILLIS) { | ||||
|                 // set expiration date | ||||
|                 val dateFormat = SimpleDateFormat(FORMAT_EXPIRATION_DATE, Locale.getDefault()) | ||||
|                 val expirationDate = Calendar.getInstance() | ||||
| @ -172,7 +136,7 @@ class UpdateRemoteShareOperation | ||||
| 
 | ||||
|             // IMPORTANT: permissions parameter needs to be updated after mPublicUpload parameter, | ||||
|             // otherwise they would be set always as 1 (READ) in the server when mPublicUpload was updated | ||||
|             if (permissions > 0) { | ||||
|             if (permissions > INIT_PERMISSION) { | ||||
|                 // set permissions | ||||
|                 formBodyBuilder.add(PARAM_PERMISSIONS, permissions.toString()) | ||||
|             } | ||||
| @ -212,21 +176,21 @@ class UpdateRemoteShareOperation | ||||
|         return result | ||||
|     } | ||||
| 
 | ||||
|     private fun isSuccess(status: Int): Boolean { | ||||
|         return status == HttpConstants.HTTP_OK | ||||
|     } | ||||
|     private fun isSuccess(status: Int): Boolean = status == HttpConstants.HTTP_OK | ||||
| 
 | ||||
|     companion object { | ||||
| 
 | ||||
|         private val TAG = GetRemoteShareOperation::class.java.simpleName | ||||
| 
 | ||||
|         private val PARAM_NAME = "name" | ||||
|         private val PARAM_PASSWORD = "password" | ||||
|         private val PARAM_EXPIRATION_DATE = "expireDate" | ||||
|         private val PARAM_PERMISSIONS = "permissions" | ||||
|         private val PARAM_PUBLIC_UPLOAD = "publicUpload" | ||||
|         private val FORMAT_EXPIRATION_DATE = "yyyy-MM-dd" | ||||
|         private val ENTITY_CONTENT_TYPE = "application/x-www-form-urlencoded" | ||||
|         private val ENTITY_CHARSET = "UTF-8" | ||||
|         private const val PARAM_NAME = "name" | ||||
|         private const val PARAM_PASSWORD = "password" | ||||
|         private const val PARAM_EXPIRATION_DATE = "expireDate" | ||||
|         private const val PARAM_PERMISSIONS = "permissions" | ||||
|         private const val PARAM_PUBLIC_UPLOAD = "publicUpload" | ||||
|         private const val FORMAT_EXPIRATION_DATE = "yyyy-MM-dd" | ||||
|         private const val ENTITY_CONTENT_TYPE = "application/x-www-form-urlencoded" | ||||
|         private const val ENTITY_CHARSET = "UTF-8" | ||||
| 
 | ||||
|         private const val INITIAL_EXPIRATION_DATE_IN_MILLIS : Long = 0 | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user