Search in sources :

Example 1 with Institution

use of org.pmiops.workbench.model.Institution in project workbench by all-of-us.

the class DevUserRegistrationServiceImpl method createUser.

@Override
public DbUser createUser(Userinfoplus userInfo) {
    // We'll try to lookup the GSuite contact email if available. Otherwise, fall back to the
    // username email address (e.g. foobar@fake-research-aou.org).
    String contactEmail = directoryService.getContactEmail(userInfo.getEmail()).orElse(userInfo.getEmail());
    log.info(String.format("Re-creating dev user '%s' with contact email '%s'.", userInfo.getEmail(), contactEmail));
    Institution institution = institutionService.getFirstMatchingInstitution(contactEmail).orElseThrow(() -> new BadRequestException(String.format("Contact email %s does not match any institutions. Cannot register new dev user.", contactEmail)));
    VerifiedInstitutionalAffiliation verifiedAffiliation = new VerifiedInstitutionalAffiliation().institutionShortName(institution.getShortName()).institutionalRoleEnum(InstitutionalRole.OTHER).institutionalRoleOtherText("System developer");
    return userService.createUser(userInfo, contactEmail, verifiedInstitutionalAffiliationMapper.modelToDbWithoutUser(verifiedAffiliation, institutionService));
}
Also used : VerifiedInstitutionalAffiliation(org.pmiops.workbench.model.VerifiedInstitutionalAffiliation) BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) Institution(org.pmiops.workbench.model.Institution)

Example 2 with Institution

use of org.pmiops.workbench.model.Institution in project workbench by all-of-us.

the class ProfileControllerTest method test_updateAccountProperties_contactEmail_newAffiliation_self_match.

@Test
public void test_updateAccountProperties_contactEmail_newAffiliation_self_match() {
    // ProfileController.updateAccountProperties() is gated on ACCESS_CONTROL_ADMIN Authority
    // which is also checked in ProfileService.validateProfile()
    boolean grantAdminAuthority = true;
    final VerifiedInstitutionalAffiliation expectedOriginalAffiliation = new VerifiedInstitutionalAffiliation().institutionShortName("Broad").institutionDisplayName("The Broad Institute").institutionalRoleEnum(InstitutionalRole.PROJECT_PERSONNEL);
    final Profile original = createAccountAndDbUserWithAffiliation(grantAdminAuthority);
    assertThat(original.getContactEmail()).isEqualTo(CONTACT_EMAIL);
    assertThat(original.getVerifiedInstitutionalAffiliation()).isEqualTo(expectedOriginalAffiliation);
    // update both the contact email and the affiliation, and validate against each other
    final String newContactEmail = "doctor@mgh.org";
    final Institution massGeneral = new Institution().shortName("MGH123").displayName("Massachusetts General Hospital").addTierConfigsItem(rtDomainsConfig.emailDomains(ImmutableList.of("mgh.org", "massgeneral.hospital"))).organizationTypeEnum(OrganizationType.HEALTH_CENTER_NON_PROFIT);
    institutionService.createInstitution(massGeneral);
    final VerifiedInstitutionalAffiliation newAffiliation = new VerifiedInstitutionalAffiliation().institutionShortName(massGeneral.getShortName()).institutionDisplayName(massGeneral.getDisplayName()).institutionalRoleEnum(InstitutionalRole.POST_DOCTORAL);
    final AccountPropertyUpdate request = new AccountPropertyUpdate().username(FULL_USER_NAME).contactEmail(newContactEmail).affiliation(newAffiliation);
    final Profile retrieved = profileService.updateAccountProperties(request);
    assertThat(retrieved.getContactEmail()).isEqualTo(newContactEmail);
    assertThat(retrieved.getVerifiedInstitutionalAffiliation()).isEqualTo(newAffiliation);
    final Agent adminAgent = Agent.asAdmin(userDao.findUserByUserId(original.getUserId()));
    verify(mockProfileAuditor).fireUpdateAction(original, retrieved, adminAgent);
}
Also used : Agent(org.pmiops.workbench.actionaudit.Agent) VerifiedInstitutionalAffiliation(org.pmiops.workbench.model.VerifiedInstitutionalAffiliation) AccountPropertyUpdate(org.pmiops.workbench.model.AccountPropertyUpdate) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Institution(org.pmiops.workbench.model.Institution) Profile(org.pmiops.workbench.model.Profile) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.jupiter.api.Test)

Example 3 with Institution

use of org.pmiops.workbench.model.Institution in project workbench by all-of-us.

