Search in sources :

Example 1 with GetUsers

use of org.activityinfo.legacy.shared.command.GetUsers in project activityinfo by bedatadriven.

the class UpdateUserPermissionsHandlerTest method testOwnerUpdate.

/**
 * Verifies that the owner of a database can update an existing users permission
 */
@Test
@OnDataSet("/dbunit/schema1.db.xml")
public void testOwnerUpdate() throws CommandException {
    setUser(1);
    UserPermissionDTO user = new UserPermissionDTO();
    user.setEmail("bavon@nrcdrc.org");
    user.setPartner(new PartnerDTO(1, "NRC"));
    user.setAllowView(true);
    user.setAllowViewAll(false);
    user.setAllowEdit(true);
    user.setAllowEdit(false);
    user.setAllowDesign(true);
    execute(new UpdateUserPermissions(1, user));
    UserResult result = execute(new GetUsers(1));
    UserPermissionDTO reUser = result.getData().get(0);
    assertThat(reUser.getEmail(), equalTo("bavon@nrcdrc.org"));
    assertThat(reUser.getAllowDesign(), equalTo(true));
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) UpdateUserPermissions(org.activityinfo.legacy.shared.command.UpdateUserPermissions) UserResult(org.activityinfo.legacy.shared.command.result.UserResult) GetUsers(org.activityinfo.legacy.shared.command.GetUsers) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 2 with GetUsers

use of org.activityinfo.legacy.shared.command.GetUsers in project activityinfo by bedatadriven.

the class UpdatePartnerHandlerTest method modifyShared.

@Test
public void modifyShared() {
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO nfiDatabase = schema.getDatabaseById(NFI_DATABASE);
    UserDatabaseDTO healthDatabase = schema.getDatabaseById(HEALTH_DATABASE);
    // The "Default" partner starts out being shared between the two database.
    PartnerDTO nfiDefaultPartner = nfiDatabase.getDefaultPartner().get();
    PartnerDTO healthDefaultPartner = healthDatabase.getDefaultPartner().get();
    assertThat(nfiDefaultPartner.getId(), equalTo(healthDefaultPartner.getId()));
    // If I update the name of "Default" partner for my database, a copy should
    // be created.
    PartnerDTO updatedPartner = new PartnerDTO(nfiDefaultPartner.getId(), "Solidarites");
    updatedPartner.setFullName("Solidarites International");
    execute(new UpdatePartner(1, updatedPartner));
    // Now we should have two distinct partner objects
    schema = execute(new GetSchema());
    nfiDatabase = schema.getDatabaseById(NFI_DATABASE);
    healthDatabase = schema.getDatabaseById(HEALTH_DATABASE);
    assertThat(nfiDatabase.getPartners(), containsInAnyOrder(hasProperty("name", equalTo("Solidarites")), hasProperty("name", equalTo("NRC"))));
    assertThat(healthDatabase.getPartners(), contains(hasProperty("name", equalTo("Default"))));
    // Users in the NFI database should be reassigned to the new NRC partner object
    UserResult nfiUsers = execute(new GetUsers(NFI_DATABASE));
    Optional<UserPermissionDTO> bavon = nfiUsers.getData().stream().filter(u -> u.getEmail().equals("bavon@nrc.org")).findAny();
    Optional<UserPermissionDTO> lisa = nfiUsers.getData().stream().filter(u -> u.getEmail().equals("lisa@solidarites")).findAny();
    // Bavon should stay as NRC
    assertThat(bavon.get().getPartner(), hasProperty("name", equalTo("NRC")));
    // Lisa should be moved to the new Solidarites partner
    assertThat(lisa.get().getPartner(), hasProperty("name", equalTo("Solidarites")));
    // Users in the Health database should be unaffected
    UserResult healthUsers = execute(new GetUsers(HEALTH_DATABASE));
    Optional<UserPermissionDTO> bavonInHealth = healthUsers.getData().stream().filter(u -> u.getEmail().equals("bavon@nrc.org")).findAny();
    assertThat(bavonInHealth.get().getPartner(), hasProperty("name", equalTo("Default")));
    // Sites in the NFI database should be update to point to the new partner
    SiteDTO nfiSite1 = execute(GetSites.byId(1)).getData().get(0);
    SiteDTO nfiSite3 = execute(GetSites.byId(3)).getData().get(0);
    assertThat(nfiSite1.getPartner(), hasProperty("name", equalTo("Solidarites")));
    assertThat(nfiSite3.getPartner(), hasProperty("name", equalTo("NRC")));
    // Sites in the Health database should be unaffected
    SiteDTO healthSite4 = execute(GetSites.byId(4)).getData().get(0);
    assertThat(healthSite4.getPartner(), hasProperty("name", equalTo("Default")));
}
Also used : CommandTestCase2(org.activityinfo.server.command.CommandTestCase2) RunWith(org.junit.runner.RunWith) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) org.activityinfo.legacy.shared.model(org.activityinfo.legacy.shared.model) Matchers(org.hamcrest.Matchers) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test) UserResult(org.activityinfo.legacy.shared.command.result.UserResult) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner) GetUsers(org.activityinfo.legacy.shared.command.GetUsers) Assert.assertThat(org.junit.Assert.assertThat) GetSites(org.activityinfo.legacy.shared.command.GetSites) InjectionSupport(org.activityinfo.fixtures.InjectionSupport) Optional(java.util.Optional) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) UserResult(org.activityinfo.legacy.shared.command.result.UserResult) GetUsers(org.activityinfo.legacy.shared.command.GetUsers) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner) Test(org.junit.Test)

