use of org.hisp.dhis.user.sharing.UserGroupAccess in project dhis2-core by dhis2.
the class DataApprovalAuditServiceTest method setPrivateAccess.
private void setPrivateAccess(BaseIdentifiableObject object, UserGroup... userGroups) {
object.getSharing().setPublicAccess(ACCESS_NONE);
// Needed for sharing to work
object.setOwner(userZ.getUid());
object.getSharing().setOwner(userZ);
for (UserGroup group : userGroups) {
object.getSharing().addUserGroupAccess(new UserGroupAccess(group, ACCESS_READ));
}
identifiableObjectManager.updateNoAcl(object);
}
use of org.hisp.dhis.user.sharing.UserGroupAccess in project dhis2-core by dhis2.
the class AclServiceTest method testUserCanUpdateDashboardSharedWithUserGroup.
@Test
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);
user1.getGroups().add(userGroup);
user2.getGroups().add(userGroup);
Dashboard dashboard = new Dashboard("Dashboard");
dashboard.setCreatedBy(user1);
dashboard.getSharing().setOwner(user1);
manager.save(dashboard);
UserGroupAccess userGroupAccess = new UserGroupAccess(userGroup, AccessStringHelper.READ);
dashboard.getSharing().addUserGroupAccess(userGroupAccess);
manager.save(dashboard, false);
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.user.sharing.UserGroupAccess in project dhis2-core by dhis2.
the class AclServiceTest method testDataElementSharingPrivateRW.
@Test
void testDataElementSharingPrivateRW() {
User user1 = createUser("user1A9", "F_DATAELEMENT_PRIVATE_ADD");
User user2 = createUser("user2A9", "F_DATAELEMENT_PRIVATE_ADD");
DataElement dataElement = createDataElement('A');
dataElement.setCreatedBy(user1);
dataElement.getSharing().setOwner(user1);
manager.save(dataElement);
assertFalse(aclService.canUpdate(user2, dataElement));
assertEquals(AccessStringHelper.DEFAULT, dataElement.getPublicAccess());
UserGroup userGroup = createUserGroup('A', new HashSet<>());
userGroup.getMembers().add(user1);
userGroup.getMembers().add(user2);
manager.save(userGroup);
user1.getGroups().add(userGroup);
user2.getGroups().add(userGroup);
dataElement.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, "rw------"));
manager.update(dataElement);
assertTrue(aclService.canUpdate(user2, dataElement));
}
use of org.hisp.dhis.user.sharing.UserGroupAccess in project dhis2-core by dhis2.
the class AclServiceTest method testCategoryOptionSharingPrivateRW.
@Test
void testCategoryOptionSharingPrivateRW() {
User user1 = createUser("user11", "F_CATEGORY_OPTION_PRIVATE_ADD");
User user2 = createUser("user22", "F_CATEGORY_OPTION_PRIVATE_ADD");
CategoryOption categoryOption = createCategoryOption('A');
categoryOption.setCreatedBy(user1);
categoryOption.getSharing().setOwner(user1);
manager.save(categoryOption);
assertFalse(aclService.canUpdate(user2, categoryOption));
assertEquals(AccessStringHelper.DEFAULT, categoryOption.getPublicAccess());
UserGroup userGroup = createUserGroup('A', new HashSet<>());
userGroup.getMembers().add(user1);
userGroup.getMembers().add(user2);
manager.save(userGroup);
user2.getGroups().add(userGroup);
user1.getGroups().add(userGroup);
categoryOption.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, "rw------"));
manager.update(categoryOption);
assertTrue(aclService.canUpdate(user2, categoryOption));
}
use of org.hisp.dhis.user.sharing.UserGroupAccess in project dhis2-core by dhis2.
the class AclServiceTest method testUpdatePrivateDataElementSharedThroughGroup.
@Test
void testUpdatePrivateDataElementSharedThroughGroup() {
User user1 = createUser("user1A", "F_DATAELEMENT_PRIVATE_ADD");
User user2 = createUser("user2A", "F_DATAELEMENT_PRIVATE_ADD");
manager.save(user1);
manager.save(user2);
UserGroup userGroup = createUserGroup('A', Sets.newHashSet(user1, user2));
manager.save(userGroup);
user1.getGroups().add(userGroup);
user2.getGroups().add(userGroup);
DataElement dataElement = createDataElement('A');
dataElement.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
dataElement.setCreatedBy(user1);
dataElement.getSharing().setOwner(user1);
UserGroupAccess userGroupAccess = new UserGroupAccess(userGroup, AccessStringHelper.READ_WRITE);
dataElement.getSharing().addUserGroupAccess(userGroupAccess);
manager.save(dataElement, false);
assertTrue(aclService.canRead(user1, dataElement));
assertTrue(aclService.canUpdate(user1, dataElement));
assertFalse(aclService.canDelete(user1, dataElement));
assertTrue(aclService.canManage(user1, dataElement));
Access access = aclService.getAccess(dataElement, user2);
assertTrue(access.isRead());
assertTrue(access.isWrite());
assertTrue(access.isUpdate());
assertFalse(access.isDelete());
assertTrue(access.isManage());
assertTrue(aclService.canRead(user2, dataElement));
assertTrue(aclService.canWrite(user2, dataElement));
assertTrue(aclService.canUpdate(user2, dataElement));
assertFalse(aclService.canDelete(user2, dataElement));
assertTrue(aclService.canManage(user2, dataElement));
}
Aggregations