From e4ba991114e9373f2cd1672d5e58d951bbffdc66 Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Kandula Date: Tue, 12 Jan 2021 16:20:48 +0530 Subject: [PATCH] Remove unused API endpoints for invite confirmation (#2532) --- .../server/controllers/UserController.java | 13 ----- .../appsmith/server/services/UserService.java | 4 -- .../server/services/UserServiceImpl.java | 57 ------------------- 3 files changed, 74 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/UserController.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/UserController.java index 2efceb4a74..40a0a7012c 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/UserController.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/UserController.java @@ -111,19 +111,6 @@ public class UserController extends BaseController { .map(user -> new ResponseDTO<>(HttpStatus.OK.value(), user, null)); } - @GetMapping("/invite/verify") - public Mono> verifyInviteToken(@RequestParam String email, @RequestParam String token) { - return service.verifyInviteToken(email, token) - .map(result -> new ResponseDTO<>(HttpStatus.OK.value(), result, null)); - } - - @PutMapping("/invite/confirm") - public Mono> confirmInviteUser(@RequestBody User inviteUser, - @RequestHeader("Origin") String originHeader) { - return service.confirmInviteUser(inviteUser, originHeader) - .map(result -> new ResponseDTO<>(HttpStatus.OK.value(), result, null)); - } - /** * This function creates an invite for new users to join an Appsmith organization. We require the Origin header * in order to construct client facing URLs that will be sent to the users via email. diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/UserService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/UserService.java index a8999fdbdd..24f8d59dc0 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/UserService.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/UserService.java @@ -22,10 +22,6 @@ public interface UserService extends CrudService { Mono inviteUserToApplication(InviteUser inviteUser, String originHeader, String applicationId); - Mono verifyInviteToken(String email, String token); - - Mono confirmInviteUser(User inviteUser, String originHeader); - Mono createUserAndSendEmail(User user, String originHeader); Mono userCreate(User user); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/UserServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/UserServiceImpl.java index 262f557282..ea2881b251 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/UserServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/UserServiceImpl.java @@ -59,7 +59,6 @@ import static com.appsmith.server.acl.AclPermission.USER_MANAGE_ORGANIZATIONS; public class UserServiceImpl extends BaseService implements UserService { private final OrganizationService organizationService; - private final AnalyticsService analyticsService; private final SessionUserService sessionUserService; private final PasswordResetTokenRepository passwordResetTokenRepository; private final PasswordEncoder passwordEncoder; @@ -102,7 +101,6 @@ public class UserServiceImpl extends BaseService i CommonConfig commonConfig) { super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService); this.organizationService = organizationService; - this.analyticsService = analyticsService; this.sessionUserService = sessionUserService; this.passwordResetTokenRepository = passwordResetTokenRepository; this.passwordEncoder = passwordEncoder; @@ -365,61 +363,6 @@ public class UserServiceImpl extends BaseService i return userMono; } - /** - * This function checks if the inviteToken is valid for the user. If the token is incorrect or it as expired, - * the client should show the appropriate message to the user - * - * @param email - * @param token - * @return - */ - @Override - public Mono verifyInviteToken(String email, String token) { - log.debug("Verifying token: {} for email: {}", token, email); - return repository.findByEmail(email) - .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "email", email))) - .flatMap(inviteUser -> passwordEncoder.matches(token, inviteUser.getInviteToken()) ? - Mono.just(true) : Mono.just(false)); - } - - /** - * This function confirms the signup for a new invited user. Primarily it will be used to set the password - * for the user and set the user to enabled. The user should have been created during the invite flow. - * - * @param inviteUser - * @return - */ - @Override - public Mono confirmInviteUser(User inviteUser, String originHeader) { - - if (inviteUser.getEmail() == null || inviteUser.getEmail().isEmpty()) { - return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, "email")); - } - - if (inviteUser.getPassword() == null || inviteUser.getPassword().isEmpty()) { - return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, "password")); - } - - log.debug("Confirming the signup for the user: {} and token: {}", inviteUser.getEmail(), inviteUser.getInviteToken()); - - inviteUser.setPassword(this.passwordEncoder.encode(inviteUser.getPassword())); - - return repository.findByEmail(inviteUser.getEmail()) - .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "email", inviteUser.getEmail()))) - .flatMap(newUser -> { - - // Activate the user now : - newUser.setIsEnabled(true); - newUser.setPassword(inviteUser.getPassword()); - // The user has now been invited and has signed up. Delete the invite token because its no longer required - newUser.setInviteToken(null); - - return repository.save(newUser) - .map(savedUser -> sendWelcomeEmail(savedUser, originHeader)) - .thenReturn(true); - }); - } - @Override public Mono create(User user) { // This is the path that is taken when a new user signs up on its own