From 1ea89d90e19c773dd120d96883d8bd08252e6d86 Mon Sep 17 00:00:00 2001 From: Aditya Agarwal Date: Mon, 4 Nov 2024 17:41:27 +0100 Subject: [PATCH] fix: fix tests, fix token moderation --- .../io/getstream/client/ModerationClient.java | 11 ++++++----- .../java/io/getstream/core/Moderation.java | 18 +++++++++++------- .../java/io/getstream/core/utils/Auth.java | 7 ++++++- .../getstream/client/ModerationClientTest.java | 11 +++++++++-- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/getstream/client/ModerationClient.java b/src/main/java/io/getstream/client/ModerationClient.java index c44aabc2..37e9514a 100644 --- a/src/main/java/io/getstream/client/ModerationClient.java +++ b/src/main/java/io/getstream/client/ModerationClient.java @@ -1,5 +1,6 @@ package io.getstream.client; +import static io.getstream.core.utils.Auth.buildModerationToken; import static io.getstream.core.utils.Auth.buildReactionsToken; import static io.getstream.core.utils.Routes.*; import static io.getstream.core.utils.Serialization.*; @@ -33,19 +34,19 @@ public CompletableFuture flagActivity( } public CompletableFuture flagReaction( - String entityId, String entityCreatorId, String reason, Map options) + String entityId, String reportingUser, String reason, Map options) throws StreamException { - return flag("stream:feeds:v2:reaction", entityId, entityCreatorId, reason, options); + return flag("stream:feeds:v2:reaction", entityId, reportingUser, reason, options); } private CompletableFuture flag( String entityType, String entityId, - String entityCreatorId, + String reportingUser, String reason, Map options) throws StreamException { - final Token token = buildReactionsToken(secret, Auth.TokenAction.WRITE); - return mod.flag(token, entityType, entityId, entityCreatorId, reason, options); + final Token token = buildModerationToken(secret, Auth.TokenAction.WRITE); + return mod.flag(token, entityType, entityId, reportingUser, reason, options); } } diff --git a/src/main/java/io/getstream/core/Moderation.java b/src/main/java/io/getstream/core/Moderation.java index d607774e..d4cb0eed 100644 --- a/src/main/java/io/getstream/core/Moderation.java +++ b/src/main/java/io/getstream/core/Moderation.java @@ -31,24 +31,28 @@ public CompletableFuture flag( Token token, String entityType, String entityId, - String entityCreatorId, - String reason, + String reportingUser, + String Reason, Map options) throws StreamException { try { final byte[] payload = toJSON( new Object() { - public final String UserId = entityCreatorId; - public final String EntityType = entityType; - public final String EntityId = entityId; - public final String Reason = reason; + public final String user_id = reportingUser; + public final String entity_type = entityType; + public final String entity_id = entityId; + public final String reason = Reason; }); - final URL url = buildModerationFlagURL(baseURL); + String strsing = new String(payload); + System.out.println(strsing); + final URL url = buildModerationFlagURL(baseURL); return httpClient.execute(buildPost(url, key, token, payload)); } catch (JsonProcessingException | MalformedURLException | URISyntaxException e) { throw new CompletionException(e); + } catch (Exception e){ + throw e; } } } diff --git a/src/main/java/io/getstream/core/utils/Auth.java b/src/main/java/io/getstream/core/utils/Auth.java index a1527ab2..3fdcada3 100644 --- a/src/main/java/io/getstream/core/utils/Auth.java +++ b/src/main/java/io/getstream/core/utils/Auth.java @@ -41,7 +41,8 @@ public enum TokenResource { OPEN_GRAPH("url"), PERSONALIZATION("personalization"), REACTIONS("reactions"), - USERS("users"); + USERS("users"), + MODERATION("moderation"); private final String resource; @@ -98,6 +99,10 @@ public static Token buildReactionsToken(String secret, TokenAction action) { return buildBackendToken(secret, TokenResource.REACTIONS, action, "*"); } + public static Token buildModerationToken(String secret, TokenAction action) { + return buildBackendToken(secret, TokenResource.MODERATION, action, "*"); + } + public static Token buildAnalyticsToken(String secret, TokenAction action) { return buildBackendToken(secret, TokenResource.ANALYTICS, action, "*"); } diff --git a/src/test/java/io/getstream/client/ModerationClientTest.java b/src/test/java/io/getstream/client/ModerationClientTest.java index e57cbc2e..798b97fa 100644 --- a/src/test/java/io/getstream/client/ModerationClientTest.java +++ b/src/test/java/io/getstream/client/ModerationClientTest.java @@ -5,6 +5,10 @@ import io.getstream.core.http.Response; import io.getstream.core.models.*; import io.getstream.core.models.Activity; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.nio.Buffer; import java.util.Date; import java.util.UUID; import org.junit.*; @@ -65,12 +69,15 @@ public void testFlagReaction() throws Exception { assertNotNull(activityResponse); Reaction reactionResponse = - client.reactions().add("user123", "like", activityResponse.getID()).join(); + client.reactions().add("test", "like", activityResponse.getID()).join(); assertNotNull(reactionResponse); Response flagResponse = - moderationClient.flagReaction(reactionResponse.getId(), "bobby", "blood", null).join(); + moderationClient.flagReaction(reactionResponse.getId(), "vishal", "blood", null).join(); + assertNotNull(flagResponse); + assertEquals(201, flagResponse.getCode()); assertNotNull(flagResponse); + } @Test