use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class IdentifiableObjectManagerTest method testRemoveUserGroupFromSharing.
@Test
void testRemoveUserGroupFromSharing() {
User userA = createUser('A');
userService.addUser(userA);
UserGroup userGroupA = createUserGroup('A', Sets.newHashSet(userA));
identifiableObjectManager.save(userGroupA);
String userGroupUid = userGroupA.getUid();
DataElement de = createDataElement('A');
Sharing sharing = new Sharing();
sharing.setUserGroupAccess(singleton(new UserGroupAccess("rw------", userGroupA.getUid())));
de.setSharing(sharing);
identifiableObjectManager.save(de, false);
de = identifiableObjectManager.get(de.getUid());
assertEquals(1, de.getSharing().getUserGroups().size());
identifiableObjectManager.delete(userGroupA);
identifiableObjectManager.removeUserGroupFromSharing(userGroupUid);
dbmsManager.clearSession();
de = identifiableObjectManager.get(de.getUid());
assertEquals(0, de.getSharing().getUserGroups().size());
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStoreTest method testMetadataRead.
/**
* Test Metadata Read access User and UserGroups mapping User1 | User2 |
* User3 | User 4 Group1 x | | | Group2 X | | | X
*
* DataElementA access defined for Users and UserGroups User1 | User2 |
* User3 | UserGroup1 | UserGroup2 Can access DEA | X | | X |
*/
@Test
void testMetadataRead() {
User admin = createAndInjectAdminUser();
User user1 = new User();
user1.setAutoFields();
User user2 = new User();
user2.setAutoFields();
User user3 = new User();
user3.setAutoFields();
User user4 = new User();
user4.setAutoFields();
UserGroup userGroup1 = new UserGroup();
userGroup1.setAutoFields();
UserGroup userGroup2 = new UserGroup();
userGroup2.setAutoFields();
user1.getGroups().add(userGroup1);
user1.getGroups().add(userGroup2);
user4.getGroups().add(userGroup2);
Map<String, UserAccess> userSharing = new HashMap<>();
userSharing.put(user1.getUid(), new UserAccess(user1, AccessStringHelper.DEFAULT));
userSharing.put(user2.getUid(), new UserAccess(user2, AccessStringHelper.READ));
userSharing.put(user3.getUid(), new UserAccess(user3, AccessStringHelper.DEFAULT));
userSharing.put(user4.getUid(), new UserAccess(user4, AccessStringHelper.DEFAULT));
Map<String, UserGroupAccess> userGroupSharing = new HashMap<>();
userGroupSharing.put(userGroup1.getUid(), new UserGroupAccess(userGroup1, AccessStringHelper.READ_WRITE));
userGroupSharing.put(userGroup2.getUid(), new UserGroupAccess(userGroup2, AccessStringHelper.DEFAULT));
DataElement dataElement = createDataElement('A');
String dataElementUid = "deabcdefghA";
dataElement.setUid(dataElementUid);
dataElement.setCreatedBy(admin);
Sharing sharing = Sharing.builder().external(false).publicAccess(AccessStringHelper.DEFAULT).owner("testOwner").userGroups(userGroupSharing).users(userSharing).build();
dataElement.setSharing(sharing);
dataElementStore.save(dataElement, false);
dataElement = dataElementStore.getByUidNoAcl(dataElementUid);
assertNotNull(dataElement.getSharing());
assertEquals(2, dataElement.getSharing().getUserGroups().size());
assertEquals(4, dataElement.getSharing().getUsers().size());
// User1 can't access but it belong to UserGroup1 which has access
assertNotNull(dataElementStore.getDataElement(dataElement.getUid(), user1));
// User2 has access to DEA
assertNotNull(dataElementStore.getDataElement(dataElement.getUid(), user2));
// User3 doesn't have access and also does't belong to any groups
assertNull(dataElementStore.getDataElement(dataElement.getUid(), user3));
// User4 doesn't have access and it belong to UserGroup2 which also
// doesn't have access
assertNull(dataElementStore.getDataElement(dataElement.getUid(), user4));
}
use of org.hisp.dhis.user.UserGroup 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.UserGroup in project dhis2-core by dhis2.
the class DataApprovalAuditServiceTest method getUserGroup.
private UserGroup getUserGroup(String userGroupName, Set<User> users) {
UserGroup userGroup = new UserGroup();
userGroup.setAutoFields();
userGroup.setName(userGroupName);
userGroup.setMembers(users);
userGroupService.addUserGroup(userGroup);
return userGroup;
}
use of org.hisp.dhis.user.UserGroup 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));
}
Aggregations