Search in sources :

Example 1 with GetUsers

use of org.activityinfo.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
    Assert.assertEquals("number of results", 2, result.getTotalLength());
}
Also used : UserResult(org.activityinfo.shared.command.result.UserResult) GetUsers(org.activityinfo.shared.command.GetUsers) Test(org.junit.Test)

Example 2 with GetUsers

use of org.activityinfo.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
 *
 * @throws CommandException
 */
@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);
    Assert.assertEquals("bavon@nrcdrc.org", reUser.getEmail());
    Assert.assertTrue("design rights", user.getAllowDesign());
}
Also used : PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) UpdateUserPermissions(org.activityinfo.shared.command.UpdateUserPermissions) UserResult(org.activityinfo.shared.command.result.UserResult) GetUsers(org.activityinfo.shared.command.GetUsers) UserPermissionDTO(org.activityinfo.shared.dto.UserPermissionDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 3 with GetUsers

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

the class ExportUsersServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    int dbId = Integer.valueOf(req.getParameter("dbUsers"));
    try {
        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").indexOf("MSIE") != -1) {
            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);
    } catch (Exception e) {
        e.printStackTrace();
        resp.setStatus(500);
    }
}
Also used : OutputStream(java.io.OutputStream) UserResult(org.activityinfo.shared.command.result.UserResult) GetUsers(org.activityinfo.shared.command.GetUsers) Date(java.util.Date) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 4 with GetUsers

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

the class GetUsersTest method testUnsorted.

@Test
public void testUnsorted() throws CommandException {
    setUser(DATABASE_OWNER);
    GetUsers cmd = new GetUsers(1);
    UserResult result = execute(cmd);
    Assert.assertEquals(3, result.getData().size());
}
Also used : UserResult(org.activityinfo.shared.command.result.UserResult) GetUsers(org.activityinfo.shared.command.GetUsers) Test(org.junit.Test)

Example 5 with GetUsers

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

the class GetUsersTest method testManageUsersPermission.

/**
 * Verify that users with ManageUsers permission can get a list of users
 * within their organisation
 */
@Test
public void testManageUsersPermission() throws CommandException {
    // populate with a known state and authenticate as user 3, who
    // has ManageUser permissions for Solidarites
    // Lisa from Solidarites
    setUser(3);
    // execute
    UserResult result = execute(new GetUsers(1));
    // VERIFY that we have 1 result:
    // - the one other solidarites user
    Assert.assertEquals("number of results", 1, result.getTotalLength());
    Assert.assertEquals("user name", "Marlene", result.getData().get(0).getName());
}
Also used : UserResult(org.activityinfo.shared.command.result.UserResult) GetUsers(org.activityinfo.shared.command.GetUsers) Test(org.junit.Test)

Aggregations

GetUsers (org.activityinfo.shared.command.GetUsers)6 UserResult (org.activityinfo.shared.command.result.UserResult)6 Test (org.junit.Test)5 OnDataSet (org.activityinfo.server.database.OnDataSet)2 UpdateUserPermissions (org.activityinfo.shared.command.UpdateUserPermissions)2 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)2 UserPermissionDTO (org.activityinfo.shared.dto.UserPermissionDTO)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 ServletException (javax.servlet.ServletException)1