Search in sources :

Example 11 with PartnerDTO

use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.

the class GetUsersHandler method execute.

@Override
public CommandResult execute(GetUsers cmd, User currentUser) {
    Database db = em.getReference(Database.class, cmd.getDatabaseId());
    UserPermission currentUserPermission = PermissionOracle.using(em).getPermissionByUser(db, currentUser);
    assertAuthorized(currentUserPermission);
    String whereClause = "up.database.id = :dbId and " + "up.user.id <> :currentUserId and " + "up.allowView = true";
    if (!currentUserPermission.isAllowManageAllUsers()) {
        whereClause += " and up.partner.id = " + currentUserPermission.getPartner().getId();
    }
    TypedQuery<UserPermission> query = em.createQuery("select up from UserPermission up where " + whereClause + " " + composeOrderByClause(cmd), UserPermission.class).setParameter("dbId", cmd.getDatabaseId()).setParameter("currentUserId", currentUser.getId());
    List<Folder> folders = em.createQuery("select f from Folder f where f.database.id = :dbId", Folder.class).setParameter("dbId", cmd.getDatabaseId()).getResultList();
    Map<ResourceId, Folder> folderMap = new HashMap<>();
    for (Folder folder : folders) {
        folderMap.put(CuidAdapter.folderId(folder.getId()), folder);
    }
    if (cmd.getOffset() > 0) {
        query.setFirstResult(cmd.getOffset());
    }
    if (cmd.getLimit() > 0) {
        query.setMaxResults(cmd.getLimit());
    }
    List<UserPermissionDTO> models = new ArrayList<>();
    for (UserPermission perm : query.getResultList()) {
        UserPermissionDTO dto = new UserPermissionDTO();
        dto.setEmail(perm.getUser().getEmail());
        dto.setName(perm.getUser().getName());
        dto.setOrganization(perm.getUser().getOrganization());
        dto.setJobtitle(perm.getUser().getJobtitle());
        dto.setAllowDesign(perm.isAllowDesign());
        dto.setAllowView(perm.isAllowView());
        dto.setAllowViewAll(perm.isAllowViewAll());
        dto.setAllowEdit(perm.isAllowEdit());
        dto.setAllowEditAll(perm.isAllowEditAll());
        dto.setAllowManageUsers(perm.isAllowManageUsers());
        dto.setAllowManageAllUsers(perm.isAllowManageAllUsers());
        dto.setPartner(new PartnerDTO(perm.getPartner().getId(), perm.getPartner().getName()));
        dto.setFolderLimitation(!Strings.isNullOrEmpty(perm.getModel()));
        dto.setFolders(folderList(folderMap, perm));
        models.add(dto);
    }
    return new UserResult(models, cmd.getOffset(), queryTotalCount(cmd, currentUser, whereClause));
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Folder(org.activityinfo.server.database.hibernate.entity.Folder) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO) ResourceId(org.activityinfo.model.resource.ResourceId) Database(org.activityinfo.server.database.hibernate.entity.Database) UserResult(org.activityinfo.legacy.shared.command.result.UserResult) UserPermission(org.activityinfo.server.database.hibernate.entity.UserPermission)

Example 12 with PartnerDTO

use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.

the class CloneDatabaseHandler method createDefaultPartner.

private void createDefaultPartner(User user) {
    Preconditions.checkNotNull(targetDb);
    Preconditions.checkState(targetDb.getId() > 0);
    PartnerDTO partner = new PartnerDTO();
    partner.setName("Default");
    new UpdatePartnerHandler(em).execute(new UpdatePartner(targetDb.getId(), partner), user);
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner)

Example 13 with PartnerDTO

use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.

the class SiteDTOs method newSite.

public static SiteDTO newSite() {
    SiteDTO newSite = new SiteDTO();
    newSite.setId(new KeyGenerator().generateInt());
    newSite.setActivityId(1);
    newSite.setLocationId(1);
    newSite.setPartner(new PartnerDTO(1, "Foobar"));
    newSite.setReportingPeriodId(new KeyGenerator().generateInt());
    newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
    newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
    newSite.setIndicatorValue(1, 996.0);
    newSite.setIndicatorValue(2, null);
    newSite.setAttributeValue(1, true);
    newSite.setAttributeValue(2, false);
    newSite.setComments("huba huba");
    newSite.setProject(new ProjectDTO(1, "WoeiProject"));
    return newSite;
}
Also used : ProjectDTO(org.activityinfo.legacy.shared.model.ProjectDTO) PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) GregorianCalendar(java.util.GregorianCalendar) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator)

Example 14 with PartnerDTO

use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.

the class UpdateUserPermissionsHandlerTest method setup.

@Before
public void setup() throws TemplateModelException {
    NRC = new Partner();
    NRC.setId(1);
    NRC.setName("NRC");
    NRC.setFullName("Norwegian Refugee Council");
    db.persist(NRC);
    IRC = new Partner();
    IRC.setId(2);
    IRC.setName("IRC");
    IRC.setFullName("International Rescue Committee");
    db.persist(IRC);
    NRC_DTO = new PartnerDTO(1, "NRC");
    TemplateModule templateModule = new TemplateModule();
    mailer = new MailSenderStub(templateModule.provideConfiguration(Providers.of(Domain.DEFAULT)));
    handler = new UpdateUserPermissionsHandler(db.getDAO(UserDatabaseDAO.class), db.getDAO(PartnerDAO.class), db.getDAO(UserDAO.class), db.getDAO(UserPermissionDAO.class), mailer);
    owner = new User();
    owner.setId(99);
    owner.setName("Alex");
    owner.setEmail("alex@bedatadriven.com");
    db.persist(owner);
    Database udb = new Database(1, "PEAR");
    udb.setOwner(owner);
    db.persist(udb);
}
Also used : MailSenderStub(org.activityinfo.server.mail.MailSenderStub) PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) TemplateModule(org.activityinfo.server.util.TemplateModule) UpdateUserPermissionsHandler(org.activityinfo.server.command.handler.UpdateUserPermissionsHandler) Before(org.junit.Before)

Example 15 with PartnerDTO

use of org.activityinfo.legacy.shared.model.PartnerDTO 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));
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) UpdateUserPermissions(org.activityinfo.legacy.shared.command.UpdateUserPermissions) UserResult(org.activityinfo.legacy.shared.command.result.UserResult) GetUsers(org.activityinfo.legacy.shared.command.GetUsers) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)23 Test (org.junit.Test)6 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)5 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)5 UserResult (org.activityinfo.legacy.shared.command.result.UserResult)4 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)4 UserPermissionDTO (org.activityinfo.legacy.shared.model.UserPermissionDTO)4 OnDataSet (org.activityinfo.server.database.OnDataSet)4 ArrayList (java.util.ArrayList)3 Filter (org.activityinfo.legacy.shared.command.Filter)3 GetPartnersDimension (org.activityinfo.legacy.shared.command.GetPartnersDimension)3 GetUsers (org.activityinfo.legacy.shared.command.GetUsers)3 UpdateUserPermissions (org.activityinfo.legacy.shared.command.UpdateUserPermissions)3 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)3 PartnerResult (org.activityinfo.legacy.shared.command.result.PartnerResult)3 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)2 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)2 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 FormDialogCallback (org.activityinfo.ui.client.page.common.dialog.FormDialogCallback)2