Skip to content

Commit 6f129f9

Browse files
committed
fix: validate file data before retrieving shares
Signed-off-by: Jorge Aguado Recio <jaguado@izertis.com>
1 parent 97cbde3 commit 6f129f9

4 files changed

Lines changed: 47 additions & 10 deletions

File tree

‎owncloudApp/src/main/java/com/owncloud/android/extensions/ThrowableExt.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import com.owncloud.android.domain.exceptions.CopyIntoSameFolderException
3333
import com.owncloud.android.domain.exceptions.FileAlreadyExistsException
3434
import com.owncloud.android.domain.exceptions.FileNotFoundException
3535
import com.owncloud.android.domain.exceptions.ForbiddenException
36+
import com.owncloud.android.domain.exceptions.IncompleteFileDataException
3637
import com.owncloud.android.domain.exceptions.IncorrectAddressException
3738
import com.owncloud.android.domain.exceptions.InstanceNotConfiguredException
3839
import com.owncloud.android.domain.exceptions.InvalidOverwriteException
@@ -84,6 +85,7 @@ fun Throwable.parseError(
8485
})
8586
is FileNotFoundException -> resources.getString(R.string.common_not_found)
8687
is ForbiddenException -> resources.getString(R.string.uploads_view_upload_status_failed_permission_error)
88+
is IncompleteFileDataException -> resources.getString(R.string.get_graph_shares_incomplete_data_error)
8789
is IncorrectAddressException -> resources.getString(R.string.auth_incorrect_address_title)
8890
is InstanceNotConfiguredException -> resources.getString(R.string.auth_not_configured_title)
8991
is InvalidOverwriteException -> resources.getString(R.string.file_already_exists)

‎owncloudApp/src/main/java/com/owncloud/android/presentation/sharing/GraphShareViewModel.kt‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.owncloud.android.presentation.sharing
2222

2323
import androidx.lifecycle.ViewModel
24+
import com.owncloud.android.domain.exceptions.IncompleteFileDataException
2425
import com.owncloud.android.domain.files.model.OCFile
2526
import com.owncloud.android.domain.roles.model.OCRole
2627
import com.owncloud.android.domain.roles.usecases.GetRolesAsyncUseCase
@@ -32,6 +33,7 @@ import com.owncloud.android.presentation.common.UIResult
3233
import com.owncloud.android.providers.CoroutinesDispatcherProvider
3334
import kotlinx.coroutines.flow.MutableStateFlow
3435
import kotlinx.coroutines.flow.StateFlow
36+
import kotlinx.coroutines.flow.update
3537

3638
class GraphShareViewModel(
3739
private val getRolesAsyncUseCase: GetRolesAsyncUseCase,
@@ -56,15 +58,24 @@ class GraphShareViewModel(
5658
)
5759
}
5860

59-
fun getGraphShares() = runUseCaseWithResult(
60-
coroutineDispatcher = coroutineDispatcherProvider.io,
61-
showLoading = true,
62-
flow = _shares,
63-
useCase = getGraphSharesAsyncUseCase,
64-
useCaseParams = GetGraphSharesAsyncUseCase.Params(
65-
accountName = accountName,
66-
spaceId = file.spaceId.orEmpty(),
67-
itemId = file.remoteId.orEmpty()
61+
fun getGraphShares() {
62+
val spaceId = file.spaceId
63+
val itemId = file.remoteId
64+
if (spaceId == null || itemId == null) {
65+
_shares.update { Event(UIResult.Error(error = IncompleteFileDataException())) }
66+
return
67+
}
68+
69+
runUseCaseWithResult(
70+
coroutineDispatcher = coroutineDispatcherProvider.io,
71+
showLoading = true,
72+
flow = _shares,
73+
useCase = getGraphSharesAsyncUseCase,
74+
useCaseParams = GetGraphSharesAsyncUseCase.Params(
75+
accountName = accountName,
76+
spaceId = spaceId,
77+
itemId = itemId
78+
)
6879
)
69-
)
80+
}
7081
}

‎owncloudApp/src/main/res/values/strings.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@
405405
<string name="error__upload__local_file_not_copied">%1$s could not be copied to %2$s local folder.</string>
406406

407407
<string name="get_shares_error">It was not possible to retrieve the shares from the server</string>
408+
<string name="get_graph_shares_incomplete_data_error">Some data could not be retrieved</string>
408409
<string name="get_sharees_error">It was not possible to retrieve users and groups from the server</string>
409410
<string name="get_capabilities_error">It was not possible to retrieve the capabilities from the server</string>
410411
<string name="share_link_file_error">It was not possible to share this file or folder</string>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* ownCloud Android client application
3+
*
4+
* @author Jorge Aguado Recio
5+
*
6+
* Copyright (C) 2026 ownCloud GmbH.
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2,
10+
* as published by the Free Software Foundation.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
package com.owncloud.android.domain.exceptions
22+
23+
class IncompleteFileDataException : Exception()

0 commit comments

Comments
 (0)