Search in sources :

Example 16 with User

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

the class WorkspacesControllerTest method testShareWorkspace.

@Test
public void testShareWorkspace() throws Exception {
    User writerUser = new User();
    writerUser.setEmail("writerfriend@gmail.com");
    writerUser.setUserId(124L);
    writerUser.setFreeTierBillingProjectName("TestBillingProject2");
    writerUser.setDisabled(false);
    writerUser = userDao.save(writerUser);
    User readerUser = new User();
    readerUser.setEmail("readerfriend@gmail.com");
    readerUser.setUserId(125L);
    readerUser.setFreeTierBillingProjectName("TestBillingProject3");
    readerUser.setDisabled(false);
    readerUser = userDao.save(readerUser);
    Workspace workspace = createDefaultWorkspace();
    workspace = workspacesController.createWorkspace(workspace).getBody();
    ShareWorkspaceRequest shareWorkspaceRequest = new ShareWorkspaceRequest();
    shareWorkspaceRequest.setWorkspaceEtag(workspace.getEtag());
    UserRole creator = new UserRole();
    creator.setEmail(LOGGED_IN_USER_EMAIL);
    creator.setRole(WorkspaceAccessLevel.OWNER);
    shareWorkspaceRequest.addItemsItem(creator);
    UserRole writer = new UserRole();
    writer.setEmail("writerfriend@gmail.com");
    writer.setRole(WorkspaceAccessLevel.WRITER);
    shareWorkspaceRequest.addItemsItem(writer);
    UserRole reader = new UserRole();
    reader.setEmail("readerfriend@gmail.com");
    reader.setRole(WorkspaceAccessLevel.READER);
    shareWorkspaceRequest.addItemsItem(reader);
    // Simulate time between API calls to trigger last-modified/@Version changes.
    CLOCK.increment(1000);
    WorkspaceACLUpdateResponseList responseValue = new WorkspaceACLUpdateResponseList();
    when(fireCloudService.updateWorkspaceACL(anyString(), anyString(), anyListOf(WorkspaceACLUpdate.class))).thenReturn(responseValue);
    ShareWorkspaceResponse shareResp = workspacesController.shareWorkspace(workspace.getNamespace(), workspace.getName(), shareWorkspaceRequest).getBody();
    stubGetWorkspace(workspace.getNamespace(), workspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    Workspace workspace2 = workspacesController.getWorkspace(workspace.getNamespace(), workspace.getName()).getBody().getWorkspace();
    assertThat(shareResp.getWorkspaceEtag()).isEqualTo(workspace2.getEtag());
    assertThat(workspace2.getUserRoles().size()).isEqualTo(3);
    int numOwners = 0;
    int numWriters = 0;
    int numReaders = 0;
    for (UserRole userRole : workspace2.getUserRoles()) {
        if (userRole.getRole().equals(WorkspaceAccessLevel.OWNER)) {
            assertThat(userRole.getEmail()).isEqualTo(LOGGED_IN_USER_EMAIL);
            numOwners++;
        } else if (userRole.getRole().equals(WorkspaceAccessLevel.WRITER)) {
            assertThat(userRole.getEmail()).isEqualTo("writerfriend@gmail.com");
            numWriters++;
        } else {
            assertThat(userRole.getEmail()).isEqualTo("readerfriend@gmail.com");
            numReaders++;
        }
    }
    assertThat(numOwners).isEqualTo(1);
    assertThat(numWriters).isEqualTo(1);
    assertThat(numReaders).isEqualTo(1);
    assertThat(workspace.getEtag()).isNotEqualTo(workspace2.getEtag());
}
Also used : ShareWorkspaceResponse(org.pmiops.workbench.model.ShareWorkspaceResponse) User(org.pmiops.workbench.db.model.User) UserRole(org.pmiops.workbench.model.UserRole) WorkspaceACLUpdateResponseList(org.pmiops.workbench.firecloud.model.WorkspaceACLUpdateResponseList) ShareWorkspaceRequest(org.pmiops.workbench.model.ShareWorkspaceRequest) Workspace(org.pmiops.workbench.model.Workspace) WorkspaceACLUpdate(org.pmiops.workbench.firecloud.model.WorkspaceACLUpdate) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 17 with User

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

the class WorkspacesControllerTest method testUnshareWorkspace.

@Test
public void testUnshareWorkspace() throws Exception {
    User writerUser = new User();
    writerUser.setEmail("writerfriend@gmail.com");
    writerUser.setUserId(124L);
    writerUser.setFreeTierBillingProjectName("TestBillingProject2");
    writerUser.setDisabled(false);
    writerUser = userDao.save(writerUser);
    User readerUser = new User();
    readerUser.setEmail("readerfriend@gmail.com");
    readerUser.setUserId(125L);
    readerUser.setFreeTierBillingProjectName("TestBillingProject3");
    readerUser.setDisabled(false);
    readerUser = userDao.save(readerUser);
    Workspace workspace = createDefaultWorkspace();
    workspace = workspacesController.createWorkspace(workspace).getBody();
    ShareWorkspaceRequest shareWorkspaceRequest = new ShareWorkspaceRequest();
    shareWorkspaceRequest.setWorkspaceEtag(workspace.getEtag());
    UserRole creator = new UserRole();
    creator.setEmail(LOGGED_IN_USER_EMAIL);
    creator.setRole(WorkspaceAccessLevel.OWNER);
    shareWorkspaceRequest.addItemsItem(creator);
    UserRole writer = new UserRole();
    writer.setEmail("writerfriend@gmail.com");
    writer.setRole(WorkspaceAccessLevel.WRITER);
    shareWorkspaceRequest.addItemsItem(writer);
    UserRole reader = new UserRole();
    reader.setEmail("readerfriend@gmail.com");
    reader.setRole(WorkspaceAccessLevel.READER);
    shareWorkspaceRequest.addItemsItem(reader);
    WorkspaceACLUpdateResponseList responseValue = new WorkspaceACLUpdateResponseList();
    responseValue.setUsersNotFound(new ArrayList<WorkspaceACLUpdate>());
    // Simulate time between API calls to trigger last-modified/@Version changes.
    CLOCK.increment(1000);
    when(fireCloudService.updateWorkspaceACL(anyString(), anyString(), anyListOf(WorkspaceACLUpdate.class))).thenReturn(responseValue);
    ShareWorkspaceResponse shareResp = workspacesController.shareWorkspace(workspace.getNamespace(), workspace.getName(), shareWorkspaceRequest).getBody();
    stubGetWorkspace(workspace.getNamespace(), workspace.getId(), workspace.getCreator(), WorkspaceAccessLevel.OWNER);
    Workspace workspace2 = workspacesController.getWorkspace(workspace.getNamespace(), workspace.getId()).getBody().getWorkspace();
    assertThat(shareResp.getWorkspaceEtag()).isEqualTo(workspace2.getEtag());
    CLOCK.increment(1000);
    shareWorkspaceRequest = new ShareWorkspaceRequest();
    shareWorkspaceRequest.setWorkspaceEtag(workspace2.getEtag());
    shareWorkspaceRequest.addItemsItem(creator);
    shareWorkspaceRequest.addItemsItem(writer);
    shareResp = workspacesController.shareWorkspace(workspace.getNamespace(), workspace.getName(), shareWorkspaceRequest).getBody();
    Workspace workspace3 = workspacesController.getWorkspace(workspace.getNamespace(), workspace.getId()).getBody().getWorkspace();
    assertThat(shareResp.getWorkspaceEtag()).isEqualTo(workspace3.getEtag());
    assertThat(workspace3.getUserRoles().size()).isEqualTo(2);
    int numOwners = 0;
    int numWriters = 0;
    int numReaders = 0;
    for (UserRole userRole : workspace3.getUserRoles()) {
        if (userRole.getRole().equals(WorkspaceAccessLevel.OWNER)) {
            assertThat(userRole.getEmail()).isEqualTo(LOGGED_IN_USER_EMAIL);
            numOwners++;
        } else if (userRole.getRole().equals(WorkspaceAccessLevel.WRITER)) {
            assertThat(userRole.getEmail()).isEqualTo("writerfriend@gmail.com");
            numWriters++;
        } else {
            assertThat(userRole.getEmail()).isEqualTo("readerfriend@gmail.com");
            numReaders++;
        }
    }
    assertThat(numOwners).isEqualTo(1);
    assertThat(numWriters).isEqualTo(1);
    assertThat(numReaders).isEqualTo(0);
    assertThat(workspace.getEtag()).isNotEqualTo(workspace2.getEtag());
    assertThat(workspace2.getEtag()).isNotEqualTo(workspace3.getEtag());
}
Also used : ShareWorkspaceResponse(org.pmiops.workbench.model.ShareWorkspaceResponse) User(org.pmiops.workbench.db.model.User) UserRole(org.pmiops.workbench.model.UserRole) WorkspaceACLUpdateResponseList(org.pmiops.workbench.firecloud.model.WorkspaceACLUpdateResponseList) ShareWorkspaceRequest(org.pmiops.workbench.model.ShareWorkspaceRequest) Workspace(org.pmiops.workbench.model.Workspace) WorkspaceACLUpdate(org.pmiops.workbench.firecloud.model.WorkspaceACLUpdate) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 18 with User

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

the class WorkspacesControllerTest method testCloneWorkspace.

@Test
public void testCloneWorkspace() throws Exception {
    Workspace workspace = createDefaultWorkspace();
    workspace = workspacesController.createWorkspace(workspace).getBody();
    // The original workspace is shared with one other user.
    User writerUser = new User();
    writerUser.setEmail("writerfriend@gmail.com");
    writerUser.setUserId(124L);
    writerUser.setFreeTierBillingProjectName("TestBillingProject2");
    writerUser.setDisabled(false);
    writerUser = userDao.save(writerUser);
    ShareWorkspaceRequest shareWorkspaceRequest = new ShareWorkspaceRequest();
    shareWorkspaceRequest.setWorkspaceEtag(workspace.getEtag());
    UserRole creator = new UserRole();
    creator.setEmail(LOGGED_IN_USER_EMAIL);
    creator.setRole(WorkspaceAccessLevel.OWNER);
    shareWorkspaceRequest.addItemsItem(creator);
    UserRole writer = new UserRole();
    writer.setEmail(writerUser.getEmail());
    writer.setRole(WorkspaceAccessLevel.WRITER);
    shareWorkspaceRequest.addItemsItem(writer);
    when(fireCloudService.updateWorkspaceACL(anyString(), anyString(), anyListOf(WorkspaceACLUpdate.class))).thenReturn(new WorkspaceACLUpdateResponseList());
    workspacesController.shareWorkspace(workspace.getNamespace(), workspace.getName(), shareWorkspaceRequest);
    stubGetWorkspace(workspace.getNamespace(), workspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    CloneWorkspaceRequest req = new CloneWorkspaceRequest();
    Workspace modWorkspace = new Workspace();
    modWorkspace.setName("cloned");
    modWorkspace.setNamespace("cloned-ns");
    ResearchPurpose modPurpose = new ResearchPurpose();
    modPurpose.setAncestry(true);
    modWorkspace.setResearchPurpose(modPurpose);
    req.setWorkspace(modWorkspace);
    stubGetWorkspace(modWorkspace.getNamespace(), modWorkspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    Workspace workspace2 = workspacesController.cloneWorkspace(workspace.getNamespace(), workspace.getId(), req).getBody().getWorkspace();
    assertWithMessage("get and clone responses are inconsistent").that(workspace2).isEqualTo(workspacesController.getWorkspace(workspace2.getNamespace(), workspace2.getId()).getBody().getWorkspace());
    assertThat(workspace2.getName()).isEqualTo(modWorkspace.getName());
    assertThat(workspace2.getNamespace()).isEqualTo(modWorkspace.getNamespace());
    assertThat(workspace2.getResearchPurpose()).isEqualTo(modPurpose);
    // Original description should have been copied.
    assertThat(workspace2.getDescription()).isEqualTo(workspace.getDescription());
    // User roles should *not* be copied.
    assertThat(workspace2.getUserRoles().size()).isEqualTo(1);
    assertThat(workspace2.getUserRoles().get(0).getRole()).isEqualTo(WorkspaceAccessLevel.OWNER);
}
Also used : User(org.pmiops.workbench.db.model.User) CloneWorkspaceRequest(org.pmiops.workbench.model.CloneWorkspaceRequest) UserRole(org.pmiops.workbench.model.UserRole) WorkspaceACLUpdateResponseList(org.pmiops.workbench.firecloud.model.WorkspaceACLUpdateResponseList) ShareWorkspaceRequest(org.pmiops.workbench.model.ShareWorkspaceRequest) Workspace(org.pmiops.workbench.model.Workspace) WorkspaceACLUpdate(org.pmiops.workbench.firecloud.model.WorkspaceACLUpdate) ResearchPurpose(org.pmiops.workbench.model.ResearchPurpose) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 19 with User

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

the class AuthInterceptorTest method authorityCheckPermitsWhenUserHasAuthority.

@Test
public void authorityCheckPermitsWhenUserHasAuthority() throws Exception {
    User userWithAuthorities = new User();
    Set<Authority> required = new HashSet<Authority>();
    required.add(Authority.REVIEW_RESEARCH_PURPOSE);
    userWithAuthorities.setAuthorities(required);
    when(userDao.findUserWithAuthorities(USER_ID)).thenReturn(userWithAuthorities);
    Method apiControllerMethod = FakeApiController.class.getMethod("handle");
    assertThat(interceptor.hasRequiredAuthority(apiControllerMethod, user)).isTrue();
}
Also used : User(org.pmiops.workbench.db.model.User) Authority(org.pmiops.workbench.model.Authority) HandlerMethod(org.springframework.web.method.HandlerMethod) Method(java.lang.reflect.Method) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with User

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

the class ProfileController method updateProfile.

@Override
public ResponseEntity<Void> updateProfile(Profile updatedProfile) {
    User user = userProvider.get();
    user.setGivenName(updatedProfile.getGivenName());
    user.setFamilyName(updatedProfile.getFamilyName());
    if (updatedProfile.getContactEmail() != null) {
        if (!updatedProfile.getContactEmail().equals(user.getContactEmail())) {
            mailChimpService.addUserContactEmail(updatedProfile.getContactEmail());
            user.setEmailVerificationStatus(EmailVerificationStatus.PENDING);
            user.setContactEmail(updatedProfile.getContactEmail());
        }
    }
    // This does not update the name in Google.
    userDao.save(user);
    return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
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