Search in sources :

Example 1 with UserPermissionDTO

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();
}
Also used : UserPermissionDTO(org.activityinfo.shared.dto.UserPermissionDTO)

Example 2 with UserPermissionDTO

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;
}
Also used : UserPermissionDTO(org.activityinfo.shared.dto.UserPermissionDTO)

Example 3 with UserPermissionDTO

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);
}
Also used : Query(javax.persistence.Query) ArrayList(java.util.ArrayList) UserResult(org.activityinfo.shared.command.result.UserResult) UserPermissionDTO(org.activityinfo.shared.dto.UserPermissionDTO) UserPermission(org.activityinfo.server.database.hibernate.entity.UserPermission)

Example 4 with UserPermissionDTO

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));
}
Also used : UpdateUserPermissions(org.activityinfo.shared.command.UpdateUserPermissions) UserPermissionDTO(org.activityinfo.shared.dto.UserPermissionDTO) Test(org.junit.Test)

Example 5 with UserPermissionDTO

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());
}
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)

Aggregations

UserPermissionDTO (org.activityinfo.shared.dto.UserPermissionDTO)15 UpdateUserPermissions (org.activityinfo.shared.command.UpdateUserPermissions)9 Test (org.junit.Test)7 UserPermission (org.activityinfo.server.database.hibernate.entity.UserPermission)6 UserResult (org.activityinfo.shared.command.result.UserResult)4 ArrayList (java.util.ArrayList)2 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)2 OnDataSet (org.activityinfo.server.database.OnDataSet)2 GetUsers (org.activityinfo.shared.command.GetUsers)2 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)2 Record (com.extjs.gxt.ui.client.store.Record)1 StoreEvent (com.extjs.gxt.ui.client.store.StoreEvent)1 CheckColumnConfig (com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig)1 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)1 ColumnModel (com.extjs.gxt.ui.client.widget.grid.ColumnModel)1 Query (javax.persistence.Query)1 User (org.activityinfo.server.database.hibernate.entity.User)1 UserDatabase (org.activityinfo.server.database.hibernate.entity.UserDatabase)1 BatchCommand (org.activityinfo.shared.command.BatchCommand)1 BatchResult (org.activityinfo.shared.command.result.BatchResult)1