From d6a81b6100c8d59fb6bfb69f635fca66163b81ef Mon Sep 17 00:00:00 2001 From: Brutus5000 Date: Wed, 6 Nov 2024 20:26:51 +0100 Subject: [PATCH] Adjust fetching nodebb user to plugin adjustments for Nodebb v3 api --- .../java/com/faforever/api/forum/NodebbService.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/faforever/api/forum/NodebbService.java b/src/main/java/com/faforever/api/forum/NodebbService.java index 5b6f20d0b..2572b174d 100644 --- a/src/main/java/com/faforever/api/forum/NodebbService.java +++ b/src/main/java/com/faforever/api/forum/NodebbService.java @@ -55,12 +55,13 @@ public void userDataChanged(UserUpdatedEvent event) { private Optional getNodebbUserId(int userId) { URI uri = UriComponentsBuilder.fromHttpUrl(properties.getNodebb().getBaseUrl()) // This is not an official NodeBB api url, it's coming from our own sso plugin - .pathSegment("api", "user", "oauth", String.valueOf(userId)) + .pathSegment("api", "v3", "plugins", "sso", "user", String.valueOf(userId)) + .queryParam("_uid", getAdminUserId()) .build() .toUri(); try { - ResponseEntity result = restTemplate.exchange(uri, HttpMethod.GET, null, UserResponse.class); + ResponseEntity result = restTemplate.exchange(uri, HttpMethod.GET, buildAuthorizedRequest(null), UserResponse.class); return Optional.ofNullable(result.getBody()).map(UserResponse::uid); } catch (HttpClientErrorException e) { if (e.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -78,7 +79,7 @@ private void updateUsernameData(int nodebbUserId, UserUpdatedEvent event) { .build() .toUri(); - var usernameUpdate = new UsernameUpdate(String.valueOf(properties.getNodebb().getAdminUserId()), event.getUsername()); + var usernameUpdate = new UsernameUpdate(getAdminUserId(), event.getUsername()); restTemplate.exchange(uri, HttpMethod.PUT, buildAuthorizedRequest(usernameUpdate), Void.class); log.debug("Username updated in NodeBB: {}", event); } @@ -89,11 +90,15 @@ private void updateEmailData(int nodebbUserId, UserUpdatedEvent event) { .build() .toUri(); - var usernameUpdate = new EmailUpdate(String.valueOf(properties.getNodebb().getAdminUserId()), event.getEmail(), 1); + var usernameUpdate = new EmailUpdate(getAdminUserId(), event.getEmail(), 1); restTemplate.exchange(uri, HttpMethod.PUT, buildAuthorizedRequest(usernameUpdate), Void.class); log.debug("Email updated in NodeBB: {}", event); } + private String getAdminUserId() { + return String.valueOf(properties.getNodebb().getAdminUserId()); + } + private HttpEntity buildAuthorizedRequest(T payload) { LinkedMultiValueMap headers = new LinkedMultiValueMap<>(); headers.add(HttpHeaders.AUTHORIZATION, "Bearer " + properties.getNodebb().getMasterToken());