Search in sources :

Example 1 with User

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

the class ProfileController method submitIdVerification.

@Override
public ResponseEntity<Profile> submitIdVerification(IdVerificationRequest request) {
    // TODO(dmohs): Prevent this if the user has already attempted verification?
    Person person = blockscoreService.createPerson(request.getFirstName(), request.getLastName(), new Address().setStreet1(request.getStreetLine1()).setStreet2(request.getStreetLine2()).setCity(request.getCity()).setSubdivision(request.getState()).setPostalCode(request.getZip()).setCountryCode("US"), request.getDob(), request.getDocumentType(), request.getDocumentNumber());
    User user = userService.setBlockscoreIdVerification(person.getId(), person.isValid());
    return getProfileResponse(user);
}
Also used : User(org.pmiops.workbench.db.model.User) Address(com.blockscore.models.Address) InternetAddress(javax.mail.internet.InternetAddress) Person(com.blockscore.models.Person)

Example 2 with User

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

the class ProfileController method getIdVerificationsForReview.

@Override
@AuthorityRequired({ Authority.REVIEW_ID_VERIFICATION })
public ResponseEntity<IdVerificationListResponse> getIdVerificationsForReview() {
    IdVerificationListResponse response = new IdVerificationListResponse();
    List<Profile> responseList = new ArrayList<Profile>();
    try {
        for (User user : userService.getNonVerifiedUsers()) {
            responseList.add(profileService.getProfile(user));
        }
    } catch (ApiException e) {
        log.log(Level.INFO, "Error calling FireCloud", e);
        return ResponseEntity.status(e.getCode()).build();
    }
    response.setProfileList(responseList);
    return ResponseEntity.ok(response);
}
Also used : IdVerificationListResponse(org.pmiops.workbench.model.IdVerificationListResponse) User(org.pmiops.workbench.db.model.User) ArrayList(java.util.ArrayList) Profile(org.pmiops.workbench.model.Profile) ApiException(org.pmiops.workbench.firecloud.ApiException) AuthorityRequired(org.pmiops.workbench.annotations.AuthorityRequired)

Example 3 with User

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

the class WorkspacesController method createWorkspace.

@Override
public ResponseEntity<Workspace> createWorkspace(Workspace workspace) {
    if (Strings.isNullOrEmpty(workspace.getNamespace())) {
        throw new BadRequestException("missing required field 'namespace'");
    } else if (Strings.isNullOrEmpty(workspace.getName())) {
        throw new BadRequestException("missing required field 'name'");
    } else if (workspace.getResearchPurpose() == null) {
        throw new BadRequestException("missing required field 'researchPurpose'");
    } else if (workspace.getDataAccessLevel() == null) {
        throw new BadRequestException("missing required field 'dataAccessLevel'");
    }
    User user = userProvider.get();
    org.pmiops.workbench.db.model.Workspace existingWorkspace = workspaceService.getByName(workspace.getNamespace(), workspace.getName());
    if (existingWorkspace != null) {
        throw new ConflictException(String.format("Workspace %s/%s already exists", workspace.getNamespace(), workspace.getName()));
    }
    // Note: please keep any initialization logic here in sync with CloneWorkspace().
    FirecloudWorkspaceId workspaceId = generateFirecloudWorkspaceId(workspace.getNamespace(), workspace.getName());
    FirecloudWorkspaceId fcWorkspaceId = workspaceId;
    org.pmiops.workbench.firecloud.model.Workspace fcWorkspace = null;
    for (int attemptValue = 0; attemptValue < MAX_FC_CREATION_ATTEMPT_VALUES; attemptValue++) {
        try {
            fcWorkspace = attemptFirecloudWorkspaceCreation(fcWorkspaceId);
            break;
        } catch (ConflictException e) {
            if (attemptValue >= 5) {
                throw e;
            } else {
                fcWorkspaceId = new FirecloudWorkspaceId(workspaceId.getWorkspaceNamespace(), workspaceId.getWorkspaceName() + Integer.toString(attemptValue));
            }
        }
    }
    Timestamp now = new Timestamp(clock.instant().toEpochMilli());
    org.pmiops.workbench.db.model.Workspace dbWorkspace = new org.pmiops.workbench.db.model.Workspace();
    dbWorkspace.setFirecloudName(fcWorkspaceId.getWorkspaceName());
    dbWorkspace.setWorkspaceNamespace(fcWorkspaceId.getWorkspaceNamespace());
    dbWorkspace.setCreator(user);
    dbWorkspace.setCreationTime(now);
    dbWorkspace.setLastModifiedTime(now);
    dbWorkspace.setVersion(1);
    setCdrVersionId(dbWorkspace, workspace.getCdrVersionId());
    writeWorkspaceConfigFile(fcWorkspace, dbWorkspace.getCdrVersion());
    org.pmiops.workbench.db.model.Workspace reqWorkspace = FROM_CLIENT_WORKSPACE.apply(workspace);
    // TODO: enforce data access level authorization
    dbWorkspace.setDataAccessLevel(reqWorkspace.getDataAccessLevel());
    dbWorkspace.setName(reqWorkspace.getName());
    dbWorkspace.setDescription(reqWorkspace.getDescription());
    // Ignore incoming fields pertaining to review status; clients can only request a review.
    setResearchPurposeDetails(dbWorkspace, workspace.getResearchPurpose());
    if (reqWorkspace.getReviewRequested()) {
        // Use a consistent timestamp.
        dbWorkspace.setTimeRequested(now);
    }
    dbWorkspace.setReviewRequested(reqWorkspace.getReviewRequested());
    org.pmiops.workbench.db.model.WorkspaceUserRole permissions = new org.pmiops.workbench.db.model.WorkspaceUserRole();
    permissions.setRole(WorkspaceAccessLevel.OWNER);
    permissions.setWorkspace(dbWorkspace);
    permissions.setUser(user);
    dbWorkspace.addWorkspaceUserRole(permissions);
    dbWorkspace = workspaceService.getDao().save(dbWorkspace);
    return ResponseEntity.ok(TO_SINGLE_CLIENT_WORKSPACE_FROM_FC_AND_DB.apply(dbWorkspace, fcWorkspace));
}
Also used : User(org.pmiops.workbench.db.model.User) ConflictException(org.pmiops.workbench.exceptions.ConflictException) WorkspaceUserRole(org.pmiops.workbench.db.model.WorkspaceUserRole) Timestamp(java.sql.Timestamp) FirecloudWorkspaceId(org.pmiops.workbench.db.model.Workspace.FirecloudWorkspaceId) BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) WorkspaceUserRole(org.pmiops.workbench.db.model.WorkspaceUserRole) Workspace(org.pmiops.workbench.model.Workspace)

