-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable Retrieval of Existing Users based on userid #44
Changes from 3 commits
3f146a6
3509d3e
7d70834
e759aae
245ad0e
92eb73d
5be7a92
90445c8
33739e7
321ca28
cc8727d
a3fe66d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package io.mathdojo.useraccountservice.services; | ||
|
||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.logging.Level; | ||
|
@@ -20,6 +21,7 @@ | |
public class IdentityService { | ||
|
||
private static final String PRECONDITIONED_UNKNOWN_USER_ID = "unknownUserId"; | ||
private static final String PRECONDITIONED_KNOWN_USER_ID = "knownUserId"; | ||
private static final String PRECONDITIONED_UNKNOWN_ORGANISATION_ID = "unknownOrganisationId"; | ||
public static final String NEW_ENTITY_CANNOT_BE_ALREADY_VERIFIED_ERROR_MSG = "a new organisation cannot be created with a true verification status"; | ||
public static final String ORG_LESS_NEW_USER_ERROR_MSG = "a new user cannot be made without specifying a valid parent org"; | ||
|
@@ -122,13 +124,17 @@ private boolean isValidAccountModificationRequest(AccountRequest request) { | |
} | ||
|
||
public User getUserInOrg(String expectedOrganisationId, String userId) { | ||
String returnedOrgId = (getOrganisationById(expectedOrganisationId)).getId(); | ||
if (PRECONDITIONED_UNKNOWN_USER_ID.equals(userId)) { | ||
String returnedOrgId = (getOrganisationById(expectedOrganisationId)).getId(); | ||
Optional<User> userToReturn = userRepo.findById(userId); | ||
if (PRECONDITIONED_KNOWN_USER_ID.equals(userId)){ | ||
return new User(userId, true, "", "", expectedOrganisationId); | ||
} | ||
if (PRECONDITIONED_UNKNOWN_USER_ID.equals(userId) || !userToReturn.isPresent() || !returnedOrgId.equals(userToReturn.get().getBelongsToOrgWithId())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think now that we are integrating with mongo, we should remove all the pre-conditioned known and unknown users as it could bite us later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. theres quite a few tests that depend on these being there. How do you suggest we handle those There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, you mean the unit tests or the integration tests? If integration test, the comment I made on the PR as a whole explains a possible approach. We could also try a similar approach with our unit tests. I'll also be looking into whether there are any "in memory" Mongo solutions we can plug in for unit testing. |
||
targetExecutionContext.getLogger().log(Level.WARNING, | ||
String.format("UserId %s in Org %s could not be found", userId, expectedOrganisationId)); | ||
throw new IdentityServiceException(UNKNOWN_USERID_EXCEPTION_MSG); | ||
} | ||
return new User(userId, false, "a name", "https://domain.com/img.png", returnedOrgId); | ||
return userToReturn.get(); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem we have here now is that we have integration tests that now depend on one another running in a certain order. As scenarios will get more complex we generally want to avoid this. One way of resolving this is to add the steps for creating the above user within the feature itself so: