chore: invite unique emails to workspace (#28151)
## Description > With the current workflow for inviting users to workspace, we are not filtering out duplicate emails. With this code change, we intend to only invite unique users to workspace. #### PR fixes following issue(s) Fixes https://github.com/appsmithorg/appsmith/issues/28067 #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] JUnit - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --------- Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com> Co-authored-by: Ankita Kinger <ankita@appsmith.com>
This commit is contained in:
parent
f55b2fd281
commit
9e7d1d85f8
|
|
@ -388,7 +388,7 @@ function InviteUsersForm(props: any) {
|
||||||
const validEmails = usersAsStringsArray.filter((user: string) =>
|
const validEmails = usersAsStringsArray.filter((user: string) =>
|
||||||
isEmail(user),
|
isEmail(user),
|
||||||
);
|
);
|
||||||
const validEmailsString = validEmails.join(",");
|
const validEmailsString = [...new Set(validEmails)].join(",");
|
||||||
invitedEmails.current = validEmails;
|
invitedEmails.current = validEmails;
|
||||||
|
|
||||||
AnalyticsUtil.logEvent("INVITE_USER", {
|
AnalyticsUtil.logEvent("INVITE_USER", {
|
||||||
|
|
|
||||||
|
|
@ -351,7 +351,8 @@ export function* inviteUsers(
|
||||||
) {
|
) {
|
||||||
const { data, reject, resolve } = action.payload;
|
const { data, reject, resolve } = action.payload;
|
||||||
try {
|
try {
|
||||||
const response: ApiResponse = yield callAPI(UserApi.inviteUser, {
|
const response: ApiResponse<{ id: string; username: string }[]> =
|
||||||
|
yield callAPI(UserApi.inviteUser, {
|
||||||
usernames: data.usernames,
|
usernames: data.usernames,
|
||||||
permissionGroupId: data.permissionGroupId,
|
permissionGroupId: data.permissionGroupId,
|
||||||
});
|
});
|
||||||
|
|
@ -367,12 +368,14 @@ export function* inviteUsers(
|
||||||
workspaceId: data.workspaceId,
|
workspaceId: data.workspaceId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const { data: responseData } = response;
|
||||||
yield put({
|
yield put({
|
||||||
type: ReduxActionTypes.INVITED_USERS_TO_WORKSPACE,
|
type: ReduxActionTypes.INVITED_USERS_TO_WORKSPACE,
|
||||||
payload: {
|
payload: {
|
||||||
workspaceId: data.workspaceId,
|
workspaceId: data.workspaceId,
|
||||||
users: data.usernames.map((name: string) => ({
|
users: responseData.map((user: { id: string; username: string }) => ({
|
||||||
username: name,
|
userId: user.id,
|
||||||
|
username: user.username,
|
||||||
permissionGroupId: data.permissionGroupId,
|
permissionGroupId: data.permissionGroupId,
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,11 @@ import reactor.core.publisher.Mono;
|
||||||
import reactor.util.function.Tuple2;
|
import reactor.util.function.Tuple2;
|
||||||
import reactor.util.function.Tuples;
|
import reactor.util.function.Tuples;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.lang.Boolean.TRUE;
|
import static java.lang.Boolean.TRUE;
|
||||||
|
|
@ -97,7 +98,7 @@ public class UserAndAccessManagementServiceCEImpl implements UserAndAccessManage
|
||||||
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ROLE));
|
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ROLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> usernames = new ArrayList<>();
|
Set<String> usernames = new HashSet<>();
|
||||||
for (String username : originalUsernames) {
|
for (String username : originalUsernames) {
|
||||||
usernames.add(username.toLowerCase());
|
usernames.add(username.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1840,4 +1840,32 @@ public class WorkspaceServiceTest {
|
||||||
mongoTemplate.count(queryWorkspaceWithAdditionalField, Workspace.class);
|
mongoTemplate.count(queryWorkspaceWithAdditionalField, Workspace.class);
|
||||||
assertThat(countWorkspaceWithAdditionalFieldAfterUpdate).isEqualTo(1);
|
assertThat(countWorkspaceWithAdditionalFieldAfterUpdate).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithUserDetails(value = "api_user")
|
||||||
|
void testInviteDuplicateUsers_shouldReturnUniqueUsers() {
|
||||||
|
String testName = "test";
|
||||||
|
List<String> duplicateUsernames = List.of(testName + "user@test.com", testName + "user@test.com");
|
||||||
|
Workspace createdWorkspace = workspaceService.create(workspace).block();
|
||||||
|
assertThat(createdWorkspace).isNotNull();
|
||||||
|
assertThat(createdWorkspace.getDefaultPermissionGroups()).isNotEmpty();
|
||||||
|
List<PermissionGroup> defaultWorkspaceRoles = permissionGroupRepository
|
||||||
|
.findAllById(createdWorkspace.getDefaultPermissionGroups())
|
||||||
|
.collectList()
|
||||||
|
.block();
|
||||||
|
assertThat(defaultWorkspaceRoles)
|
||||||
|
.hasSize(createdWorkspace.getDefaultPermissionGroups().size());
|
||||||
|
|
||||||
|
InviteUsersDTO inviteUsersDTO = new InviteUsersDTO();
|
||||||
|
inviteUsersDTO.setUsernames(duplicateUsernames);
|
||||||
|
inviteUsersDTO.setPermissionGroupId(defaultWorkspaceRoles.get(0).getId());
|
||||||
|
|
||||||
|
// Invited users list contains duplicate users.
|
||||||
|
List<User> userList = userAndAccessManagementService
|
||||||
|
.inviteUsers(inviteUsersDTO, "test")
|
||||||
|
.block();
|
||||||
|
assertThat(userList).hasSize(1);
|
||||||
|
User invitedUser = userList.get(0);
|
||||||
|
assertThat(invitedUser.getUsername()).isEqualTo(testName + "user@test.com");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user