Search in sources :

Example 6 with Dashboard

use of org.hisp.dhis.dashboard.Dashboard in project dhis2-core by dhis2.

the class AclServiceTest method testUserCanUpdateDashboardSharedWithUserGroup.

@Test
public void testUserCanUpdateDashboardSharedWithUserGroup() {
    User user1 = createUser('A');
    User user2 = createUser('B');
    manager.save(user1);
    manager.save(user2);
    UserGroup userGroup = createUserGroup('A', Sets.newHashSet(user1, user2));
    manager.save(userGroup);
    Dashboard dashboard = new Dashboard("Dashboard");
    dashboard.setUser(user1);
    manager.save(dashboard);
    UserGroupAccess userGroupAccess = new UserGroupAccess(userGroup, AccessStringHelper.READ);
    dashboard.getUserGroupAccesses().add(userGroupAccess);
    manager.update(dashboard);
    assertTrue(aclService.canRead(user1, dashboard));
    assertTrue(aclService.canUpdate(user1, dashboard));
    assertTrue(aclService.canDelete(user1, dashboard));
    assertTrue(aclService.canManage(user1, dashboard));
    Access access = aclService.getAccess(dashboard, user2);
    assertTrue(access.isRead());
    assertFalse(access.isUpdate());
    assertFalse(access.isDelete());
    assertFalse(access.isManage());
    assertTrue(aclService.canRead(user2, dashboard));
    assertFalse(aclService.canUpdate(user2, dashboard));
    assertFalse(aclService.canDelete(user2, dashboard));
    assertFalse(aclService.canManage(user2, dashboard));
}
Also used : User(org.hisp.dhis.user.User) UserGroupAccess(org.hisp.dhis.user.UserGroupAccess) Dashboard(org.hisp.dhis.dashboard.Dashboard) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.UserGroupAccess) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with Dashboard

use of org.hisp.dhis.dashboard.Dashboard in project dhis2-core by dhis2.

the class AclServiceTest method testBlockDashboardPublic.

@Test
public void testBlockDashboardPublic() {
    User user1 = createUser("user1");
    manager.save(user1);
    Dashboard dashboard = new Dashboard("Dashboard");
    dashboard.setPublicAccess(AccessStringHelper.DEFAULT);
    dashboard.setUser(user1);
    aclService.canWrite(user1, dashboard);
    manager.save(dashboard);
    dashboard.setPublicAccess(AccessStringHelper.READ_WRITE);
    assertFalse(aclService.canUpdate(user1, dashboard));
    manager.update(dashboard);
}
Also used : User(org.hisp.dhis.user.User) Dashboard(org.hisp.dhis.dashboard.Dashboard) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 8 with Dashboard

use of org.hisp.dhis.dashboard.Dashboard in project dhis2-core by dhis2.

the class HibernateDashboardItemStore method getDashboardFromDashboardItem.

@Override
public Dashboard getDashboardFromDashboardItem(DashboardItem dashboardItem) {
    Query query = getQuery("from Dashboard d where :item in elements(d.items)");
    query.setEntity("item", dashboardItem);
    return (Dashboard) query.uniqueResult();
}
Also used : Query(org.hibernate.Query) Dashboard(org.hisp.dhis.dashboard.Dashboard)

Example 9 with Dashboard

use of org.hisp.dhis.dashboard.Dashboard in project dhis2-core by dhis2.

the class AclServiceTest method testCanUpdatePrivateDashboard.

@Test
public void testCanUpdatePrivateDashboard() {
    User user = createAdminUser("F_DATAELEMENT_PRIVATE_ADD");
    Dashboard dashboard = new Dashboard("Dashboard");
    dashboard.setAutoFields();
    dashboard.setUser(user);
    dashboard.setPublicAccess(AccessStringHelper.DEFAULT);
    assertTrue(aclService.canUpdate(user, dashboard));
}
Also used : User(org.hisp.dhis.user.User) Dashboard(org.hisp.dhis.dashboard.Dashboard) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 10 with Dashboard

use of org.hisp.dhis.dashboard.Dashboard in project dhis2-core by dhis2.

the class DashboardController method deleteItemContent.

@RequestMapping(value = "/{dashboardUid}/items/{itemUid}/content/{contentUid}", method = RequestMethod.DELETE)
public void deleteItemContent(HttpServletResponse response, HttpServletRequest request, @PathVariable String dashboardUid, @PathVariable String itemUid, @PathVariable String contentUid) throws WebMessageException {
    Dashboard dashboard = dashboardService.getDashboard(dashboardUid);
    if (dashboard == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Dashboard does not exist: " + dashboardUid));
    }
    if (!aclService.canUpdate(currentUserService.getCurrentUser(), dashboard)) {
        throw new UpdateAccessDeniedException("You don't have the proper permissions to update this dashboard.");
    }
    DashboardItem item = dashboard.getItemByUid(itemUid);
    if (item == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Dashboard item does not exist: " + dashboardUid));
    }
    if (item.removeItemContent(contentUid)) {
        if (item.getContentCount() == 0 && dashboard.getItems().remove(item)) {
            // Delete if empty                
            dashboardService.deleteDashboardItem(item);
        }
        dashboardService.updateDashboard(dashboard);
        webMessageService.send(WebMessageUtils.ok("Dashboard item content removed"), response, request);
    }
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) UpdateAccessDeniedException(org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException) Dashboard(org.hisp.dhis.dashboard.Dashboard) DashboardItem(org.hisp.dhis.dashboard.DashboardItem) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Dashboard (org.hisp.dhis.dashboard.Dashboard)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)7 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)7 DashboardItem (org.hisp.dhis.dashboard.DashboardItem)6 User (org.hisp.dhis.user.User)6 DhisSpringTest (org.hisp.dhis.DhisSpringTest)5 Test (org.junit.Test)5 Query (org.hibernate.Query)1 Chart (org.hisp.dhis.chart.Chart)1 Document (org.hisp.dhis.document.Document)1 EventChart (org.hisp.dhis.eventchart.EventChart)1 EventReport (org.hisp.dhis.eventreport.EventReport)1 Map (org.hisp.dhis.mapping.Map)1 UserGroup (org.hisp.dhis.user.UserGroup)1 UserGroupAccess (org.hisp.dhis.user.UserGroupAccess)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1