the class ProfileControllerTest method testCreateAccount_success_domainsRtRequirement.

@Test
public void testCreateAccount_success_domainsRtRequirement() {
    final Institution broad = new Institution().shortName("Broad").displayName("The Broad Institute").addTierConfigsItem(rtDomainsConfig.emailDomains(ImmutableList.of("example.com"))).organizationTypeEnum(OrganizationType.ACADEMIC_RESEARCH_INSTITUTION);
    institutionService.createInstitution(broad);
    final VerifiedInstitutionalAffiliation verifiedInstitutionalAffiliation = new VerifiedInstitutionalAffiliation().institutionShortName("Broad").institutionalRoleEnum(InstitutionalRole.STUDENT);
    createAccountRequest.getProfile().contactEmail("bob@example.com");
    createAccountAndDbUserWithAffiliation(verifiedInstitutionalAffiliation);
}
Also used : VerifiedInstitutionalAffiliation(org.pmiops.workbench.model.VerifiedInstitutionalAffiliation) Institution(org.pmiops.workbench.model.Institution) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.jupiter.api.Test)

Example 4 with Institution

use of org.pmiops.workbench.model.Institution in project workbench by all-of-us.

the class ProfileControllerTest method testCreateAccount_success_addressesRtRequirement.

@Test
public void testCreateAccount_success_addressesRtRequirement() {
    final Institution broad = new Institution().shortName("Broad").displayName("The Broad Institute").addTierConfigsItem(rtAddressesConfig.emailAddresses(ImmutableList.of(CONTACT_EMAIL))).organizationTypeEnum(OrganizationType.ACADEMIC_RESEARCH_INSTITUTION);
    institutionService.createInstitution(broad);
    final VerifiedInstitutionalAffiliation verifiedInstitutionalAffiliation = new VerifiedInstitutionalAffiliation().institutionShortName("Broad").institutionalRoleEnum(InstitutionalRole.STUDENT);
    createAccountRequest.getProfile().contactEmail(CONTACT_EMAIL);
    createAccountAndDbUserWithAffiliation(verifiedInstitutionalAffiliation);
}
Also used : VerifiedInstitutionalAffiliation(org.pmiops.workbench.model.VerifiedInstitutionalAffiliation) Institution(org.pmiops.workbench.model.Institution) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.jupiter.api.Test)

Example 5 with Institution

use of org.pmiops.workbench.model.Institution in project workbench by all-of-us.

the class ProfileControllerTest method testMe_verifiedInstitutionalAffiliation_invalidEmail.

@Test
public void testMe_verifiedInstitutionalAffiliation_invalidEmail() {
    assertThrows(BadRequestException.class, () -> {
        final Institution broad = new Institution().shortName("Broad").displayName("The Broad Institute").addTierConfigsItem(rtAddressesConfig.emailAddresses(ImmutableList.of())).organizationTypeEnum(OrganizationType.ACADEMIC_RESEARCH_INSTITUTION);
        institutionService.createInstitution(broad);
        final VerifiedInstitutionalAffiliation verifiedInstitutionalAffiliation = new VerifiedInstitutionalAffiliation().institutionShortName(broad.getShortName()).institutionalRoleEnum(InstitutionalRole.ADMIN);
        createAccountAndDbUserWithAffiliation(verifiedInstitutionalAffiliation);
    });
}
Also used : VerifiedInstitutionalAffiliation(org.pmiops.workbench.model.VerifiedInstitutionalAffiliation) Institution(org.pmiops.workbench.model.Institution) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.jupiter.api.Test)

Aggregations

Institution (org.pmiops.workbench.model.Institution)66 Test (org.junit.jupiter.api.Test)55 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)54 DbInstitution (org.pmiops.workbench.db.model.DbInstitution)46 VerifiedInstitutionalAffiliation (org.pmiops.workbench.model.VerifiedInstitutionalAffiliation)16 DbUser (org.pmiops.workbench.db.model.DbUser)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 AccountPropertyUpdate (org.pmiops.workbench.model.AccountPropertyUpdate)6 Profile (org.pmiops.workbench.model.Profile)6 UserTierEligibility (org.pmiops.workbench.model.UserTierEligibility)6 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)4 Agent (org.pmiops.workbench.actionaudit.Agent)3 User (com.google.api.services.directory.model.User)2 ArrayList (java.util.ArrayList)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)2 WorkbenchException (org.pmiops.workbench.exceptions.WorkbenchException)2 Timestamp (java.sql.Timestamp)1 MessagingException (javax.mail.MessagingException)1 AddressException (javax.mail.internet.AddressException)1