1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

Compare commits

..

No commits in common. "master" and "2.1-beta.1" have entirely different histories.

29 changed files with 101 additions and 429 deletions

View File

@ -49,6 +49,6 @@ ownCloud Android Library uses OkHttp version 4.6.0, licensed under Apache Licens
### Compatibility ### Compatibility
ownCloud Android Library is valid for Android systems from version Android 6 (android:minSdkVersion="23" android:targetSdkVersion="33"). ownCloud Android Library is valid for Android systems from version Android 5 (android:minSdkVersion="21" android:targetSdkVersion="29").
ownCloud Android library supports ownCloud server from version 4.5. ownCloud Android library supports ownCloud server from version 4.5.

View File

@ -17,7 +17,7 @@ dependencies {
ksp "com.squareup.moshi:moshi-kotlin-codegen:$comSquareupMoshi" ksp "com.squareup.moshi:moshi-kotlin-codegen:$comSquareupMoshi"
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
testImplementation 'org.robolectric:robolectric:4.10' testImplementation 'org.robolectric:robolectric:4.9.2'
debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0' debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
} }
@ -25,8 +25,8 @@ android {
compileSdkVersion 33 compileSdkVersion 33
defaultConfig { defaultConfig {
minSdkVersion 23 minSdkVersion 21
targetSdkVersion 33 targetSdkVersion 31
} }
lint { lint {

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- ownCloud Android Library is available under MIT license <!-- ownCloud Android Library is available under MIT license
Copyright (C) 2023 ownCloud GmbH. Copyright (C) 2016 ownCloud GmbH.
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
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@ -25,6 +25,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- USE_CREDENTIALS, MANAGE_ACCOUNTS and AUTHENTICATE_ACCOUNTS are needed for API < 23.
In API >= 23 the do not exist anymore -->
<uses-permission
android:name="android.permission.MANAGE_ACCOUNTS"
android:maxSdkVersion="22" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest> </manifest>

View File

@ -43,7 +43,6 @@ import timber.log.Timber;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import java.util.Locale;
import static com.owncloud.android.lib.common.http.HttpConstants.AUTHORIZATION_HEADER; import static com.owncloud.android.lib.common.http.HttpConstants.AUTHORIZATION_HEADER;
import static com.owncloud.android.lib.common.http.HttpConstants.HTTP_MOVED_PERMANENTLY; import static com.owncloud.android.lib.common.http.HttpConstants.HTTP_MOVED_PERMANENTLY;
@ -129,7 +128,6 @@ public class OwnCloudClient extends HttpClient {
Timber.d("Executing in request with id %s", requestId); Timber.d("Executing in request with id %s", requestId);
method.setRequestHeader(HttpConstants.OC_X_REQUEST_ID, requestId); method.setRequestHeader(HttpConstants.OC_X_REQUEST_ID, requestId);
method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent()); method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
method.setRequestHeader(HttpConstants.ACCEPT_LANGUAGE_HEADER, Locale.getDefault().getLanguage());
method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY); method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY);
if (mCredentials.getHeaderAuth() != null && !mCredentials.getHeaderAuth().isEmpty()) { if (mCredentials.getHeaderAuth() != null && !mCredentials.getHeaderAuth().isEmpty()) {
method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth()); method.setRequestHeader(AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());

View File

@ -40,7 +40,6 @@ public class HttpConstants {
public static final String IF_MATCH_HEADER = "If-Match"; public static final String IF_MATCH_HEADER = "If-Match";
public static final String IF_NONE_MATCH_HEADER = "If-None-Match"; public static final String IF_NONE_MATCH_HEADER = "If-None-Match";
public static final String CONTENT_TYPE_HEADER = "Content-Type"; public static final String CONTENT_TYPE_HEADER = "Content-Type";
public static final String ACCEPT_LANGUAGE_HEADER = "Accept-Language";
public static final String CONTENT_LENGTH_HEADER = "Content-Length"; public static final String CONTENT_LENGTH_HEADER = "Content-Length";
public static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length"; public static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length";
public static final String OC_X_OC_MTIME_HEADER = "X-OC-Mtime"; public static final String OC_X_OC_MTIME_HEADER = "X-OC-Mtime";

View File

@ -36,7 +36,7 @@ import java.net.URL
class CopyMethod( class CopyMethod(
val url: URL, val url: URL,
private val destinationUrl: String, private val destinationUrl: String,
val forceOverride: Boolean = false private val forceOverride: Boolean = false
) : DavMethod(url) { ) : DavMethod(url) {
@Throws(Exception::class) @Throws(Exception::class)
public override fun onDavExecute(davResource: DavOCResource): Int { public override fun onDavExecute(davResource: DavOCResource): Int {

View File

@ -36,7 +36,7 @@ import java.net.URL
class MoveMethod( class MoveMethod(
url: URL, url: URL,
private val destinationUrl: String, private val destinationUrl: String,
val forceOverride: Boolean = false private val forceOverride: Boolean = false
) : DavMethod(url) { ) : DavMethod(url) {
@Throws(Exception::class) @Throws(Exception::class)
override fun onDavExecute(davResource: DavOCResource): Int { override fun onDavExecute(davResource: DavOCResource): Int {

View File

@ -46,7 +46,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.Serializable; import java.io.Serializable;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.SocketException; import java.net.SocketException;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
@ -167,10 +166,7 @@ public class RemoteOperationResult<T>
} else if (e instanceof FileNotFoundException) { } else if (e instanceof FileNotFoundException) {
mCode = ResultCode.LOCAL_FILE_NOT_FOUND; mCode = ResultCode.LOCAL_FILE_NOT_FOUND;
} else if (e instanceof ProtocolException) { } else {
mCode = ResultCode.NETWORK_ERROR;
}
else {
mCode = ResultCode.UNKNOWN_ERROR; mCode = ResultCode.UNKNOWN_ERROR;
} }
} }
@ -593,6 +589,5 @@ public class RemoteOperationResult<T>
SPECIFIC_METHOD_NOT_ALLOWED, SPECIFIC_METHOD_NOT_ALLOWED,
SPECIFIC_BAD_REQUEST, SPECIFIC_BAD_REQUEST,
TOO_EARLY, TOO_EARLY,
NETWORK_ERROR,
} }
} }

View File

@ -1,108 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2023 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.appregistry
import com.owncloud.android.lib.common.OwnCloudClient
import com.owncloud.android.lib.common.http.HttpConstants
import com.owncloud.android.lib.common.http.methods.nonwebdav.PostMethod
import com.owncloud.android.lib.common.network.WebdavUtils
import com.owncloud.android.lib.common.operations.RemoteOperation
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
import com.squareup.moshi.Json
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonClass
import com.squareup.moshi.Moshi
import okhttp3.FormBody
import okhttp3.RequestBody
import timber.log.Timber
import java.net.URL
import java.util.concurrent.TimeUnit
class CreateRemoteFileWithAppProviderOperation(
private val createFileWithAppProviderEndpoint: String,
private val parentContainerId: String,
private val filename: String,
) : RemoteOperation<String>() {
override fun run(client: OwnCloudClient): RemoteOperationResult<String> {
return try {
val createFileWithAppProviderRequestBody = CreateFileWithAppProviderParams(parentContainerId, filename)
.toRequestBody()
val stringUrl = client.baseUri.toString() + WebdavUtils.encodePath(createFileWithAppProviderEndpoint)
val postMethod = PostMethod(URL(stringUrl), createFileWithAppProviderRequestBody).apply {
setReadTimeout(TIMEOUT, TimeUnit.MILLISECONDS)
setConnectionTimeout(TIMEOUT, TimeUnit.MILLISECONDS)
}
val status = client.executeHttpMethod(postMethod)
Timber.d("Create file $filename with app provider in folder with ID $parentContainerId - $status${if (!isSuccess(status)) "(FAIL)" else ""}")
if (isSuccess(status)) RemoteOperationResult<String>(ResultCode.OK).apply {
val moshi = Moshi.Builder().build()
val adapter: JsonAdapter<CreateFileWithAppProviderResponse> = moshi.adapter(CreateFileWithAppProviderResponse::class.java)
data = postMethod.getResponseBodyAsString()?.let { adapter.fromJson(it)!!.fileId }
}
else RemoteOperationResult<String>(postMethod).apply { data = "" }
} catch (e: Exception) {
val result = RemoteOperationResult<String>(e)
Timber.e(e, "Create file $filename with app provider in folder with ID $parentContainerId failed")
result
}
}
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK
data class CreateFileWithAppProviderParams(
val parentContainerId: String,
val filename: String,
) {
fun toRequestBody(): RequestBody =
FormBody.Builder()
.add(PARAM_PARENT_CONTAINER_ID, parentContainerId)
.add(PARAM_FILENAME, filename)
.build()
companion object {
const val PARAM_PARENT_CONTAINER_ID = "parent_container_id"
const val PARAM_FILENAME = "filename"
}
}
@JsonClass(generateAdapter = true)
data class CreateFileWithAppProviderResponse(
@Json(name = "file_id")
val fileId: String,
)
companion object {
private const val TIMEOUT: Long = 5_000
}
}

View File

@ -1,78 +0,0 @@
/* ownCloud Android Library is available under MIT license
* @author Abel García de Prada
*
* Copyright (C) 2023 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.appregistry
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.operations.RemoteOperationResult.ResultCode.OK
import com.owncloud.android.lib.resources.appregistry.responses.AppRegistryResponse
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import timber.log.Timber
import java.net.URL
class GetRemoteAppRegistryOperation(private val appUrl: String?) : RemoteOperation<AppRegistryResponse>() {
override fun run(client: OwnCloudClient): RemoteOperationResult<AppRegistryResponse> {
var result: RemoteOperationResult<AppRegistryResponse>
try {
val uriBuilder = client.baseUri.buildUpon().apply {
appendEncodedPath(appUrl)
}
val getMethod = GetMethod(URL(uriBuilder.build().toString()))
val status = client.executeHttpMethod(getMethod)
val response = getMethod.getResponseBodyAsString()
if (status == HttpConstants.HTTP_OK) {
Timber.d("Successful response $response")
// Parse the response
val moshi: Moshi = Moshi.Builder().build()
val adapter: JsonAdapter<AppRegistryResponse> = moshi.adapter(AppRegistryResponse::class.java)
val appRegistryResponse: AppRegistryResponse = response?.let { adapter.fromJson(it) } ?: AppRegistryResponse(value = emptyList())
result = RemoteOperationResult(OK)
result.data = appRegistryResponse
Timber.d("Get AppRegistry completed and parsed to ${result.data}")
} else {
result = RemoteOperationResult(getMethod)
Timber.e("Failed response while getting app registry from the server status code: $status; response message: $response")
}
} catch (e: Exception) {
result = RemoteOperationResult(e)
Timber.e(e, "Exception while getting app registry")
}
return result
}
}

View File

@ -1,56 +0,0 @@
/* ownCloud Android Library is available under MIT license
* @author Abel García de Prada
*
* Copyright (C) 2023 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.appregistry.responses
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class AppRegistryResponse(
@Json(name = "mime-types")
val value: List<AppRegistryMimeTypeResponse>
)
@JsonClass(generateAdapter = true)
data class AppRegistryMimeTypeResponse(
@Json(name = "mime_type") val mimeType: String,
val ext: String? = null,
@Json(name = "app_providers")
val appProviders: List<AppRegistryProviderResponse>,
val name: String? = null,
val icon: String? = null,
val description: String? = null,
@Json(name = "allow_creation")
val allowCreation: Boolean? = null,
@Json(name = "default_application")
val defaultApplication: String? = null
)
@JsonClass(generateAdapter = true)
data class AppRegistryProviderResponse(
val name: String,
val icon: String,
)

View File

@ -1,44 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2023 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.appregistry.services
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.resources.Service
import com.owncloud.android.lib.resources.appregistry.responses.AppRegistryResponse
interface AppRegistryService : Service {
fun getAppRegistry(appUrl: String?): RemoteOperationResult<AppRegistryResponse>
fun getUrlToOpenInWeb(
openWebEndpoint: String,
fileId: String,
appName: String,
): RemoteOperationResult<String>
fun createFileWithAppProvider(
createFileWithAppProviderEndpoint: String,
parentContainerId: String,
filename: String,
): RemoteOperationResult<String>
}

View File

@ -1,54 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2023 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.appregistry.services
import com.owncloud.android.lib.common.OwnCloudClient
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.resources.appregistry.CreateRemoteFileWithAppProviderOperation
import com.owncloud.android.lib.resources.appregistry.GetRemoteAppRegistryOperation
import com.owncloud.android.lib.resources.appregistry.GetUrlToOpenInWebRemoteOperation
import com.owncloud.android.lib.resources.appregistry.responses.AppRegistryResponse
class OCAppRegistryService(override val client: OwnCloudClient) : AppRegistryService {
override fun getAppRegistry(appUrl: String?): RemoteOperationResult<AppRegistryResponse> =
GetRemoteAppRegistryOperation(appUrl).execute(client)
override fun getUrlToOpenInWeb(openWebEndpoint: String, fileId: String, appName: String): RemoteOperationResult<String> =
GetUrlToOpenInWebRemoteOperation(
openWithWebEndpoint = openWebEndpoint,
fileId = fileId,
appName = appName
).execute(client)
override fun createFileWithAppProvider(
createFileWithAppProviderEndpoint: String,
parentContainerId: String,
filename: String
): RemoteOperationResult<String> =
CreateRemoteFileWithAppProviderOperation(
createFileWithAppProviderEndpoint = createFileWithAppProviderEndpoint,
parentContainerId = parentContainerId,
filename = filename,
).execute(client)
}

View File

@ -54,8 +54,9 @@ class CheckPathExistenceRemoteOperation(
) : RemoteOperation<Boolean>() { ) : RemoteOperation<Boolean>() {
override fun run(client: OwnCloudClient): RemoteOperationResult<Boolean> { override fun run(client: OwnCloudClient): RemoteOperationResult<Boolean> {
val baseStringUrl = spaceWebDavUrl ?: if (isUserLoggedIn) client.userFilesWebDavUri.toString() else client.baseFilesWebDavUri.toString() val baseStringUrl = spaceWebDavUrl ?: if (isUserLoggedIn) client.baseFilesWebDavUri.toString()
val stringUrl = if (isUserLoggedIn) baseStringUrl + WebdavUtils.encodePath(remotePath) else baseStringUrl else client.userFilesWebDavUri.toString()
val stringUrl = baseStringUrl + WebdavUtils.encodePath(remotePath)
return try { return try {
val propFindMethod = PropfindMethod(URL(stringUrl), 0, allPropSet).apply { val propFindMethod = PropfindMethod(URL(stringUrl), 0, allPropSet).apply {
@ -80,7 +81,6 @@ class CheckPathExistenceRemoteOperation(
e, e,
"Existence check for $stringUrl : ${result.logMessage}" "Existence check for $stringUrl : ${result.logMessage}"
) )
result.data = false
result result
} }
} }

View File

@ -45,7 +45,6 @@ import java.util.concurrent.TimeUnit
* @author Christian Schabesberger * @author Christian Schabesberger
* @author David González V. * @author David González V.
* @author Juan Carlos Garrote Gascón * @author Juan Carlos Garrote Gascón
* @author Manuel Plazas Palacio
* *
* @param sourceRemotePath Remote path of the file/folder to copy. * @param sourceRemotePath Remote path of the file/folder to copy.
* @param targetRemotePath Remote path desired for the file/folder to copy it. * @param targetRemotePath Remote path desired for the file/folder to copy it.
@ -55,7 +54,6 @@ class CopyRemoteFileOperation(
private val targetRemotePath: String, private val targetRemotePath: String,
private val sourceSpaceWebDavUrl: String? = null, private val sourceSpaceWebDavUrl: String? = null,
private val targetSpaceWebDavUrl: String? = null, private val targetSpaceWebDavUrl: String? = null,
private val forceOverride: Boolean = false,
) : RemoteOperation<String>() { ) : RemoteOperation<String>() {
/** /**
@ -76,11 +74,9 @@ class CopyRemoteFileOperation(
var result: RemoteOperationResult<String> var result: RemoteOperationResult<String>
try { try {
val copyMethod = CopyMethod( val copyMethod = CopyMethod(
url = URL((sourceSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)), URL((sourceSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)),
destinationUrl = (targetSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath), (targetSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath),
forceOverride = forceOverride,
).apply { ).apply {
addRequestHeaders(this)
setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS) setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS)
setConnectionTimeout(COPY_CONNECTION_TIMEOUT, TimeUnit.SECONDS) setConnectionTimeout(COPY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
} }
@ -91,7 +87,6 @@ class CopyRemoteFileOperation(
result = RemoteOperationResult(ResultCode.OK) result = RemoteOperationResult(ResultCode.OK)
result.setData(fileRemoteId) result.setData(fileRemoteId)
} }
isPreconditionFailed(status) -> { isPreconditionFailed(status) -> {
result = RemoteOperationResult(ResultCode.INVALID_OVERWRITE) result = RemoteOperationResult(ResultCode.INVALID_OVERWRITE)
client.exhaustResponse(copyMethod.getResponseBodyAsStream()) client.exhaustResponse(copyMethod.getResponseBodyAsStream())
@ -99,7 +94,6 @@ class CopyRemoteFileOperation(
/// for other errors that could be explicitly handled, check first: /// for other errors that could be explicitly handled, check first:
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
} }
else -> { else -> {
result = RemoteOperationResult(copyMethod) result = RemoteOperationResult(copyMethod)
client.exhaustResponse(copyMethod.getResponseBodyAsStream()) client.exhaustResponse(copyMethod.getResponseBodyAsStream())
@ -113,13 +107,6 @@ class CopyRemoteFileOperation(
return result return result
} }
private fun addRequestHeaders(copyMethod: CopyMethod) {
//Adding this because the library has an error with override
if (copyMethod.forceOverride) {
copyMethod.setRequestHeader(OVERWRITE, TRUE)
}
}
private fun isSuccess(status: Int) = status.isOneOf(HttpConstants.HTTP_CREATED, HttpConstants.HTTP_NO_CONTENT) private fun isSuccess(status: Int) = status.isOneOf(HttpConstants.HTTP_CREATED, HttpConstants.HTTP_NO_CONTENT)
private fun isPreconditionFailed(status: Int) = status == HttpConstants.HTTP_PRECONDITION_FAILED private fun isPreconditionFailed(status: Int) = status == HttpConstants.HTTP_PRECONDITION_FAILED
@ -127,7 +114,5 @@ class CopyRemoteFileOperation(
companion object { companion object {
private const val COPY_READ_TIMEOUT = 10L private const val COPY_READ_TIMEOUT = 10L
private const val COPY_CONNECTION_TIMEOUT = 6L private const val COPY_CONNECTION_TIMEOUT = 6L
private const val OVERWRITE = "overwrite"
private const val TRUE = "T"
} }
} }

View File

@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license /* ownCloud Android Library is available under MIT license
* Copyright (C) 2023 ownCloud GmbH. * Copyright (C) 2022 ownCloud GmbH.
* *
* 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
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -21,8 +21,7 @@
* THE SOFTWARE. * THE SOFTWARE.
* *
*/ */
package com.owncloud.android.lib.resources.files
package com.owncloud.android.lib.resources.appregistry
import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.OwnCloudClient
import com.owncloud.android.lib.common.http.HttpConstants import com.owncloud.android.lib.common.http.HttpConstants
@ -31,6 +30,7 @@ import com.owncloud.android.lib.common.network.WebdavUtils
import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperation
import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
import com.owncloud.android.lib.resources.files.GetUrlToOpenInWebRemoteOperation.OpenInWebParams.Companion.PARAM_FILE_ID
import com.squareup.moshi.JsonAdapter import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass
import com.squareup.moshi.Moshi import com.squareup.moshi.Moshi
@ -41,18 +41,16 @@ import java.net.URL
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
class GetUrlToOpenInWebRemoteOperation( class GetUrlToOpenInWebRemoteOperation(
private val openWithWebEndpoint: String, val openWithWebEndpoint: String,
private val fileId: String, val fileId: String,
private val appName: String,
) : RemoteOperation<String>() { ) : RemoteOperation<String>() {
override fun run(client: OwnCloudClient): RemoteOperationResult<String> { override fun run(client: OwnCloudClient): RemoteOperationResult<String> {
return try { return try {
val openInWebRequestBody = OpenInWebParams(fileId, appName).toRequestBody() val openInWebRequestBody = OpenInWebParams(fileId).toRequestBody()
val stringUrl = val stringUrl = client.baseUri.toString() + WebdavUtils.encodePath(openWithWebEndpoint) + "?$PARAM_FILE_ID=$fileId"
client.baseUri.toString() + WebdavUtils.encodePath(openWithWebEndpoint)
val postMethod = PostMethod(URL(stringUrl), openInWebRequestBody).apply { val postMethod = PostMethod(URL(stringUrl), openInWebRequestBody).apply {
setReadTimeout(TIMEOUT, TimeUnit.MILLISECONDS) setReadTimeout(TIMEOUT, TimeUnit.MILLISECONDS)
@ -77,21 +75,14 @@ class GetUrlToOpenInWebRemoteOperation(
} }
} }
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS
data class OpenInWebParams( data class OpenInWebParams(val fileId: String) {
val fileId: String,
val appName: String,
) {
fun toRequestBody(): RequestBody = fun toRequestBody(): RequestBody =
FormBody.Builder() FormBody.Builder().build()
.add(PARAM_FILE_ID, fileId)
.add(PARAM_APP_NAME, appName)
.build()
companion object { companion object {
const val PARAM_FILE_ID = "file_id" const val PARAM_FILE_ID = "file_id"
const val PARAM_APP_NAME = "app_name"
} }
} }

View File

@ -46,7 +46,6 @@ import java.util.concurrent.TimeUnit
* @author David González Verdugo * @author David González Verdugo
* @author Abel García de Prada * @author Abel García de Prada
* @author Juan Carlos Garrote Gascón * @author Juan Carlos Garrote Gascón
* @author Manuel Plazas Palacio
* *
* @param sourceRemotePath Remote path of the file/folder to copy. * @param sourceRemotePath Remote path of the file/folder to copy.
* @param targetRemotePath Remote path desired for the file/folder to copy it. * @param targetRemotePath Remote path desired for the file/folder to copy it.
@ -55,7 +54,6 @@ open class MoveRemoteFileOperation(
private val sourceRemotePath: String, private val sourceRemotePath: String,
private val targetRemotePath: String, private val targetRemotePath: String,
private val spaceWebDavUrl: String? = null, private val spaceWebDavUrl: String? = null,
private val forceOverride: Boolean = false,
) : RemoteOperation<Unit>() { ) : RemoteOperation<Unit>() {
/** /**
@ -82,7 +80,6 @@ open class MoveRemoteFileOperation(
val moveMethod = MoveMethod( val moveMethod = MoveMethod(
url = URL((spaceWebDavUrl ?: srcWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)), url = URL((spaceWebDavUrl ?: srcWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)),
destinationUrl = (spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath), destinationUrl = (spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath),
forceOverride = forceOverride,
).apply { ).apply {
addRequestHeaders(this) addRequestHeaders(this)
setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS) setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS)
@ -95,7 +92,6 @@ open class MoveRemoteFileOperation(
isSuccess(status) -> { isSuccess(status) -> {
result = RemoteOperationResult<Unit>(ResultCode.OK) result = RemoteOperationResult<Unit>(ResultCode.OK)
} }
isPreconditionFailed(status) -> { isPreconditionFailed(status) -> {
result = RemoteOperationResult<Unit>(ResultCode.INVALID_OVERWRITE) result = RemoteOperationResult<Unit>(ResultCode.INVALID_OVERWRITE)
client.exhaustResponse(moveMethod.getResponseBodyAsStream()) client.exhaustResponse(moveMethod.getResponseBodyAsStream())
@ -103,7 +99,6 @@ open class MoveRemoteFileOperation(
/// for other errors that could be explicitly handled, check first: /// for other errors that could be explicitly handled, check first:
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
} }
else -> { else -> {
result = RemoteOperationResult<Unit>(moveMethod) result = RemoteOperationResult<Unit>(moveMethod)
client.exhaustResponse(moveMethod.getResponseBodyAsStream()) client.exhaustResponse(moveMethod.getResponseBodyAsStream())
@ -130,10 +125,6 @@ open class MoveRemoteFileOperation(
* In case new headers are needed, override this method * In case new headers are needed, override this method
*/ */
open fun addRequestHeaders(moveMethod: MoveMethod) { open fun addRequestHeaders(moveMethod: MoveMethod) {
//Adding this because the library has an error with override
if (moveMethod.forceOverride) {
moveMethod.setRequestHeader(OVERWRITE, TRUE)
}
} }
private fun isSuccess(status: Int) = status.isOneOf(HttpConstants.HTTP_CREATED, HttpConstants.HTTP_NO_CONTENT) private fun isSuccess(status: Int) = status.isOneOf(HttpConstants.HTTP_CREATED, HttpConstants.HTTP_NO_CONTENT)
@ -143,7 +134,5 @@ open class MoveRemoteFileOperation(
companion object { companion object {
private const val MOVE_READ_TIMEOUT = 10L private const val MOVE_READ_TIMEOUT = 10L
private const val MOVE_CONNECTION_TIMEOUT = 6L private const val MOVE_CONNECTION_TIMEOUT = 6L
private const val OVERWRITE = "overwrite"
private const val TRUE = "T"
} }
} }

View File

@ -106,7 +106,7 @@ class RenameRemoteFileOperation(
* @return 'True' if the target path is already used by an existing file. * @return 'True' if the target path is already used by an existing file.
*/ */
private fun targetPathIsUsed(client: OwnCloudClient): Boolean { private fun targetPathIsUsed(client: OwnCloudClient): Boolean {
val checkPathExistenceRemoteOperation = CheckPathExistenceRemoteOperation(newRemotePath, true) val checkPathExistenceRemoteOperation = CheckPathExistenceRemoteOperation(newRemotePath, false)
val exists = checkPathExistenceRemoteOperation.execute(client) val exists = checkPathExistenceRemoteOperation.execute(client)
return exists.isSuccess return exists.isSuccess
} }

View File

@ -28,6 +28,8 @@ import com.owncloud.android.lib.resources.Service
import com.owncloud.android.lib.resources.files.RemoteFile import com.owncloud.android.lib.resources.files.RemoteFile
interface FileService : Service { interface FileService : Service {
fun getUrlToOpenInWeb(openWebEndpoint: String, fileId: String): RemoteOperationResult<String>
fun checkPathExistence( fun checkPathExistence(
path: String, path: String,
isUserLogged: Boolean, isUserLogged: Boolean,
@ -39,8 +41,7 @@ interface FileService : Service {
targetRemotePath: String, targetRemotePath: String,
sourceSpaceWebDavUrl: String?, sourceSpaceWebDavUrl: String?,
targetSpaceWebDavUrl: String?, targetSpaceWebDavUrl: String?,
replace: Boolean, ): RemoteOperationResult<String>
): RemoteOperationResult<String?>
fun createFolder( fun createFolder(
remotePath: String, remotePath: String,
@ -58,7 +59,6 @@ interface FileService : Service {
sourceRemotePath: String, sourceRemotePath: String,
targetRemotePath: String, targetRemotePath: String,
spaceWebDavUrl: String?, spaceWebDavUrl: String?,
replace: Boolean,
): RemoteOperationResult<Unit> ): RemoteOperationResult<Unit>
fun readFile( fun readFile(

View File

@ -29,6 +29,7 @@ import com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperatio
import com.owncloud.android.lib.resources.files.CopyRemoteFileOperation import com.owncloud.android.lib.resources.files.CopyRemoteFileOperation
import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation
import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation
import com.owncloud.android.lib.resources.files.GetUrlToOpenInWebRemoteOperation
import com.owncloud.android.lib.resources.files.MoveRemoteFileOperation import com.owncloud.android.lib.resources.files.MoveRemoteFileOperation
import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation
@ -38,6 +39,7 @@ import com.owncloud.android.lib.resources.files.RenameRemoteFileOperation
import com.owncloud.android.lib.resources.files.services.FileService import com.owncloud.android.lib.resources.files.services.FileService
class OCFileService(override val client: OwnCloudClient) : FileService { class OCFileService(override val client: OwnCloudClient) : FileService {
override fun checkPathExistence( override fun checkPathExistence(
path: String, path: String,
isUserLogged: Boolean, isUserLogged: Boolean,
@ -49,19 +51,20 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
spaceWebDavUrl = spaceWebDavUrl, spaceWebDavUrl = spaceWebDavUrl,
).execute(client) ).execute(client)
override fun getUrlToOpenInWeb(openWebEndpoint: String, fileId: String): RemoteOperationResult<String> =
GetUrlToOpenInWebRemoteOperation(openWithWebEndpoint = openWebEndpoint, fileId = fileId).execute(client)
override fun copyFile( override fun copyFile(
sourceRemotePath: String, sourceRemotePath: String,
targetRemotePath: String, targetRemotePath: String,
sourceSpaceWebDavUrl: String?, sourceSpaceWebDavUrl: String?,
targetSpaceWebDavUrl: String?, targetSpaceWebDavUrl: String?,
replace: Boolean, ): RemoteOperationResult<String> =
): RemoteOperationResult<String?> =
CopyRemoteFileOperation( CopyRemoteFileOperation(
sourceRemotePath = sourceRemotePath, sourceRemotePath = sourceRemotePath,
targetRemotePath = targetRemotePath, targetRemotePath = targetRemotePath,
sourceSpaceWebDavUrl = sourceSpaceWebDavUrl, sourceSpaceWebDavUrl = sourceSpaceWebDavUrl,
targetSpaceWebDavUrl = targetSpaceWebDavUrl, targetSpaceWebDavUrl = targetSpaceWebDavUrl,
forceOverride = replace,
).execute(client) ).execute(client)
override fun createFolder( override fun createFolder(
@ -90,13 +93,11 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
sourceRemotePath: String, sourceRemotePath: String,
targetRemotePath: String, targetRemotePath: String,
spaceWebDavUrl: String?, spaceWebDavUrl: String?,
replace: Boolean,
): RemoteOperationResult<Unit> = ): RemoteOperationResult<Unit> =
MoveRemoteFileOperation( MoveRemoteFileOperation(
sourceRemotePath = sourceRemotePath, sourceRemotePath = sourceRemotePath,
targetRemotePath = targetRemotePath, targetRemotePath = targetRemotePath,
spaceWebDavUrl = spaceWebDavUrl, spaceWebDavUrl = spaceWebDavUrl,
forceOverride = replace,
).execute(client) ).execute(client)
override fun readFile( override fun readFile(

View File

@ -89,6 +89,8 @@ class CreateRemoteShareOperation(
var expirationDateInMillis: Long = INIT_EXPIRATION_DATE_IN_MILLIS // Expiration date to set for the public link var expirationDateInMillis: Long = INIT_EXPIRATION_DATE_IN_MILLIS // Expiration date to set for the public link
var publicUpload: Boolean = false // Upload permissions for the public link (only folders)
var retrieveShareDetails = false // To retrieve more info about the just created share var retrieveShareDetails = false // To retrieve more info about the just created share
private fun buildRequestUri(baseUri: Uri) = private fun buildRequestUri(baseUri: Uri) =
@ -97,7 +99,7 @@ class CreateRemoteShareOperation(
.appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT) .appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT)
.build() .build()
private fun parseResponse(response: String): ShareResponse { private fun parseResponse(response: String): ShareResponse? {
val moshi = Moshi.Builder().build() val moshi = Moshi.Builder().build()
val commonOcsType: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareItem::class.java) val commonOcsType: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareItem::class.java)
val adapter: JsonAdapter<CommonOcsResponse<ShareItem>> = moshi.adapter(commonOcsType) val adapter: JsonAdapter<CommonOcsResponse<ShareItem>> = moshi.adapter(commonOcsType)
@ -153,10 +155,12 @@ class CreateRemoteShareOperation(
formBodyBuilder.add(PARAM_EXPIRATION_DATE, formattedExpirationDate) formBodyBuilder.add(PARAM_EXPIRATION_DATE, formattedExpirationDate)
} }
if (publicUpload) {
formBodyBuilder.add(PARAM_PUBLIC_UPLOAD, publicUpload.toString())
}
if (password.isNotEmpty()) { if (password.isNotEmpty()) {
formBodyBuilder.add(PARAM_PASSWORD, password) formBodyBuilder.add(PARAM_PASSWORD, password)
} }
if (RemoteShare.DEFAULT_PERMISSION != permissions) { if (RemoteShare.DEFAULT_PERMISSION != permissions) {
formBodyBuilder.add(PARAM_PERMISSIONS, permissions.toString()) formBodyBuilder.add(PARAM_PERMISSIONS, permissions.toString())
} }
@ -203,6 +207,7 @@ class CreateRemoteShareOperation(
private const val PARAM_SHARE_TYPE = "shareType" private const val PARAM_SHARE_TYPE = "shareType"
private const val PARAM_SHARE_WITH = "shareWith" private const val PARAM_SHARE_WITH = "shareWith"
private const val PARAM_PASSWORD = "password" private const val PARAM_PASSWORD = "password"
private const val PARAM_PUBLIC_UPLOAD = "publicUpload"
private const val PARAM_PERMISSIONS = "permissions" private const val PARAM_PERMISSIONS = "permissions"
//Arguments - constant values //Arguments - constant values

View File

@ -103,6 +103,13 @@ class UpdateRemoteShareOperation
*/ */
var permissions: Int = DEFAULT_PERMISSION var permissions: Int = DEFAULT_PERMISSION
/**
* Enable upload permissions to update in Share resource.
*
* Null results in no update applied to the upload permission.
*/
var publicUpload: Boolean? = null
var retrieveShareDetails = false // To retrieve more info about the just updated share var retrieveShareDetails = false // To retrieve more info about the just updated share
private fun buildRequestUri(baseUri: Uri) = private fun buildRequestUri(baseUri: Uri) =
@ -112,7 +119,7 @@ class UpdateRemoteShareOperation
.appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT) .appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT)
.build() .build()
private fun parseResponse(response: String): ShareResponse { private fun parseResponse(response: String): ShareResponse? {
val moshi = Moshi.Builder().build() val moshi = Moshi.Builder().build()
val commonOcsType: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareItem::class.java) val commonOcsType: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareItem::class.java)
val adapter: JsonAdapter<CommonOcsResponse<ShareItem>> = moshi.adapter(commonOcsType) val adapter: JsonAdapter<CommonOcsResponse<ShareItem>> = moshi.adapter(commonOcsType)
@ -174,6 +181,10 @@ class UpdateRemoteShareOperation
formBodyBuilder.add(PARAM_EXPIRATION_DATE, formattedExpirationDate) formBodyBuilder.add(PARAM_EXPIRATION_DATE, formattedExpirationDate)
} // else, ignore - no update } // else, ignore - no update
if (publicUpload != null) {
formBodyBuilder.add(PARAM_PUBLIC_UPLOAD, publicUpload.toString())
}
// IMPORTANT: permissions parameter needs to be updated after mPublicUpload parameter, // 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 // otherwise they would be set always as 1 (READ) in the server when mPublicUpload was updated
if (permissions > DEFAULT_PERMISSION) { if (permissions > DEFAULT_PERMISSION) {
@ -222,6 +233,7 @@ class UpdateRemoteShareOperation
private const val PARAM_PASSWORD = "password" private const val PARAM_PASSWORD = "password"
private const val PARAM_EXPIRATION_DATE = "expireDate" private const val PARAM_EXPIRATION_DATE = "expireDate"
private const val PARAM_PERMISSIONS = "permissions" private const val PARAM_PERMISSIONS = "permissions"
private const val PARAM_PUBLIC_UPLOAD = "publicUpload"
//Arguments - constant values //Arguments - constant values
private const val FORMAT_EXPIRATION_DATE = "yyyy-MM-dd" private const val FORMAT_EXPIRATION_DATE = "yyyy-MM-dd"

View File

@ -46,6 +46,7 @@ interface ShareService : Service {
name: String, name: String,
password: String, password: String,
expirationDate: Long, expirationDate: Long,
publicUpload: Boolean
): RemoteOperationResult<ShareResponse> ): RemoteOperationResult<ShareResponse>
fun updateShare( fun updateShare(
@ -54,6 +55,7 @@ interface ShareService : Service {
password: String?, password: String?,
expirationDate: Long, expirationDate: Long,
permissions: Int, permissions: Int,
publicUpload: Boolean
): RemoteOperationResult<ShareResponse> ): RemoteOperationResult<ShareResponse>
fun deleteShare(remoteId: String): RemoteOperationResult<Unit> fun deleteShare(remoteId: String): RemoteOperationResult<Unit>

View File

@ -55,6 +55,7 @@ class OCShareService(override val client: OwnCloudClient) : ShareService {
name: String, name: String,
password: String, password: String,
expirationDate: Long, expirationDate: Long,
publicUpload: Boolean
): RemoteOperationResult<ShareResponse> = ): RemoteOperationResult<ShareResponse> =
CreateRemoteShareOperation( CreateRemoteShareOperation(
remoteFilePath, remoteFilePath,
@ -65,6 +66,7 @@ class OCShareService(override val client: OwnCloudClient) : ShareService {
this.name = name this.name = name
this.password = password this.password = password
this.expirationDateInMillis = expirationDate this.expirationDateInMillis = expirationDate
this.publicUpload = publicUpload
this.retrieveShareDetails = true this.retrieveShareDetails = true
}.execute(client) }.execute(client)
@ -74,6 +76,7 @@ class OCShareService(override val client: OwnCloudClient) : ShareService {
password: String?, password: String?,
expirationDate: Long, expirationDate: Long,
permissions: Int, permissions: Int,
publicUpload: Boolean
): RemoteOperationResult<ShareResponse> = ): RemoteOperationResult<ShareResponse> =
UpdateRemoteShareOperation( UpdateRemoteShareOperation(
remoteId remoteId
@ -82,6 +85,7 @@ class OCShareService(override val client: OwnCloudClient) : ShareService {
this.password = password this.password = password
this.expirationDateInMillis = expirationDate this.expirationDateInMillis = expirationDate
this.permissions = permissions this.permissions = permissions
this.publicUpload = publicUpload
this.retrieveShareDetails = true this.retrieveShareDetails = true
}.execute(client) }.execute(client)

View File

@ -61,6 +61,7 @@ data class QuotaResponse(
data class RootResponse( data class RootResponse(
val eTag: String?, val eTag: String?,
val id: String, val id: String,
val permissions: List<PermissionResponse>?,
val webDavUrl: String, val webDavUrl: String,
val deleted: DeleteResponse?, val deleted: DeleteResponse?,
) )
@ -87,11 +88,38 @@ data class FileResponse(
val mimeType: String val mimeType: String
) )
@JsonClass(generateAdapter = true)
data class IdentityPermissionResponse(
val id: String,
val displayName: String?,
)
@JsonClass(generateAdapter = true)
data class GrantedToIdentitiesResponse(
val user: IdentityPermissionResponse?,
val group: IdentityPermissionResponse?,
)
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class DeleteResponse( data class DeleteResponse(
val state: String, val state: String,
) )
@JsonClass(generateAdapter = true)
data class PermissionResponse(
val grantedTo: List<GrantedToIdentitiesResponse>?,
val grantedToIdentities: List<GrantedToIdentitiesResponse>?,
val roles: List<String>,
) {
/**
* Supports api renaming from grantedTo to grantedToIdentities on v1.0.1
* https://github.com/owncloud/libre-graph-api/releases/tag/v1.0.1
*/
fun getGrantedToIdentitiesResponse(): List<GrantedToIdentitiesResponse> {
return grantedToIdentities ?: grantedTo ?: throw IllegalArgumentException("Permissions not granted to anyone")
}
}
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class SpecialFolderResponse( data class SpecialFolderResponse(
val name: String val name: String

View File

@ -40,7 +40,7 @@ class OCServerInfoService : ServerInfoService {
): RemoteOperationResult<Boolean> = ): RemoteOperationResult<Boolean> =
CheckPathExistenceRemoteOperation( CheckPathExistenceRemoteOperation(
remotePath = path, remotePath = path,
isUserLoggedIn = isUserLoggedIn, isUserLoggedIn = true,
).execute(client) ).execute(client)
override fun getRemoteStatus( override fun getRemoteStatus(

View File

@ -75,17 +75,13 @@ class GetInstancesViaWebFingerOperation(
val response = parseResponse(rawResponse) val response = parseResponse(rawResponse)
Timber.d("Successful WebFinger request: $response") Timber.d("Successful WebFinger request: $response")
val operationResult = RemoteOperationResult<List<String>>(RemoteOperationResult.ResultCode.OK) val operationResult = RemoteOperationResult<List<String>>(RemoteOperationResult.ResultCode.OK)
operationResult.data = response.links?.map { it.href } ?: listOf() operationResult.data = response.links.map { it.href }
return operationResult return operationResult
} }
override fun run(client: OwnCloudClient): RemoteOperationResult<List<String>> { override fun run(client: OwnCloudClient): RemoteOperationResult<List<String>> {
val requestUri = buildRequestUri() val requestUri = buildRequestUri()
val getMethod = GetMethod(URL(requestUri.toString())) val getMethod = GetMethod(URL(requestUri.toString()))
// First iteration won't follow redirections.
getMethod.followRedirects = false
return try { return try {
val status = client.executeHttpMethod(getMethod) val status = client.executeHttpMethod(getMethod)
val response = getMethod.getResponseBodyAsString()!! val response = getMethod.getResponseBodyAsString()!!

View File

@ -29,7 +29,7 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class WebFingerResponse( data class WebFingerResponse(
val subject: String, val subject: String,
val links: List<LinkItem>? val links: List<LinkItem>
) )
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)

View File

@ -22,20 +22,20 @@ class WebFingerResponseTest {
@Test @Test
fun `check rel in too much information - ok`() { fun `check rel in too much information - ok`() {
val response = loadResponses(TOO_MUCH_INFORMATION_JSON)!! val response = loadResponses(TOO_MUCH_INFORMATION_JSON)!!
Assert.assertEquals("https://gast.somedomain.de", response.links!![0].href) Assert.assertEquals("https://gast.somedomain.de", response.links[0].href)
Assert.assertEquals("http://webfinger.owncloud/rel/server-instance", response.links!![0].rel) Assert.assertEquals("http://webfinger.owncloud/rel/server-instance", response.links[0].rel)
} }
@Test(expected = JsonDataException::class) @Test(expected = JsonDataException::class)
fun `check key value pairs - ko - no href key`() { fun `check key value pairs - ko - no href key`() {
val response = loadResponses(BROKEN_JSON)!! val response = loadResponses(BROKEN_JSON)!!
Assert.assertEquals("https://gast.somedomain.de", response.links!![0].href) Assert.assertEquals("https://gast.somedomain.de", response.links[0].href)
} }
@Test(expected = JsonDataException::class) @Test(expected = JsonDataException::class)
fun `check key value pairs - ko - no rel key`() { fun `check key value pairs - ko - no rel key`() {
val response = loadResponses(BROKEN_JSON)!! val response = loadResponses(BROKEN_JSON)!!
Assert.assertEquals("https://gast.somedomain.de", response.links!![0].href) Assert.assertEquals("https://gast.somedomain.de", response.links[0].href)
} }
companion object { companion object {