use of org.activityinfo.shared.dto.UserPermissionDTO in project activityinfo by bedatadriven.
the class MailingListDialog method createMailingList.
private String createMailingList(List<UserPermissionDTO> users) {
StringBuilder emails = new StringBuilder();
for (UserPermissionDTO dto : users) {
emails.append("\"" + dto.getName() + "\"");
emails.append(" ");
emails.append("<" + dto.getEmail() + ">,");
emails.append(" ");
}
return emails.toString();
}
use of org.activityinfo.shared.dto.UserPermissionDTO in project activityinfo by bedatadriven.
the class UserForm method getUser.
public UserPermissionDTO getUser() {
UserPermissionDTO user = new UserPermissionDTO();
user.setEmail(emailField.getValue());
user.setName(nameField.getValue());
user.setPartner(partnerCombo.getValue());
return user;
}
use of org.activityinfo.shared.dto.UserPermissionDTO in project activityinfo by bedatadriven.
the class GetUsersHandler method execute.
@Override
public CommandResult execute(GetUsers cmd, User currentUser) throws CommandException {
String orderByClause = "";
if (cmd.getSortInfo().getSortDir() != Style.SortDir.NONE) {
String dir = cmd.getSortInfo().getSortDir() == Style.SortDir.ASC ? "asc" : "desc";
String property = null;
String field = cmd.getSortInfo().getSortField();
if ("name".equals(field)) {
property = "up.user.name";
} else if ("email".equals(field)) {
property = "up.user.email";
} else if ("partner".equals(field)) {
property = "up.partner.name";
} else if (field != null && field.startsWith("allow")) {
property = "up." + field;
}
if (property != null) {
orderByClause = " order by " + property + " " + dir;
}
}
Query query = em.createQuery("select up from UserPermission up where " + "up.database.id = :dbId and " + "up.user.id <> :currentUserId " + orderByClause).setParameter("dbId", cmd.getDatabaseId()).setParameter("currentUserId", currentUser.getId());
if (cmd.getOffset() > 0) {
query.setFirstResult(cmd.getOffset());
}
if (cmd.getLimit() > 0) {
query.setMaxResults(cmd.getLimit());
}
List<UserPermission> perms = query.getResultList();
List<UserPermissionDTO> models = new ArrayList<UserPermissionDTO>();
for (UserPermission perm : perms) {
models.add(mapper.map(perm, UserPermissionDTO.class));
}
int totalCount = ((Number) em.createQuery("select count(up) from UserPermission up where " + "up.database.id = :dbId and " + "up.user.id <> :currentUserId ").setParameter("dbId", cmd.getDatabaseId()).setParameter("currentUserId", currentUser.getId()).getSingleResult()).intValue();
return new UserResult(models, cmd.getOffset(), totalCount);
}
use of org.activityinfo.shared.dto.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.shared.dto.UserPermissionDTO 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());
}
Aggregations