Search in sources :

Example 16 with Profile

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;
}
Also used : UserAuthentication(org.pmiops.workbench.auth.UserAuthentication) Profile(org.pmiops.workbench.model.Profile)

Example 17 with Profile

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;
}
Also used : User(org.pmiops.workbench.db.model.User) EmailVerificationStatus(org.pmiops.workbench.model.EmailVerificationStatus) Profile(org.pmiops.workbench.model.Profile)

Aggregations

Profile (org.pmiops.workbench.model.Profile)17 Test (org.junit.Test)13 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)13 BillingProjectMembership (org.pmiops.workbench.model.BillingProjectMembership)4 ApiException (org.pmiops.workbench.firecloud.ApiException)3 Address (com.blockscore.models.Address)2 WorkbenchConfig (org.pmiops.workbench.config.WorkbenchConfig)2 FireCloudConfig (org.pmiops.workbench.config.WorkbenchConfig.FireCloudConfig)2 User (org.pmiops.workbench.db.model.User)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 AuthorityRequired (org.pmiops.workbench.annotations.AuthorityRequired)1 ProfileService (org.pmiops.workbench.auth.ProfileService)1 UserAuthentication (org.pmiops.workbench.auth.UserAuthentication)1 WorkbenchEnvironment (org.pmiops.workbench.config.WorkbenchEnvironment)1 UserService (org.pmiops.workbench.db.dao.UserService)1 CreateAccountRequest (org.pmiops.workbench.model.CreateAccountRequest)1 EmailVerificationStatus (org.pmiops.workbench.model.EmailVerificationStatus)1 IdVerificationListResponse (org.pmiops.workbench.model.IdVerificationListResponse)1 IdVerificationRequest (org.pmiops.workbench.model.IdVerificationRequest)1