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