Autoscroll to invited organisation (#3945)
* Added organization slug to the invite Url, which is finally used by email template(#2359) * Separate method to create email params. Welcome email url variable updated so as to be consistent with other email templates * Unused enum emailType removed, importing of java.util.* removed as per suggestion
This commit is contained in:
parent
9e6e8e5e4b
commit
6ea795e8a1
|
|
@ -1,13 +1,17 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.domains.InviteUser;
|
||||
import com.appsmith.server.domains.Organization;
|
||||
import com.appsmith.server.domains.User;
|
||||
import com.appsmith.server.dtos.InviteUsersDTO;
|
||||
import com.appsmith.server.dtos.ResetUserPasswordDTO;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface UserService extends CrudService<User, String> {
|
||||
|
||||
|
|
@ -31,4 +35,5 @@ public interface UserService extends CrudService<User, String> {
|
|||
|
||||
Mono<User> updateCurrentUser(User updates, ServerWebExchange exchange);
|
||||
|
||||
Map<String, String> getEmailParams(Organization organization, User inviterUser, String inviteUrl, boolean isNewUser);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -494,7 +494,7 @@ public class UserServiceImpl extends BaseService<UserRepository, User, String> i
|
|||
public Mono<User> sendWelcomeEmail(User user, String originHeader) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("firstName", user.getName());
|
||||
params.put("appsmithLink", originHeader);
|
||||
params.put("inviteUrl", originHeader);
|
||||
return emailSender
|
||||
.sendMail(user.getEmail(), "Welcome to Appsmith", WELCOME_USER_EMAIL_TEMPLATE, params)
|
||||
.thenReturn(user)
|
||||
|
|
@ -536,6 +536,7 @@ public class UserServiceImpl extends BaseService<UserRepository, User, String> i
|
|||
* 2. User exists :
|
||||
* a. Add user to the organization
|
||||
* b. Add organization to the user
|
||||
*
|
||||
* @return Publishes the invited users, after being saved with the new organization ID.
|
||||
*/
|
||||
@Override
|
||||
|
|
@ -557,7 +558,7 @@ public class UserServiceImpl extends BaseService<UserRepository, User, String> i
|
|||
|
||||
List<String> usernames = new ArrayList<>();
|
||||
for (String username : originalUsernames) {
|
||||
usernames.add(username.toLowerCase());
|
||||
usernames.add(username.toLowerCase());
|
||||
}
|
||||
|
||||
Mono<User> currentUserMono = sessionUserService.getCurrentUser().cache();
|
||||
|
|
@ -588,22 +589,16 @@ public class UserServiceImpl extends BaseService<UserRepository, User, String> i
|
|||
Organization organization = tuple.getT2();
|
||||
User currentUser = tuple.getT3();
|
||||
|
||||
// Email template parameters initialization below.
|
||||
Map<String, String> params = new HashMap<>();
|
||||
if (!StringUtils.isEmpty(currentUser.getName())) {
|
||||
params.put("Inviter_First_Name", currentUser.getName());
|
||||
} else {
|
||||
params.put("Inviter_First_Name", currentUser.getEmail());
|
||||
}
|
||||
params.put("inviter_org_name", organization.getName());
|
||||
|
||||
return repository.findByEmail(username)
|
||||
.flatMap(existingUser -> {
|
||||
// The user already existed, just send an email informing that the user has been added
|
||||
// to a new organization
|
||||
log.debug("Going to send email to user {} informing that the user has been added to new organization {}",
|
||||
existingUser.getEmail(), organization.getName());
|
||||
params.put("inviteUrl", originHeader);
|
||||
|
||||
// Email template parameters initialization below.
|
||||
Map<String, String> params = getEmailParams(organization, currentUser, originHeader, false);
|
||||
|
||||
Mono<Boolean> emailMono = emailSender.sendMail(existingUser.getEmail(),
|
||||
"Appsmith: You have been added to a new organization",
|
||||
USER_ADDED_TO_ORGANIZATION_EMAIL_TEMPLATE, params);
|
||||
|
|
@ -611,7 +606,7 @@ public class UserServiceImpl extends BaseService<UserRepository, User, String> i
|
|||
return emailMono
|
||||
.thenReturn(existingUser);
|
||||
})
|
||||
.switchIfEmpty(createNewUserAndSendInviteEmail(username, originHeader, params));
|
||||
.switchIfEmpty(createNewUserAndSendInviteEmail(username, originHeader, organization, currentUser));
|
||||
})
|
||||
.cache();
|
||||
|
||||
|
|
@ -657,7 +652,7 @@ public class UserServiceImpl extends BaseService<UserRepository, User, String> i
|
|||
);
|
||||
}
|
||||
|
||||
private Mono<User> createNewUserAndSendInviteEmail(String email, String originHeader, Map<String, String> params) {
|
||||
private Mono<User> createNewUserAndSendInviteEmail(String email, String originHeader, Organization organization, User inviter) {
|
||||
User newUser = new User();
|
||||
newUser.setEmail(email.toLowerCase());
|
||||
|
||||
|
|
@ -678,7 +673,9 @@ public class UserServiceImpl extends BaseService<UserRepository, User, String> i
|
|||
URLEncoder.encode(createdUser.getEmail(), StandardCharsets.UTF_8)
|
||||
);
|
||||
|
||||
params.put("inviteUrl", inviteUrl);
|
||||
// Email template parameters initialization below.
|
||||
Map<String, String> params = getEmailParams(organization, inviter, inviteUrl, true);
|
||||
|
||||
Mono<Boolean> emailMono = emailSender.sendMail(createdUser.getEmail(), "Invite for Appsmith", INVITE_USER_EMAIL_TEMPLATE, params);
|
||||
|
||||
// We have sent out the emails. Just send back the saved user.
|
||||
|
|
@ -742,4 +739,25 @@ public class UserServiceImpl extends BaseService<UserRepository, User, String> i
|
|||
);
|
||||
}
|
||||
|
||||
public Map<String, String> getEmailParams(Organization organization, User inviter, String inviteUrl, boolean isNewUser) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
|
||||
if (inviter != null) {
|
||||
if (!StringUtils.isEmpty(inviter.getName())) {
|
||||
params.put("Inviter_First_Name", inviter.getName());
|
||||
} else {
|
||||
params.put("Inviter_First_Name", inviter.getEmail());
|
||||
}
|
||||
}
|
||||
if (organization != null) {
|
||||
params.put("inviter_org_name", organization.getName());
|
||||
}
|
||||
if (isNewUser) {
|
||||
params.put("inviteUrl", inviteUrl);
|
||||
} else {
|
||||
params.put("inviteUrl", inviteUrl + "/applications#" + organization.getSlug());
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -374,7 +374,7 @@
|
|||
<tbody>
|
||||
<tr>
|
||||
<td class="inner-td" style="border-radius: 6px; font-size: 16px; text-align: center; background-color: inherit;" align="center" bgcolor="#ff6d2d">
|
||||
<a style="background-color: #ff6d2d; border: 1px solid #ff6d2d; border-radius: 6px; color: #ffffff; display: inline-block; font-weight: 400; letter-spacing: 0; line-height: 6px; padding: 12px 18px; text-align: center; text-decoration: none; font-family: tahoma,geneva,sans-serif; font-size: 16px;" href="{{appsmithLink}}" target="_blank" rel="noopener">Go to Appsmith</a>
|
||||
<a style="background-color: #ff6d2d; border: 1px solid #ff6d2d; border-radius: 6px; color: #ffffff; display: inline-block; font-weight: 400; letter-spacing: 0; line-height: 6px; padding: 12px 18px; text-align: center; text-decoration: none; font-family: tahoma,geneva,sans-serif; font-size: 16px;" href="{{inviteUrl}}" target="_blank" rel="noopener">Go to Appsmith</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.appsmith.server.acl.AclPermission.MANAGE_APPLICATIONS;
|
||||
|
|
@ -43,6 +44,7 @@ import static com.appsmith.server.acl.AclPermission.READ_USERS;
|
|||
import static com.appsmith.server.acl.AclPermission.USER_MANAGE_ORGANIZATIONS;
|
||||
import static com.appsmith.server.acl.AclPermission.USER_READ_ORGANIZATIONS;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@Slf4j
|
||||
|
|
@ -79,6 +81,42 @@ public class UserServiceTest {
|
|||
organizationMono = organizationService.getBySlug("spring-test-organization");
|
||||
}
|
||||
|
||||
//Test if email params are updating correctly
|
||||
@Test
|
||||
public void checkEmailParamsForExistingUser() {
|
||||
Organization organization = new Organization();
|
||||
organization.setName("UserServiceTest Update Org");
|
||||
organization.setSlug("userservicetest-update-org");
|
||||
|
||||
User inviter = new User();
|
||||
inviter.setName("inviterUserToApplication");
|
||||
|
||||
String inviteUrl = "http://localhost:8080";
|
||||
String expectedUrl = inviteUrl + "/applications#userservicetest-update-org";
|
||||
|
||||
Map<String, String> params = userService.getEmailParams(organization, inviter, inviteUrl, false);
|
||||
assertEquals(expectedUrl, params.get("inviteUrl"));
|
||||
assertEquals("inviterUserToApplication", params.get("Inviter_First_Name"));
|
||||
assertEquals("UserServiceTest Update Org", params.get("inviter_org_name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkEmailParamsForNewUser() {
|
||||
Organization organization = new Organization();
|
||||
organization.setName("UserServiceTest Update Org");
|
||||
organization.setSlug("userservicetest-update-org");
|
||||
|
||||
User inviter = new User();
|
||||
inviter.setName("inviterUserToApplication");
|
||||
|
||||
String inviteUrl = "http://localhost:8080";
|
||||
|
||||
Map<String, String> params = userService.getEmailParams(organization, inviter, inviteUrl, true);
|
||||
assertEquals(inviteUrl, params.get("inviteUrl"));
|
||||
assertEquals("inviterUserToApplication", params.get("Inviter_First_Name"));
|
||||
assertEquals("UserServiceTest Update Org", params.get("inviter_org_name"));
|
||||
}
|
||||
|
||||
//Test the update organization flow.
|
||||
@Test
|
||||
public void updateInvalidUserWithAnything() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user