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