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));
}
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);
}
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);
}
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);
}
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);
});
}
Aggregations