From 79db463934584c308a6934a07d28633929e7a08d Mon Sep 17 00:00:00 2001 From: MiniDigger | Martin Date: Sun, 7 Jul 2024 10:00:15 +0200 Subject: [PATCH] fix: inconsistencies with website social link (closes #1370) --- .../hangar/controller/internal/HangarUserController.java | 9 ++++----- frontend/src/components/UserHeader.vue | 2 +- frontend/src/i18n/locales/en.json | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/io/papermc/hangar/controller/internal/HangarUserController.java b/backend/src/main/java/io/papermc/hangar/controller/internal/HangarUserController.java index 7089104a2..d87579178 100644 --- a/backend/src/main/java/io/papermc/hangar/controller/internal/HangarUserController.java +++ b/backend/src/main/java/io/papermc/hangar/controller/internal/HangarUserController.java @@ -1,7 +1,5 @@ package io.papermc.hangar.controller.internal; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; import io.papermc.hangar.HangarComponent; import io.papermc.hangar.components.auth.service.CredentialsService; import io.papermc.hangar.components.auth.service.TokenService; @@ -78,7 +76,6 @@ public class HangarUserController extends HangarComponent { private static final Set ACCEPTED_SOCIAL_TYPES = Set.of("discord", "github", "twitter", "youtube", "website"); - private final ObjectMapper mapper; private final UsersApiService usersApiService; private final UserService userService; private final NotificationService notificationService; @@ -93,8 +90,7 @@ public class HangarUserController extends HangarComponent { private final ProjectViewsDAO projectViewsDAO; @Autowired - public HangarUserController(final ObjectMapper mapper, final UsersApiService usersApiService, final UserService userService, final NotificationService notificationService, final ProjectRoleService projectRoleService, final OrganizationService organizationService, final OrganizationRoleService organizationRoleService, final ProjectInviteService projectInviteService, final OrganizationInviteService organizationInviteService, final TokenService tokenService, final AvatarService avatarService, final CredentialsService credentialsService, final ProjectViewsDAO projectViewsDAO) { - this.mapper = mapper; + public HangarUserController(final UsersApiService usersApiService, final UserService userService, final NotificationService notificationService, final ProjectRoleService projectRoleService, final OrganizationService organizationService, final OrganizationRoleService organizationRoleService, final ProjectInviteService projectInviteService, final OrganizationInviteService organizationInviteService, final TokenService tokenService, final AvatarService avatarService, final CredentialsService credentialsService, final ProjectViewsDAO projectViewsDAO) { this.usersApiService = usersApiService; this.userService = userService; this.notificationService = notificationService; @@ -257,6 +253,9 @@ public void saveProfileSettings(@PathVariable final String userName, @RequestBod if (!ACCEPTED_SOCIAL_TYPES.contains(social[0])) { throw new HangarApiException("Badly formatted request, social type " + social[0] + " is unknown!"); } + if ("website".equals(social[0]) && !social[1].matches(this.config.getUrlRegex())) { + throw new HangarApiException("Badly formatted request, website " + social[1] + " is not a valid url! (Did you add https://?)"); + } map.put(social[0], social[1]); } userTable.setSocials(new JSONB(map)); diff --git a/frontend/src/components/UserHeader.vue b/frontend/src/components/UserHeader.vue index dbf71e634..0ea8fd3d6 100644 --- a/frontend/src/components/UserHeader.vue +++ b/frontend/src/components/UserHeader.vue @@ -65,7 +65,7 @@ const canEditCurrentUser = computed(() => { > - + diff --git a/frontend/src/i18n/locales/en.json b/frontend/src/i18n/locales/en.json index ad59406a6..8f4a344b8 100644 --- a/frontend/src/i18n/locales/en.json +++ b/frontend/src/i18n/locales/en.json @@ -35,7 +35,7 @@ "used": "Used", "reveal": "Reveal", "error": { - "invalidUrl": "Invalid URL format", + "invalidUrl": "Invalid URL format (did you forget the https://?)", "nameEmpty": "Name cannot be empty", "fieldEmpty": "This field is required to be set" } @@ -1193,12 +1193,12 @@ "minLength": "Minimum length is {min}", "pattern": "{property} is invalid, '{model}' doesn't match pattern '{regex}'", "noDuplicated": "Can only select each {property} once!", - "url": "Invalid URL format", + "url": "Invalid URL format (did you forget https://?)", "maxFileSize": "File is too large, max size is 10mb", "validProjectName": "Project name is already taken" }, "fieldError": { - "url": "Invalid url value for {0}, got {1}" + "url": "Invalid url value for {0}, got {1} (did you forget https://?)" }, "prompts": { "confirm": "Got it!",