Example 4 with User

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

the class AuthDomainController method addUserToAuthDomain.

@Override
@AuthorityRequired({ Authority.MANAGE_GROUP })
public ResponseEntity<Void> addUserToAuthDomain(String groupName, AuthDomainRequest request) {
    User user = userDao.findUserByEmail(request.getEmail());
    DataAccessLevel previousAccess = user.getDataAccessLevel();
    try {
        fireCloudService.addUserToGroup(request.getEmail(), groupName);
    } catch (ApiException e) {
        ExceptionUtils.convertFirecloudException(e);
    }
    // TODO(blrubenstein): Parameterize this.
    user.setDataAccessLevel(DataAccessLevel.REGISTERED);
    user.setDisabled(false);
    userDao.save(user);
    userService.logAdminUserAction(user.getUserId(), "user access to  " + groupName + " domain", previousAccess, DataAccessLevel.REGISTERED);
    return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
Also used : User(org.pmiops.workbench.db.model.User) DataAccessLevel(org.pmiops.workbench.model.DataAccessLevel) ApiException(org.pmiops.workbench.firecloud.ApiException) AuthorityRequired(org.pmiops.workbench.annotations.AuthorityRequired)

Example 5 with User

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

the class ProfileControllerTest method assertUser.

private void assertUser(String primaryEmail, String contactEmail, String familyName, String givenName, DataAccessLevel dataAccessLevel, Timestamp firstSignInTime, String freeTierBillingProject) {
    User user = userDao.findUserByEmail(primaryEmail);
    assertThat(user).isNotNull();
    assertThat(user.getContactEmail()).isEqualTo(contactEmail);
    assertThat(user.getFamilyName()).isEqualTo(familyName);
    assertThat(user.getGivenName()).isEqualTo(givenName);
    assertThat(user.getDataAccessLevel()).isEqualTo(dataAccessLevel);
    assertThat(user.getFirstSignInTime()).isEqualTo(firstSignInTime);
    assertThat(user.getFreeTierBillingProjectName()).isEqualTo(freeTierBillingProject);
    assertThat(user.getDataAccessLevel()).isEqualTo(dataAccessLevel);
}
Also used : User(org.pmiops.workbench.db.model.User)

Aggregations

User (org.pmiops.workbench.db.model.User)27 Test (org.junit.Test)8 Workspace (org.pmiops.workbench.model.Workspace)8 ApiException (org.pmiops.workbench.firecloud.ApiException)7 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)6 ResearchPurpose (org.pmiops.workbench.model.ResearchPurpose)5 Before (org.junit.Before)4 AuthorityRequired (org.pmiops.workbench.annotations.AuthorityRequired)4 WorkspaceUserRole (org.pmiops.workbench.db.model.WorkspaceUserRole)4 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)4 ConflictException (org.pmiops.workbench.exceptions.ConflictException)4 ShareWorkspaceResponse (org.pmiops.workbench.model.ShareWorkspaceResponse)4 UserRole (org.pmiops.workbench.model.UserRole)4 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3 CdrVersion (org.pmiops.workbench.db.model.CdrVersion)3 WorkspaceACLUpdate (org.pmiops.workbench.firecloud.model.WorkspaceACLUpdate)3 WorkspaceACLUpdateResponseList (org.pmiops.workbench.firecloud.model.WorkspaceACLUpdateResponseList)3 Profile (org.pmiops.workbench.model.Profile)3 ShareWorkspaceRequest (org.pmiops.workbench.model.ShareWorkspaceRequest)3