mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Modify remote operations to create or update shares
This commit is contained in:
parent
688a978b1e
commit
4849be5daa
@ -65,8 +65,7 @@ import java.util.Locale
|
||||
* To obtain combinations, add the desired values together.
|
||||
* For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27.
|
||||
*/
|
||||
class CreateRemoteShareOperation
|
||||
(
|
||||
class CreateRemoteShareOperation(
|
||||
private val remoteFilePath: String,
|
||||
private val shareType: ShareType,
|
||||
private val shareWith: String,
|
||||
@ -107,10 +106,10 @@ class CreateRemoteShareOperation
|
||||
formBodyBuilder.add(PARAM_EXPIRATION_DATE, formattedExpirationDate)
|
||||
}
|
||||
|
||||
if (publicUpload == true) {
|
||||
if (publicUpload) {
|
||||
formBodyBuilder.add(PARAM_PUBLIC_UPLOAD, publicUpload.toString())
|
||||
}
|
||||
if (!password.isNullOrEmpty()) {
|
||||
if (password.isNotEmpty()) {
|
||||
formBodyBuilder.add(PARAM_PASSWORD, password)
|
||||
}
|
||||
if (RemoteShare.DEFAULT_PERMISSION != permissions) {
|
||||
@ -126,7 +125,7 @@ class CreateRemoteShareOperation
|
||||
postMethod.setRequestBody(formBodyBuilder.build())
|
||||
|
||||
postMethod.setRequestHeader(HttpConstants.CONTENT_TYPE_HEADER, HttpConstants.CONTENT_TYPE_URLENCODED_UTF8)
|
||||
postMethod.addRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE)
|
||||
postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
||||
|
||||
val status = client.executeHttpMethod(postMethod)
|
||||
|
||||
@ -141,7 +140,6 @@ class CreateRemoteShareOperation
|
||||
result = parser.parse(postMethod.responseBodyAsString)
|
||||
|
||||
if (result.isSuccess && retrieveShareDetails) {
|
||||
|
||||
// TODO Use executeHttpMethod
|
||||
// retrieve more info - POST only returns the index of the new share
|
||||
val emptyShare = result.data.shares[0]
|
||||
|
@ -49,7 +49,7 @@ class RemoteShare : Parcelable, Serializable {
|
||||
var fileSource: Long = 0
|
||||
var itemSource: Long = 0
|
||||
var shareType: ShareType? = null
|
||||
var permissions: Int = INIT_PERMISSION
|
||||
var permissions: Int = DEFAULT_PERMISSION
|
||||
var sharedDate: Long = INIT_SHARED_DATE
|
||||
var expirationDate: Long = INIT_EXPIRATION_DATE_IN_MILLIS
|
||||
var isFolder: Boolean = false
|
||||
@ -156,7 +156,6 @@ class RemoteShare : Parcelable, Serializable {
|
||||
|
||||
private val TAG = RemoteShare::class.java.simpleName
|
||||
|
||||
const val INIT_PERMISSION = 0
|
||||
const val DEFAULT_PERMISSION = -1
|
||||
const val READ_PERMISSION_FLAG = 1
|
||||
const val UPDATE_PERMISSION_FLAG = 2
|
||||
|
@ -31,7 +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 com.owncloud.android.lib.resources.shares.RemoteShare.Companion.DEFAULT_PERMISSION
|
||||
import okhttp3.FormBody
|
||||
import java.net.URL
|
||||
import java.text.SimpleDateFormat
|
||||
@ -51,11 +51,14 @@ import java.util.Locale
|
||||
class UpdateRemoteShareOperation
|
||||
/**
|
||||
* Constructor. No update is initialized by default, need to be applied with setters below.
|
||||
*
|
||||
* @param remoteId Identifier of the share to update.
|
||||
*/
|
||||
(private val remoteId: Long) : RemoteOperation<ShareParserResult>() {
|
||||
(
|
||||
/**
|
||||
* @param remoteId Identifier of the share to update.
|
||||
*/
|
||||
private val remoteId: Long
|
||||
|
||||
) : RemoteOperation<ShareParserResult>() {
|
||||
/**
|
||||
* Password to update in Share resource.
|
||||
*
|
||||
@ -81,7 +84,7 @@ class UpdateRemoteShareOperation
|
||||
* @param permissions Permissions to set to the target share.
|
||||
* Values <= 0 result in no update applied to the permissions.
|
||||
*/
|
||||
var permissions: Int = INIT_PERMISSION
|
||||
var permissions: Int = DEFAULT_PERMISSION
|
||||
|
||||
/**
|
||||
* Enable upload permissions to update in Share resource.
|
||||
@ -90,6 +93,7 @@ class UpdateRemoteShareOperation
|
||||
* Null results in no update applied to the upload permission.
|
||||
*/
|
||||
var publicUpload: Boolean? = null
|
||||
|
||||
/**
|
||||
* Name to update in Share resource. Ignored by servers previous to version 10.0.0
|
||||
*
|
||||
@ -99,13 +103,6 @@ class UpdateRemoteShareOperation
|
||||
*/
|
||||
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> {
|
||||
var result: RemoteOperationResult<ShareParserResult>
|
||||
|
||||
@ -114,7 +111,7 @@ class UpdateRemoteShareOperation
|
||||
|
||||
// Parameters to update
|
||||
if (name != null) {
|
||||
formBodyBuilder.add(PARAM_NAME, name!!)
|
||||
formBodyBuilder.add(PARAM_NAME, name)
|
||||
}
|
||||
|
||||
if (expirationDateInMillis < INITIAL_EXPIRATION_DATE_IN_MILLIS) {
|
||||
@ -136,7 +133,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 > INIT_PERMISSION) {
|
||||
if (permissions > DEFAULT_PERMISSION) {
|
||||
// set permissions
|
||||
formBodyBuilder.add(PARAM_PERMISSIONS, permissions.toString())
|
||||
}
|
||||
@ -179,7 +176,6 @@ class UpdateRemoteShareOperation
|
||||
private fun isSuccess(status: Int): Boolean = status == HttpConstants.HTTP_OK
|
||||
|
||||
companion object {
|
||||
|
||||
private val TAG = GetRemoteShareOperation::class.java.simpleName
|
||||
|
||||
private const val PARAM_NAME = "name"
|
||||
@ -191,6 +187,6 @@ class UpdateRemoteShareOperation
|
||||
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
|
||||
private const val INITIAL_EXPIRATION_DATE_IN_MILLIS: Long = 0
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user