From defe6e3df6af2a04ab4e1c7079fa05684e8642f7 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Tue, 4 Jul 2023 17:54:33 +0600 Subject: [PATCH] 6839-Sanitize_userId issue: https://gitlab.e.foundation/e/backlog/-/issues/6839 Sanitize userId (remove end part from the email to get userId) for ocs requests. --- .../notes/persistence/CapabilitiesClient.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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..700898b99 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 @@ -7,16 +7,9 @@ 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; @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(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,15 @@ public class CapabilitiesClient { } return null; } + + @NonNull + private static String sanitizeUserId(@NonNull String userId) { + int endIndex = userId.lastIndexOf("@"); + + if (endIndex < 0) { + return userId; + } + + return userId.substring(0, endIndex); + } } -- GitLab