Skip to content

Commit c0c86b1

Browse files
committed
feat: add support to fetch platform roles from server
1 parent 7ccd678 commit c0c86b1

File tree

17 files changed

+400
-19
lines changed

17 files changed

+400
-19
lines changed

owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/RemoteDataSourceModule.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
* ownCloud Android client application
33
*
44
* @author David González Verdugo
5-
* Copyright (C) 2020 ownCloud GmbH.
5+
* @author Jorge Aguado Recio
6+
*
7+
* Copyright (C) 2025 ownCloud GmbH.
68
*
79
* This program is free software: you can redistribute it and/or modify
810
* it under the terms of the GNU General Public License version 2,
@@ -33,6 +35,8 @@ import com.owncloud.android.data.files.datasources.RemoteFileDataSource
3335
import com.owncloud.android.data.files.datasources.implementation.OCRemoteFileDataSource
3436
import com.owncloud.android.data.oauth.datasources.RemoteOAuthDataSource
3537
import com.owncloud.android.data.oauth.datasources.implementation.OCRemoteOAuthDataSource
38+
import com.owncloud.android.data.roles.datasources.RemoteRolesDataSource
39+
import com.owncloud.android.data.roles.datasources.implementation.OCRemoteRolesDataSource
3640
import com.owncloud.android.data.server.datasources.RemoteServerInfoDataSource
3741
import com.owncloud.android.data.server.datasources.implementation.OCRemoteServerInfoDataSource
3842
import com.owncloud.android.data.sharing.sharees.datasources.RemoteShareeDataSource
@@ -73,6 +77,7 @@ val remoteDataSourceModule = module {
7377
singleOf(::OCRemoteCapabilitiesDataSource) bind RemoteCapabilitiesDataSource::class
7478
singleOf(::OCRemoteFileDataSource) bind RemoteFileDataSource::class
7579
singleOf(::OCRemoteOAuthDataSource) bind RemoteOAuthDataSource::class
80+
singleOf(::OCRemoteRolesDataSource) bind RemoteRolesDataSource::class
7681
singleOf(::OCRemoteServerInfoDataSource) bind RemoteServerInfoDataSource::class
7782
singleOf(::OCRemoteShareDataSource) bind RemoteShareDataSource::class
7883
singleOf(::OCRemoteShareeDataSource) bind RemoteShareeDataSource::class

owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/RepositoryModule.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
* @author David González Verdugo
55
* @author Abel García de Prada
66
* @author Juan Carlos Garrote Gascón
7+
* @author Jorge Aguado Recio
78
*
8-
* Copyright (C) 2022 ownCloud GmbH.
9+
* Copyright (C) 2025 ownCloud GmbH.
910
*
1011
* This program is free software: you can redistribute it and/or modify
1112
* it under the terms of the GNU General Public License version 2,
@@ -28,6 +29,7 @@ import com.owncloud.android.data.capabilities.repository.OCCapabilityRepository
2829
import com.owncloud.android.data.files.repository.OCFileRepository
2930
import com.owncloud.android.data.folderbackup.repository.OCFolderBackupRepository
3031
import com.owncloud.android.data.oauth.repository.OCOAuthRepository
32+
import com.owncloud.android.data.roles.repository.OCRolesRepository
3133
import com.owncloud.android.data.server.repository.OCServerInfoRepository
3234
import com.owncloud.android.data.sharing.sharees.repository.OCShareeRepository
3335
import com.owncloud.android.data.sharing.shares.repository.OCShareRepository
@@ -41,6 +43,7 @@ import com.owncloud.android.domain.authentication.oauth.OAuthRepository
4143
import com.owncloud.android.domain.automaticuploads.FolderBackupRepository
4244
import com.owncloud.android.domain.capabilities.CapabilityRepository
4345
import com.owncloud.android.domain.files.FileRepository
46+
import com.owncloud.android.domain.roles.RolesRepository
4447
import com.owncloud.android.domain.server.ServerInfoRepository
4548
import com.owncloud.android.domain.sharing.sharees.ShareeRepository
4649
import com.owncloud.android.domain.sharing.shares.ShareRepository
@@ -59,6 +62,7 @@ val repositoryModule = module {
5962
factoryOf(::OCFileRepository) bind FileRepository::class
6063
factoryOf(::OCFolderBackupRepository) bind FolderBackupRepository::class
6164
factoryOf(::OCOAuthRepository) bind OAuthRepository::class
65+
factoryOf(::OCRolesRepository) bind RolesRepository::class
6266
factoryOf(::OCServerInfoRepository) bind ServerInfoRepository::class
6367
factoryOf(::OCShareRepository) bind ShareRepository::class
6468
factoryOf(::OCShareeRepository) bind ShareeRepository::class

owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/UseCaseModule.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import com.owncloud.android.domain.files.usecases.SetLastUsageFileUseCase
7979
import com.owncloud.android.domain.files.usecases.SortFilesUseCase
8080
import com.owncloud.android.domain.files.usecases.SortFilesWithSyncInfoUseCase
8181
import com.owncloud.android.domain.files.usecases.UpdateAlreadyDownloadedFilesPathUseCase
82+
import com.owncloud.android.domain.roles.usecases.GetRolesAsyncUseCase
8283
import com.owncloud.android.domain.server.usecases.GetServerInfoAsyncUseCase
8384
import com.owncloud.android.domain.sharing.sharees.GetShareesAsyncUseCase
8485
import com.owncloud.android.domain.sharing.shares.usecases.CreatePrivateShareAsyncUseCase
@@ -302,4 +303,7 @@ val useCaseModule = module {
302303

303304
// Accounts
304305
factoryOf(::RemoveAccountUseCase)
306+
307+
// Roles
308+
factoryOf(::GetRolesAsyncUseCase)
305309
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* ownCloud Android client application
3+
*
4+
* @author Jorge Aguado Recio
5+
*
6+
* Copyright (C) 2025 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.lib.resources.roles
22+
23+
import com.owncloud.android.lib.common.OwnCloudClient
24+
import com.owncloud.android.lib.common.http.HttpConstants
25+
import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
26+
import com.owncloud.android.lib.common.operations.RemoteOperation
27+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
28+
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
29+
import com.owncloud.android.lib.resources.roles.responses.RoleResponse
30+
import com.squareup.moshi.JsonAdapter
31+
import com.squareup.moshi.Moshi
32+
import com.squareup.moshi.Types
33+
import timber.log.Timber
34+
import java.net.URL
35+
36+
class GetRemoteRolesOperation: RemoteOperation<List<RoleResponse>>() {
37+
override fun run(client: OwnCloudClient): RemoteOperationResult<List<RoleResponse>> {
38+
var result: RemoteOperationResult<List<RoleResponse>>
39+
try {
40+
val requestUri = client.baseUri.buildUpon().apply {
41+
appendEncodedPath(GRAPH_API_ROLE_DEFINITIONS_PATH)
42+
build()
43+
}
44+
45+
val getMethod = GetMethod(URL(requestUri.toString()))
46+
47+
val status = client.executeHttpMethod(getMethod)
48+
49+
val response = getMethod.getResponseBodyAsString()
50+
51+
if (status == HttpConstants.HTTP_OK) {
52+
Timber.d("Successful response: $response")
53+
54+
val moshi: Moshi = Moshi.Builder().build()
55+
val type = Types.newParameterizedType(List::class.java, RoleResponse::class.java)
56+
val adapter: JsonAdapter<List<RoleResponse>> = moshi.adapter(type)
57+
58+
val roles = adapter.fromJson(response)
59+
60+
result = RemoteOperationResult(ResultCode.OK)
61+
result.data = roles ?: emptyList()
62+
63+
result = RemoteOperationResult(ResultCode.OK)
64+
result.data = getMethod.getResponseBodyAsString().let { adapter.fromJson(it) }
65+
66+
Timber.d("Get roles completed and parsed to ${result.data}")
67+
} else {
68+
result = RemoteOperationResult(getMethod)
69+
Timber.e("Failed response while getting roles; status code: $status, response: $response")
70+
}
71+
} catch (e: Exception) {
72+
result = RemoteOperationResult(e)
73+
Timber.e(e, "Exception while getting roles")
74+
}
75+
return result
76+
}
77+
78+
companion object {
79+
private const val GRAPH_API_ROLE_DEFINITIONS_PATH = "graph/v1beta1/roleManagement/permissions/roleDefinitions"
80+
}
81+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* ownCloud Android client application
3+
*
4+
* @author Jorge Aguado Recio
5+
*
6+
* Copyright (C) 2025 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.lib.resources.roles.responses
22+
23+
import com.squareup.moshi.JsonClass
24+
25+
@JsonClass(generateAdapter = true)
26+
data class RoleResponse(
27+
val id: String,
28+
val displayName: String
29+
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* ownCloud Android client application
3+
*
4+
* @author Jorge Aguado Recio
5+
*
6+
* Copyright (C) 2025 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.lib.resources.roles.services
22+
23+
import com.owncloud.android.lib.common.OwnCloudClient
24+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
25+
import com.owncloud.android.lib.resources.roles.GetRemoteRolesOperation
26+
import com.owncloud.android.lib.resources.roles.responses.RoleResponse
27+
28+
class OCRolesService(override val client: OwnCloudClient) : RolesService {
29+
30+
override fun getRoles(): RemoteOperationResult<List<RoleResponse>> =
31+
GetRemoteRolesOperation().execute(client)
32+
33+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* ownCloud Android client application
3+
*
4+
* @author Jorge Aguado Recio
5+
*
6+
* Copyright (C) 2025 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.lib.resources.roles.services
22+
23+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
24+
import com.owncloud.android.lib.resources.Service
25+
import com.owncloud.android.lib.resources.roles.responses.RoleResponse
26+
27+
interface RolesService: Service {
28+
fun getRoles(): RemoteOperationResult<List<RoleResponse>>
29+
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/spaces/responses/SpacesResponse.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
package com.owncloud.android.lib.resources.spaces.responses
2525

26+
import com.owncloud.android.lib.resources.roles.responses.RoleResponse
2627
import com.squareup.moshi.Json
2728
import com.squareup.moshi.JsonClass
2829

@@ -126,13 +127,8 @@ data class SpacePermissionsResponse(
126127
@Json(name = "@libre.graph.permissions.actions.allowedValues")
127128
val actions: List<String>,
128129
@Json(name = "@libre.graph.permissions.roles.allowedValues")
129-
val roles: List<SpaceRoleResponse>,
130+
val roles: List<RoleResponse>,
130131
@Json(name = "value")
131132
val members: List<PermissionsResponse>
132133
)
133134

134-
@JsonClass(generateAdapter = true)
135-
data class SpaceRoleResponse(
136-
val displayName: String,
137-
val id: String
138-
)

owncloudData/src/main/java/com/owncloud/android/data/ClientManager.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
* ownCloud Android client application
33
*
44
* @author Abel García de Prada
5-
* Copyright (C) 2023 ownCloud GmbH.
5+
* @author Jorge Aguado Recio
6+
*
7+
* Copyright (C) 2025 ownCloud GmbH.
68
*
79
* This program is free software: you can redistribute it and/or modify
810
* it under the terms of the GNU General Public License version 2,
@@ -34,6 +36,8 @@ import com.owncloud.android.lib.resources.appregistry.services.AppRegistryServic
3436
import com.owncloud.android.lib.resources.appregistry.services.OCAppRegistryService
3537
import com.owncloud.android.lib.resources.files.services.FileService
3638
import com.owncloud.android.lib.resources.files.services.implementation.OCFileService
39+
import com.owncloud.android.lib.resources.roles.services.OCRolesService
40+
import com.owncloud.android.lib.resources.roles.services.RolesService
3741
import com.owncloud.android.lib.resources.shares.services.ShareService
3842
import com.owncloud.android.lib.resources.shares.services.ShareeService
3943
import com.owncloud.android.lib.resources.shares.services.implementation.OCShareService
@@ -160,4 +164,9 @@ class ClientManager(
160164
val ownCloudClient = getClientForAccount(accountName)
161165
return OCAppRegistryService(client = ownCloudClient)
162166
}
167+
168+
fun getRolesService(accountName: String): RolesService {
169+
val ownCloudClient = getClientForAccount(accountName)
170+
return OCRolesService(client = ownCloudClient)
171+
}
163172
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* ownCloud Android client application
3+
*
4+
* @author Jorge Aguado Recio
5+
*
6+
* Copyright (C) 2025 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.data.roles.datasources
22+
23+
import com.owncloud.android.domain.roles.model.OCRole
24+
25+
interface RemoteRolesDataSource {
26+
fun getRoles(accountName: String): List<OCRole>
27+
}

0 commit comments

Comments
 (0)