Example 3 with GetUsers

use of org.activityinfo.legacy.shared.command.GetUsers in project activityinfo by bedatadriven.

the class GetUsersTest method testManageAllUsersPermission.

@Test
public void testManageAllUsersPermission() throws CommandException {
    // Bavon from NRC(with manageAllUsers) permission
    setUser(2);
    // execute
    UserResult result = execute(new GetUsers(1));
    // VERIFY that we can get can see the two other users from NRC
    assertThat(result.getTotalLength(), equalTo(2));
}
Also used : UserResult(org.activityinfo.legacy.shared.command.result.UserResult) GetUsers(org.activityinfo.legacy.shared.command.GetUsers) Test(org.junit.Test)

Example 4 with GetUsers

use of org.activityinfo.legacy.shared.command.GetUsers in project activityinfo by bedatadriven.

the class ExportUsersServlet method doGet.

@Override
@Timed(name = "export", kind = "users")
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    int dbId = Integer.valueOf(req.getParameter("dbUsers"));
    UserResult userResult = dispatcher.execute(new GetUsers(dbId));
    DbUserExport export = new DbUserExport(userResult.getData());
    export.createSheet();
    resp.setContentType("application/vnd.ms-excel");
    if (req.getHeader("User-Agent").contains("MSIE")) {
        resp.addHeader("Content-Disposition", "attachment; filename=ActivityInfo.xls");
    } else {
        resp.addHeader("Content-Disposition", "attachment; filename=" + ("ActivityInfo Export " + new Date().toString() + ".xls").replace(" ", "_"));
    }
    OutputStream os = resp.getOutputStream();
    export.getBook().write(os);
}
Also used : OutputStream(java.io.OutputStream) UserResult(org.activityinfo.legacy.shared.command.result.UserResult) GetUsers(org.activityinfo.legacy.shared.command.GetUsers) Date(java.util.Date) Timed(org.activityinfo.server.util.monitoring.Timed)

Example 5 with GetUsers

use of org.activityinfo.legacy.shared.command.GetUsers in project activityinfo by bedatadriven.

the class UpdateUserPermissionsHandlerTest method testAuthorizedCreate.

/**
 * Verifies that a user with the manageUsers permission can add another user to the UserDatabase
 */
@Test
@OnDataSet("/dbunit/schema1.db.xml")
public void testAuthorizedCreate() throws CommandException {
    setUser(2);
    UserPermissionDTO user = new UserPermissionDTO();
    user.setEmail("ralph@lauren.com");
    user.setName("Ralph");
    user.setPartner(new PartnerDTO(1, "NRC"));
    user.setAllowView(true);
    user.setAllowEdit(true);
    UpdateUserPermissions cmd = new UpdateUserPermissions(1, user);
    execute(cmd);
    UserResult result = execute(new GetUsers(1));
    assertThat(result.getTotalLength(), equalTo(1));
    UserPermissionDTO ralph = result.getData().get(0);
    assertThat(ralph.getEmail(), equalTo("ralph@lauren.com"));
    assertThat(ralph.getAllowEdit(), equalTo(true));
    assertThat(ralph.hasFolderLimitation(), equalTo(false));
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) UpdateUserPermissions(org.activityinfo.legacy.shared.command.UpdateUserPermissions) UserResult(org.activityinfo.legacy.shared.command.result.UserResult) GetUsers(org.activityinfo.legacy.shared.command.GetUsers) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

GetUsers (org.activityinfo.legacy.shared.command.GetUsers)8 UserResult (org.activityinfo.legacy.shared.command.result.UserResult)8 Test (org.junit.Test)7 UserPermissionDTO (org.activityinfo.legacy.shared.model.UserPermissionDTO)4 OnDataSet (org.activityinfo.server.database.OnDataSet)4 UpdateUserPermissions (org.activityinfo.legacy.shared.command.UpdateUserPermissions)3 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)3 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 Optional (java.util.Optional)1 InjectionSupport (org.activityinfo.fixtures.InjectionSupport)1 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)1 GetSites (org.activityinfo.legacy.shared.command.GetSites)1 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)1 org.activityinfo.legacy.shared.model (org.activityinfo.legacy.shared.model)1 FolderDTO (org.activityinfo.legacy.shared.model.FolderDTO)1 CommandTestCase2 (org.activityinfo.server.command.CommandTestCase2)1 Timed (org.activityinfo.server.util.monitoring.Timed)1 Matchers (org.hamcrest.Matchers)1 IsEqual.equalTo (org.hamcrest.core.IsEqual.equalTo)1