use of org.pmiops.workbench.model.Profile in project workbench by all-of-us.
the class ProfileControllerTest method createUser.
private Profile createUser() throws Exception {
when(cloudStorageService.readInvitationKey()).thenReturn(INVITATION_KEY);
when(directoryService.createUser(GIVEN_NAME, FAMILY_NAME, USERNAME, PASSWORD)).thenReturn(googleUser);
when(fireCloudService.isRequesterEnabledInFirecloud()).thenReturn(false);
Profile result = profileController.createAccount(createAccountRequest).getBody();
user = userDao.findUserByEmail(PRIMARY_EMAIL);
user.setEmailVerificationStatus(EmailVerificationStatus.SUBSCRIBED);
userDao.save(user);
when(userProvider.get()).thenReturn(user);
when(userAuthenticationProvider.get()).thenReturn(new UserAuthentication(user, null, null, UserType.RESEARCHER));
return result;
}
use of org.pmiops.workbench.model.Profile in project workbench by all-of-us.
the class ProfileService method getProfile.
public Profile getProfile(User user) throws ApiException {
// Fetch the user's authorities, since they aren't loaded during normal request interception.
User userWithAuthorities = userDao.findUserWithAuthorities(user.getUserId());
if (userWithAuthorities != null) {
// If the user is already written to the database, use it and whatever authorities are there.
user = userWithAuthorities;
}
boolean enabledInFireCloud = fireCloudService.isRequesterEnabledInFirecloud();
Profile profile = new Profile();
profile.setUserId(user.getUserId());
profile.setUsername(user.getEmail());
profile.setFamilyName(user.getFamilyName());
profile.setGivenName(user.getGivenName());
profile.setContactEmail(user.getContactEmail());
profile.setPhoneNumber(user.getPhoneNumber());
profile.setFreeTierBillingProjectName(user.getFreeTierBillingProjectName());
profile.setFreeTierBillingProjectStatus(user.getFreeTierBillingProjectStatus());
profile.setEnabledInFireCloud(enabledInFireCloud);
if (user.getBlockscoreVerificationIsValid() == null) {
profile.setBlockscoreIdVerificationStatus(BlockscoreIdVerificationStatus.UNVERIFIED);
} else if (user.getBlockscoreVerificationIsValid() == false) {
profile.setBlockscoreIdVerificationStatus(BlockscoreIdVerificationStatus.REJECTED);
} else {
profile.setBlockscoreIdVerificationStatus(BlockscoreIdVerificationStatus.VERIFIED);
}
if (user.getTermsOfServiceCompletionTime() != null) {
profile.setTermsOfServiceCompletionTime(user.getTermsOfServiceCompletionTime().getTime());
}
if (user.getEthicsTrainingCompletionTime() != null) {
profile.setEthicsTrainingCompletionTime(user.getEthicsTrainingCompletionTime().getTime());
}
if (user.getDemographicSurveyCompletionTime() != null) {
profile.setDemographicSurveyCompletionTime(user.getDemographicSurveyCompletionTime().getTime());
}
if (user.getDataAccessLevel() != null) {
profile.setDataAccessLevel(user.getDataAccessLevel());
}
if (user.getAuthorities() != null) {
profile.setAuthorities(new ArrayList<>(user.getAuthorities()));
}
EmailVerificationStatus userEmailVerificationStatus = user.getEmailVerificationStatus();
// if verification is pending or unverified, need to query MailChimp and update DB accordingly
if (!userEmailVerificationStatus.equals(EmailVerificationStatus.SUBSCRIBED)) {
if (userEmailVerificationStatus.equals(EmailVerificationStatus.UNVERIFIED) && user.getContactEmail() != null) {
mailChimpService.addUserContactEmail(user.getContactEmail());
userEmailVerificationStatus = EmailVerificationStatus.PENDING;
} else if (userEmailVerificationStatus.equals(EmailVerificationStatus.PENDING)) {
userEmailVerificationStatus = EmailVerificationStatus.fromValue(mailChimpService.getMember(user.getContactEmail()));
}
user.setEmailVerificationStatus(userEmailVerificationStatus);
userDao.save(user);
}
profile.setEmailVerificationStatus(user.getEmailVerificationStatus());
return profile;
}
Aggregations