Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Address review comments

Add minor improvement

Address review comments

Address minor improvement

Improve the model
  • Loading branch information
Kanapriya committed Dec 5, 2023
1 parent 2d1aa55 commit d70069b
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
package org.wso2.carbon.identity.organization.user.invitation.management;

import org.wso2.carbon.identity.organization.user.invitation.management.exception.UserInvitationMgtException;
import org.wso2.carbon.identity.organization.user.invitation.management.models.CreatedInvitation;
import org.wso2.carbon.identity.organization.user.invitation.management.models.Invitation;
import org.wso2.carbon.identity.organization.user.invitation.management.models.InvitationDO;

import java.util.List;

Expand All @@ -35,7 +37,7 @@ public interface InvitationCoreService {
* @return The created invitation.
* @throws UserInvitationMgtException If an error occurs while creating the invitation.
*/
List<Invitation> createInvitation(Invitation invitation) throws UserInvitationMgtException;
List<CreatedInvitation> createInvitations(InvitationDO invitation) throws UserInvitationMgtException;

/**
* Accepts the invitation with the given confirmation code.
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class UserInvitationMgtConstants {
public static final String DEFAULT_USER_STORE_DOMAIN = "DEFAULT";
public static final String DEFAULT_PROFILE = "default";
public static final String INVITED_USER_GROUP_NAME_PREFIX = "invitedOrgUserGroup-";
public static final String SUCCESS_STATUS = "Success";
public static final String FAIL_STATUS = "Fail";

// Filter Constants
public static final String STATUS_PENDING = "PENDING";
Expand Down Expand Up @@ -68,7 +70,7 @@ public enum ErrorMessage {
// Service layer errors
ERROR_CODE_USER_NOT_FOUND("10011",
"Invalid user identification provided.",
"Could not find an user with given username %s."),
"Could not find an user with given username."),
ERROR_CODE_CREATE_INVITATION("10012",
"Unable to create the invitation.",
"Could not create the invitation to the user %s."),
Expand All @@ -89,7 +91,7 @@ public enum ErrorMessage {
"The filter attribute '%s' is not supported."),
ERROR_CODE_ACTIVE_INVITATION_EXISTS("10018",
"Invitation already exists.",
"An active invitation already exists for the user %s."),
"An active invitation already exists for the user."),
ERROR_CODE_INVITATION_EXPIRED("10019",
"Invitation expired.",
"The invitation for the user %s has expired."),
Expand Down Expand Up @@ -125,10 +127,13 @@ public enum ErrorMessage {
"Could not find a role with given roleId %s."),
ERROR_CODE_INVITED_USER_EMAIL_NOT_FOUND("10030",
"Failed to resolve the email of the invited user.",
"Could not find the email of the invited user %s."),
"Could not find the email of the invited user."),
ERROR_CODE_CONSOLE_ACCESS_RESTRICTED("10031",
"Invited user doesn't have console access.",
"Could not find any role with a console access to create an invitation."),
ERROR_CODE_USER_ALREADY_EXISTS_INVITED_ORGANIZATION("10032",
"Couldn't create the invitation.",
"User is already exists in the invited organization"),
ERROR_CODE_ROLE_EXISTENCE("10032",
"Error while checking the role existence.",
"Could not resolve the role existence from the given list."),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.wso2.carbon.identity.organization.user.invitation.management.models;

/**
* Model that contains the created invitation details.
*/
public class CreatedInvitation {

private String username;
private InvitationResult result;

public InvitationResult getResult() {

return result;
}

public void setResult(InvitationResult result) {

this.result = result;
}

public String getUsername() {

return username;
}

public void setUsername(String username) {

this.username = username;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.wso2.carbon.identity.organization.user.invitation.management.models;

import java.sql.Timestamp;
import java.util.List;

/**
* Model that contains the invitation related details.
Expand All @@ -29,7 +28,6 @@ public class Invitation {
private String invitationId;
private String confirmationCode;
private String username;
private List<String> usernamesList;
private String userDomain;
private String email;
private String userOrganizationId;
Expand All @@ -41,7 +39,6 @@ public class Invitation {
private Timestamp expiredAt;
private String userRedirectUrl;
private RoleAssignments[] roleAssignments;
private List<String> skippedUsersList;

public String getInvitationId() {

Expand Down Expand Up @@ -73,16 +70,6 @@ public void setUsername(String username) {
this.username = username;
}

public List<String> getUsernamesList() {

return usernamesList;
}

public void setUsernamesList(List<String> usernames) {

this.usernamesList = usernames;
}

public String getUserDomain() {

return userDomain;
Expand Down Expand Up @@ -195,14 +182,4 @@ public void setRoleAssignments(RoleAssignments[] roleAssignments) {

this.roleAssignments = roleAssignments != null ? roleAssignments.clone() : null;
}

public List<String> getSkippedUsersList() {

return skippedUsersList;
}

public void setSkippedUsersList(List<String> usernames) {

this.skippedUsersList = usernames;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.wso2.carbon.identity.organization.user.invitation.management.models;

import java.util.List;

/**
* Model that contains the invitation data object.
*/
public class InvitationDO {

private List<String> usernamesList;
private String userDomain;
private RoleAssignments[] roleAssignments;
private String userRedirectUrl;

public String getUserRedirectUrl() {

return userRedirectUrl;
}

public void setUserRedirectUrl(String userRedirectUrl) {

this.userRedirectUrl = userRedirectUrl;
}

public List<String> getUsernamesList() {

return usernamesList;
}

public void setUsernamesList(List<String> usernamesList) {

this.usernamesList = usernamesList;
}

public String getUserDomain() {

return userDomain;
}

public void setUserDomain(String userDomain) {

this.userDomain = userDomain;
}

public RoleAssignments[] getRoleAssignments() {

if (roleAssignments == null) {
return null;
}
return roleAssignments.clone();
}

public void setRoleAssignments(RoleAssignments[] roleAssignments) {

this.roleAssignments = roleAssignments != null ? roleAssignments.clone() : null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.wso2.carbon.identity.organization.user.invitation.management.models;

import org.wso2.carbon.identity.organization.user.invitation.management.constant.UserInvitationMgtConstants;

/**
* Model that contains the created invitation result details.
*/
public class InvitationResult {

private UserInvitationMgtConstants.ErrorMessage errorMsg;
private String status;

public UserInvitationMgtConstants.ErrorMessage getErrorMsg() {

return errorMsg;
}

public void setErrorMsg(UserInvitationMgtConstants.ErrorMessage errorMsg) {

this.errorMsg = errorMsg;
}

public String getStatus() {

return status;
}

public void setStatus(String status) {

this.status = status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import org.wso2.carbon.identity.organization.user.invitation.management.exception.UserInvitationMgtClientException;
import org.wso2.carbon.identity.organization.user.invitation.management.exception.UserInvitationMgtException;
import org.wso2.carbon.identity.organization.user.invitation.management.internal.UserInvitationMgtDataHolder;
import org.wso2.carbon.identity.organization.user.invitation.management.models.CreatedInvitation;
import org.wso2.carbon.identity.organization.user.invitation.management.models.Invitation;
import org.wso2.carbon.identity.organization.user.invitation.management.models.InvitationDO;
import org.wso2.carbon.identity.organization.user.invitation.management.models.RoleAssignments;
import org.wso2.carbon.identity.organization.user.invitation.management.util.TestUtils;
import org.wso2.carbon.identity.role.v2.mgt.core.RoleManagementService;
Expand All @@ -48,7 +50,6 @@
import java.nio.file.Paths;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand All @@ -60,6 +61,7 @@
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import static org.wso2.carbon.identity.organization.user.invitation.management.constants.InvitationTestConstants.INV_01_CONF_CODE;
Expand Down Expand Up @@ -95,9 +97,6 @@ public class InvitationCoreServiceImplTest extends PowerMockTestCase {
private final UserInvitationDAO userInvitationDAO = new UserInvitationDAOImpl();
private InvitationCoreServiceImpl invitationCoreService;
private final String [] roleList = {"1224", "12345"};
String[] username1 = {INV_01_UN};
String[] username2 = {INV_02_UN};
String[] username3 = {INV_03_UN};
@BeforeClass
public void setUp() throws Exception {

Expand All @@ -114,16 +113,16 @@ public void setUp() throws Exception {
Connection connection2 = getConnection();
Connection connection3 = getConnection();

Invitation invitation1 = buildInvitation(INV_01_INVITATION_ID, INV_01_CONF_CODE, Arrays.asList(username1),
Invitation invitation1 = buildInvitation(INV_01_INVITATION_ID, INV_01_CONF_CODE, INV_01_UN,
"DEFAULT", INV_01_EMAIL,
"https://localhost:8080/travel-manager-001/invitations/accept", INV_01_USER_ORG_ID,
INV_01_INV_ORG_ID, null, "PENDING");
Invitation invitation2 = buildInvitation(INV_02_INVITATION_ID, INV_02_CONF_CODE, Arrays.asList(username2),
Invitation invitation2 = buildInvitation(INV_02_INVITATION_ID, INV_02_CONF_CODE, INV_02_UN,
"DEFAULT", INV_02_EMAIL,
"https://localhost:8080/travel-manager-001/invitations/accept",
INV_02_USER_ORG_ID, INV_02_INV_ORG_ID, null, "PENDING");
RoleAssignments roleAssignments2 = buildRoleAssignments(roleList);
Invitation invitation3 = buildInvitation(INV_03_INVITATION_ID, INV_03_CONF_CODE, Arrays.asList(username3),
Invitation invitation3 = buildInvitation(INV_03_INVITATION_ID, INV_03_CONF_CODE, INV_03_UN,
"DEFAULT", INV_03_EMAIL,
"https://localhost:8080/travel-manager-001/invitations/accept", INV_03_USER_ORG_ID,
INV_03_INV_ORG_ID, new RoleAssignments[]{roleAssignments2}, "PENDING");
Expand Down Expand Up @@ -254,11 +253,11 @@ public void testDeleteInvitationWithNotOwnedInvitationId() throws Exception {
@Test(priority = 9)
public void testCreateInvitationWithNonExistingUserInParent() throws Exception {

Invitation invitation1 = buildInvitation(null,
null, Collections.singletonList("samson"), "DEFAULT",
null, "https://localhost:8080/travel-manager-001/invitations/accept",
null, null,
null, null);
InvitationDO invitation1 = new InvitationDO();
invitation1.setUsernamesList(Collections.singletonList("samson"));
invitation1.setUserDomain("DEFAULT");
invitation1.setRoleAssignments(null);
invitation1.setUserRedirectUrl("https://localhost:8080/travel-manager-001/invitations/accept");

OrganizationManager organizationManager = mock(OrganizationManager.class);
RealmService realmService = mock(RealmService.class);
Expand All @@ -280,7 +279,9 @@ public void testCreateInvitationWithNonExistingUserInParent() throws Exception {
when(IdentityDatabaseUtil.getDBConnection(true)).thenReturn(getConnection());
when(IdentityTenantUtil.getTenantId(anyString())).thenReturn(-1234);
mockIdentityTenantUtil();
invitationCoreService.createInvitation(invitation1);
List<CreatedInvitation> createdInvitation = invitationCoreService.createInvitations(invitation1);
assertNotNull(createdInvitation);
assertEquals(createdInvitation.get(0).getResult().getStatus(), "Fail");
}


Expand All @@ -301,19 +302,13 @@ private void populateH2Base(Connection connection, Invitation invitation) throws

when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection);
when(IdentityUtil.getProperty(anyString())).thenReturn("1440");
if (invitation.getUsernamesList() != null) {
for (String username : invitation.getUsernamesList()) {
invitation.setUsername(username);
}
if (invitation.getRoleAssignments() != null) {
for (RoleAssignments roleAssignments : invitation.getRoleAssignments()) {
for (String role : roleList) {
roleAssignments.setRole(role);
}
if (invitation.getRoleAssignments() != null) {
for (RoleAssignments roleAssignments : invitation.getRoleAssignments()) {
for (String role : roleList) {
roleAssignments.setRole(role);
}
}
}

userInvitationDAO.createInvitation(invitation);
}

Expand All @@ -326,14 +321,14 @@ private void mockCarbonContextForTenant() {
thenReturn("dc828181-e1a8-4f5e-8936-f154f4aefa75");
}

private Invitation buildInvitation(String invitationId, String confirmationCode, List<String> username,
private Invitation buildInvitation(String invitationId, String confirmationCode, String username,
String userDomain, String email, String userRedirectUrl, String userOrgId,
String invitedOrgId, RoleAssignments[] roleAssignments, String status) {

Invitation invitation = new Invitation();
invitation.setInvitationId(invitationId);
invitation.setConfirmationCode(confirmationCode);
invitation.setUsernamesList(username);
invitation.setUsername(username);
invitation.setUserDomain(userDomain);
invitation.setEmail(email);
invitation.setUserRedirectUrl(userRedirectUrl);
Expand Down

0 comments on commit d70069b

Please sign in to comment.