From d23993a4fd6a2162b957e46e6e3f814d1389c50f Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 5 Jul 2023 12:13:29 +0600 Subject: [PATCH 1/3] Revert "6839-Downgrade_ocs_api_version" This reverts commit a2a6e0d8d5de7eb30686ccb373f6c281b5dc7f4c. --- .../it/niedermann/owncloud/notes/persistence/ApiProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/ApiProvider.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/ApiProvider.java index 1199e6e1c..0cab114ee 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/ApiProvider.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/ApiProvider.java @@ -38,7 +38,7 @@ public class ApiProvider { private static final ApiProvider INSTANCE = new ApiProvider(); - private static final String API_ENDPOINT_OCS = "/ocs/v1.php/cloud/"; + private static final String API_ENDPOINT_OCS = "/ocs/v2.php/cloud/"; private static final Map API_CACHE = new ConcurrentHashMap<>(); -- GitLab From 1c48201d8e10e247540a1af9ddc3a2870dadb28d Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 5 Jul 2023 13:36:20 +0600 Subject: [PATCH 2/3] 1422-Sanitize_userId_for_ocs_request issue: https://gitlab.e.foundation/e/os/backlog/-/issues/1422 Murena account's userId is set same as it's email address (passed by accountManager app). For old accounts (@e.email) userId = email. For new accounts (@murena.io) userId is first part of email (ex: for email abc@murena.io, userId is abc). For `GET /ocs/v2.php/cloud/users/` request, we need to pass the actual userId. --- .../notes/persistence/AccountUtil.java | 42 +++++++++++++++++++ .../notes/persistence/CapabilitiesClient.java | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/it/niedermann/owncloud/notes/persistence/AccountUtil.java diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/AccountUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/AccountUtil.java new file mode 100644 index 000000000..784c336fe --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/AccountUtil.java @@ -0,0 +1,42 @@ +/* + * Copyright MURENA SAS 2023 + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package it.niedermann.owncloud.notes.persistence; + +import androidx.annotation.NonNull; + +public abstract class AccountUtil { + + private AccountUtil() { + } + + /** + * Murena account's userId is set same as it's email address (passed by accountManager app). + * For old accounts (@e.email) userId = email. + * For new accounts (@murena.io) userId is first part of email (ex: for email abc@murena.io, userId is abc). + * For api requests, we needed to pass the actual userId. This method remove the unwanted part (@murena.io) from the userId + */ + @NonNull + public static String sanitizeUserId(@NonNull String userId) { + final String murenaMailEndPart = "@murena.io"; + + if (!userId.endsWith(murenaMailEndPart)) { + return userId; + } + + return userId.split(murenaMailEndPart)[0]; + } +} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java index 8b8f79c41..ded44d6a4 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java @@ -53,7 +53,7 @@ public class CapabilitiesClient { public static String getDisplayName(@NonNull Context context, @NonNull SingleSignOnAccount ssoAccount, @NonNull ApiProvider apiProvider) { final var ocsAPI = apiProvider.getOcsAPI(context, ssoAccount); try { - final var userResponse = ocsAPI.getUser(ssoAccount.userId).execute(); + final var userResponse = ocsAPI.getUser(AccountUtil.sanitizeUserId(ssoAccount.userId)).execute(); if (userResponse.isSuccessful()) { final var ocsResponse = userResponse.body(); if (ocsResponse != null) { -- GitLab From 3c158b3ccf23308c1e65bbb05c3308a52eb87246 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 5 Jul 2023 16:17:54 +0600 Subject: [PATCH 3/3] Refactor according to review --- .../notes/persistence/AccountUtil.java | 42 ------------------- .../notes/persistence/CapabilitiesClient.java | 28 +++++++++---- 2 files changed, 19 insertions(+), 51 deletions(-) delete mode 100644 app/src/main/java/it/niedermann/owncloud/notes/persistence/AccountUtil.java diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/AccountUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/AccountUtil.java deleted file mode 100644 index 784c336fe..000000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/AccountUtil.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright MURENA SAS 2023 - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package it.niedermann.owncloud.notes.persistence; - -import androidx.annotation.NonNull; - -public abstract class AccountUtil { - - private AccountUtil() { - } - - /** - * Murena account's userId is set same as it's email address (passed by accountManager app). - * For old accounts (@e.email) userId = email. - * For new accounts (@murena.io) userId is first part of email (ex: for email abc@murena.io, userId is abc). - * For api requests, we needed to pass the actual userId. This method remove the unwanted part (@murena.io) from the userId - */ - @NonNull - public static String sanitizeUserId(@NonNull String userId) { - final String murenaMailEndPart = "@murena.io"; - - if (!userId.endsWith(murenaMailEndPart)) { - return userId; - } - - return userId.split(murenaMailEndPart)[0]; - } -} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java index ded44d6a4..d772981f0 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java @@ -1,22 +1,15 @@ package it.niedermann.owncloud.notes.persistence; import android.content.Context; -import trikita.log.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; -import com.nextcloud.android.sso.api.ParsedResponse; import com.nextcloud.android.sso.model.SingleSignOnAccount; -import java.util.Map; - -import it.niedermann.owncloud.notes.persistence.sync.OcsAPI; import it.niedermann.owncloud.notes.shared.model.Capabilities; -import it.niedermann.owncloud.notes.shared.model.OcsResponse; -import it.niedermann.owncloud.notes.shared.model.OcsUser; -import retrofit2.Response; +import trikita.log.Log; @WorkerThread public class CapabilitiesClient { @@ -53,7 +46,7 @@ public class CapabilitiesClient { public static String getDisplayName(@NonNull Context context, @NonNull SingleSignOnAccount ssoAccount, @NonNull ApiProvider apiProvider) { final var ocsAPI = apiProvider.getOcsAPI(context, ssoAccount); try { - final var userResponse = ocsAPI.getUser(AccountUtil.sanitizeUserId(ssoAccount.userId)).execute(); + final var userResponse = ocsAPI.getUser(sanitizeUserId(ssoAccount.userId)).execute(); if (userResponse.isSuccessful()) { final var ocsResponse = userResponse.body(); if (ocsResponse != null) { @@ -69,4 +62,21 @@ public class CapabilitiesClient { } return null; } + + /** + * Murena account's userId is set same as it's email address (passed by accountManager app). + * For old accounts (@e.email) userId = email. + * For new accounts (@murena.io) userId is first part of email (ex: for email abc@murena.io, userId is abc). + * For api requests, we needed to pass the actual userId. This method remove the unwanted part (@murena.io) from the userId + */ + @NonNull + private static String sanitizeUserId(@NonNull String userId) { + final String murenaMailEndPart = "@murena.io"; + + if (!userId.endsWith(murenaMailEndPart)) { + return userId; + } + + return userId.split(murenaMailEndPart)[0]; + } } -- GitLab