use of org.activityinfo.legacy.shared.model.UserPermissionDTO 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.model.UserPermissionDTO in project activityinfo by bedatadriven.
the class UpdateUserPermissionsHandlerTest method ownerCanAddUser.
@Test
public void ownerCanAddUser() throws Exception {
UserPermissionDTO user = new UserPermissionDTO();
user.setEmail("other@foobar");
user.setName("Foo Bar");
user.setPartner(NRC_DTO);
user.setAllowView(true);
UpdateUserPermissions cmd = new UpdateUserPermissions(1, user);
handler.execute(cmd, owner);
assertThat(mailer.sentMails.size(), equalTo(1));
}
use of org.activityinfo.legacy.shared.model.UserPermissionDTO in project activityinfo by bedatadriven.
the class UpdateUserPermissionsHandlerTest method testFailingVerifyAuthorityForView.
@Test(expected = IllegalAccessCommandException.class)
public void testFailingVerifyAuthorityForView() throws IllegalAccessCommandException {
UserPermission executingUserPermissions = new UserPermission();
executingUserPermissions.setPartner(IRC);
executingUserPermissions.setAllowManageUsers(true);
UserPermissionDTO dto = new UserPermissionDTO();
dto.setPartner(NRC_DTO);
dto.setAllowView(true);
dto.setAllowEdit(true);
UpdateUserPermissions cmd = new UpdateUserPermissions(1, dto);
UpdateUserPermissionsHandler.verifyAuthority(cmd, executingUserPermissions);
}
use of org.activityinfo.legacy.shared.model.UserPermissionDTO in project activityinfo by bedatadriven.
the class UpdateUserPermissionsHandlerTest method testVerifyAuthorityForViewPermissions.
/**
* Asserts that someone with ManageUsersPermission will be permitted to
* grant some one edit rights.
*/
@Test
public void testVerifyAuthorityForViewPermissions() throws IllegalAccessCommandException {
UserPermission executingUserPermissions = new UserPermission();
executingUserPermissions.setPartner(NRC);
executingUserPermissions.setAllowManageUsers(true);
UserPermissionDTO dto = new UserPermissionDTO();
dto.setPartner(NRC_DTO);
dto.setAllowView(true);
UpdateUserPermissions cmd = new UpdateUserPermissions(1, dto);
UpdateUserPermissionsHandler.verifyAuthority(cmd, executingUserPermissions);
}
use of org.activityinfo.legacy.shared.model.UserPermissionDTO in project activityinfo by bedatadriven.
the class UpdateUserPermissionsHandler method execute.
@Override
public CommandResult execute(UpdateUserPermissions cmd, User executingUser) {
LOGGER.info("UpdateUserPermissions: " + cmd);
Database database = databaseDAO.findById(cmd.getDatabaseId());
UserPermissionDTO dto = cmd.getModel();
/*
* First check that the current user has permission to add users to to
* the queries
*/
boolean isOwner = executingUser.getId() == database.getOwner().getId();
UserPermission executingUserPermission = queryUserPermission(executingUser, database);
LOGGER.info("executingUserPermission: isOwner: " + isOwner + ", executingUserPermissions: " + cmd);
if (!isOwner) {
verifyAuthority(cmd, executingUserPermission);
}
/* Database owner cannot be added */
if (database.getOwner().getEmail().equalsIgnoreCase(cmd.getModel().getEmail())) {
throw new UserExistsException();
}
User user = null;
if (userDAO.doesUserExist(dto.getEmail())) {
user = userDAO.findUserByEmail(dto.getEmail());
}
if (user == null) {
user = createNewUser(executingUser, dto);
}
/*
* Does the permission record exist ?
*/
UserPermission perm = queryUserPermission(user, database);
if (perm == null) {
perm = new UserPermission(database, user);
doUpdate(perm, dto, isOwner, executingUserPermission);
permDAO.persist(perm);
} else {
// If the user is intending to add a new user, verify that this user doesn't already exist
if (cmd.isNewUser() && perm.isAllowView()) {
throw new UserExistsException();
}
doUpdate(perm, dto, isOwner, executingUserPermission);
}
return null;
}
Aggregations