From 27ad3c42c76c465af8e5ee341ec53e3f30eb8ddb Mon Sep 17 00:00:00 2001 From: parneet-guraya Date: Wed, 10 Jul 2024 13:27:41 +0530 Subject: [PATCH 1/3] remove unnecessary call for share info Signed-off-by: parneet-guraya --- .../shares/CreateRemoteShareOperation.kt | 11 +- .../shares/GetRemoteShareOperation.kt | 116 ------------------ .../shares/UpdateRemoteShareOperation.kt | 10 +- .../services/implementation/OCShareService.kt | 2 - 4 files changed, 2 insertions(+), 137 deletions(-) delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareOperation.kt diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt index fed12f83bef..9c49c24daf4 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt @@ -89,8 +89,6 @@ class CreateRemoteShareOperation( var expirationDateInMillis: Long = INIT_EXPIRATION_DATE_IN_MILLIS // Expiration date to set for the public link - var retrieveShareDetails = false // To retrieve more info about the just created share - private fun buildRequestUri(baseUri: Uri) = baseUri.buildUpon() .appendEncodedPath(OCS_ROUTE) @@ -125,14 +123,7 @@ class CreateRemoteShareOperation( result.data = parseResponse(response!!) Timber.d("*** Creating new remote share operation completed ") - val emptyShare = result.data.shares.first() - - return if (retrieveShareDetails) { - // retrieve more info - PUT only returns the index of the new share - GetRemoteShareOperation(emptyShare.id).execute(client) - } else { - result - } + return result } private fun createFormBody(): FormBody { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareOperation.kt deleted file mode 100644 index 0f14168e67e..00000000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareOperation.kt +++ /dev/null @@ -1,116 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * @author Fernando Sanz Velasco - * Copyright (C) 2021 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.HttpConstants.PARAM_FORMAT -import com.owncloud.android.lib.common.http.HttpConstants.VALUE_FORMAT -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.resources.CommonOcsResponse -import com.owncloud.android.lib.resources.shares.responses.ShareItem -import com.squareup.moshi.JsonAdapter -import com.squareup.moshi.Moshi -import com.squareup.moshi.Types -import timber.log.Timber -import java.lang.reflect.Type -import java.net.URL - -class GetRemoteShareOperation(private val remoteId: String) : RemoteOperation() { - - private fun buildRequestUri(baseUri: Uri) = - baseUri.buildUpon() - .appendEncodedPath(OCS_ROUTE) - .appendEncodedPath(remoteId) - .appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT) - .build() - - private fun parseResponse(response: String): ShareResponse? { - val moshi = Moshi.Builder().build() - val listOfShareItemType: Type = Types.newParameterizedType(List::class.java, ShareItem::class.java) - val commonOcsType: Type = Types.newParameterizedType(CommonOcsResponse::class.java, listOfShareItemType) - val adapter: JsonAdapter>> = moshi.adapter(commonOcsType) - return adapter.fromJson(response)?.ocs?.data?.let { listOfShareItems -> - ShareResponse(listOfShareItems.map { shareItem -> - shareItem.toRemoteShare() - }) - } - } - - private fun onResultUnsuccessful( - method: GetMethod, - response: String?, - status: Int - ): RemoteOperationResult { - Timber.e("Failed response while while getting remote shares ") - if (response != null) { - Timber.e("*** status code: $status; response message: $response") - } else { - Timber.e("*** status code: $status") - } - return RemoteOperationResult(method) - } - - private fun onRequestSuccessful(response: String?): RemoteOperationResult { - val result = RemoteOperationResult(RemoteOperationResult.ResultCode.OK) - Timber.d("Successful response: $response") - result.data = parseResponse(response!!) - Timber.d("*** Get Users or groups completed ") - return result - } - - override fun run(client: OwnCloudClient): RemoteOperationResult { - val requestUri = buildRequestUri(client.baseUri) - - val getMethod = GetMethod(URL(requestUri.toString())).apply { - addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE) - } - - return try { - val status = client.executeHttpMethod(getMethod) - val response = getMethod.getResponseBodyAsString() - - if (!isSuccess(status)) { - onResultUnsuccessful(getMethod, response, status) - } else { - onRequestSuccessful(response) - } - } catch (e: Exception) { - Timber.e(e, "Exception while getting remote shares") - RemoteOperationResult(e) - } - } - - private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK - - companion object { - //OCS Route - private const val OCS_ROUTE = "ocs/v2.php/apps/files_sharing/api/v1/shares" - } -} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt index b9f814a2a23..8bfb082e8b2 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt @@ -103,8 +103,6 @@ class UpdateRemoteShareOperation */ var permissions: Int = DEFAULT_PERMISSION - var retrieveShareDetails = false // To retrieve more info about the just updated share - private fun buildRequestUri(baseUri: Uri) = baseUri.buildUpon() .appendEncodedPath(OCS_ROUTE) @@ -139,14 +137,8 @@ class UpdateRemoteShareOperation Timber.d("Successful response: $response") result.data = parseResponse(response!!) Timber.d("*** Retrieve the index of the new share completed ") - val emptyShare = result.data.shares.first() - return if (retrieveShareDetails) { - // retrieve more info - PUT only returns the index of the new share - GetRemoteShareOperation(emptyShare.id).execute(client) - } else { - result - } + return result } private fun createFormBodyBuilder(): FormBody.Builder { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareService.kt index 96381b6a8e3..af2845293b4 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareService.kt @@ -65,7 +65,6 @@ class OCShareService(override val client: OwnCloudClient) : ShareService { this.name = name this.password = password this.expirationDateInMillis = expirationDate - this.retrieveShareDetails = true }.execute(client) override fun updateShare( @@ -82,7 +81,6 @@ class OCShareService(override val client: OwnCloudClient) : ShareService { this.password = password this.expirationDateInMillis = expirationDate this.permissions = permissions - this.retrieveShareDetails = true }.execute(client) override fun deleteShare(remoteId: String): RemoteOperationResult = From b643243a79e9bc3296deb3190f956b34e75ce974 Mon Sep 17 00:00:00 2001 From: parneet-guraya Date: Thu, 18 Jul 2024 13:27:09 +0530 Subject: [PATCH 2/3] add changelog Signed-off-by: parneet-guraya --- changelog/unreleased/4435 | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/unreleased/4435 diff --git a/changelog/unreleased/4435 b/changelog/unreleased/4435 new file mode 100644 index 00000000000..ae238bdf783 --- /dev/null +++ b/changelog/unreleased/4435 @@ -0,0 +1,6 @@ +Bugfix: Shares in non-root are updated correctly + +The items of the "Share" view are updated instantly when create/edit a link or share with users or groups in a non-root file. + +https://github.com/owncloud/android/issues/4432 +https://github.com/owncloud/android/pull/4435 \ No newline at end of file From c0f49a75133ade69f8a77deaaec3c9c8da0bb164 Mon Sep 17 00:00:00 2001 From: parneet-guraya Date: Mon, 12 Aug 2024 05:51:01 +0530 Subject: [PATCH 3/3] trigger refresh after private share Signed-off-by: parneet-guraya --- .../owncloud/android/presentation/sharing/ShareActivity.kt | 5 ++++- .../owncloud/android/presentation/sharing/ShareViewModel.kt | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/sharing/ShareActivity.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/sharing/ShareActivity.kt index 14ae905174b..6595a9d2795 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/sharing/ShareActivity.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/sharing/ShareActivity.kt @@ -154,7 +154,10 @@ class ShareActivity : FileActivity(), ShareFragmentListener { is UIResult.Loading -> { showLoadingDialog(R.string.common_loading) } - is UIResult.Success -> {} + is UIResult.Success -> { + // Needs to trigger refresh after creation because creation request returns wrong path resulting list not getting updated. + shareViewModel.refreshSharesFromNetwork() + } } } ) diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/sharing/ShareViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/sharing/ShareViewModel.kt index 362cc937615..892bd99ccb2 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/sharing/ShareViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/sharing/ShareViewModel.kt @@ -70,7 +70,7 @@ class ShareViewModel( refreshSharesFromNetwork() } - private fun refreshSharesFromNetwork() = runUseCaseWithResultAndUseCachedData( + fun refreshSharesFromNetwork() = runUseCaseWithResultAndUseCachedData( coroutineDispatcher = coroutineDispatcherProvider.io, cachedData = sharesLiveData.value, liveData = _shares,