use of org.hisp.dhis.user.sharing.Sharing in project dhis2-core by dhis2.
the class SharingTest method setDtoUserGroupAccessClearsExisting.
@Test
void setDtoUserGroupAccessClearsExisting() {
Sharing actual = new Sharing();
UserGroup group1 = new UserGroup();
group1.setUid("id");
actual.setDtoUserGroupAccesses(singleton(new org.hisp.dhis.user.UserGroupAccess(group1, "rw------")));
UserGroup group2 = new UserGroup();
group2.setUid("uid");
actual.setDtoUserGroupAccesses(singleton(new org.hisp.dhis.user.UserGroupAccess(group2, "r-------")));
assertEquals(1, actual.getUserGroups().size());
UserGroupAccess userAccess = actual.getUserGroups().values().iterator().next();
assertEquals("r-------", userAccess.getAccess());
assertEquals("uid", userAccess.getId());
}
use of org.hisp.dhis.user.sharing.Sharing in project dhis2-core by dhis2.
the class SharingTest method withAccessAppliesToUsers.
@Test
void withAccessAppliesToUsers() {
Sharing original = new Sharing();
original.setUsers(singletonMap("key", new UserAccess("abcd1234", "uid")));
Sharing actual = original.withAccess(Sharing::copyMetadataToData);
Map<String, UserAccess> users = actual.getUsers();
assertEquals(1, users.size());
assertEquals("key", users.keySet().iterator().next());
assertEquals("abab1234", users.values().iterator().next().getAccess());
assertEquals("uid", users.values().iterator().next().getId());
}
use of org.hisp.dhis.user.sharing.Sharing in project dhis2-core by dhis2.
the class SharingTest method setUserGroupAccessClearsExisting.
@Test
void setUserGroupAccessClearsExisting() {
Sharing actual = new Sharing();
actual.setUserGroupAccess(singleton(new UserGroupAccess("rw------", "id")));
actual.setUserGroupAccess(singleton(new UserGroupAccess("r-------", "uid")));
assertEquals(1, actual.getUserGroups().size());
UserGroupAccess userAccess = actual.getUserGroups().values().iterator().next();
assertEquals("r-------", userAccess.getAccess());
assertEquals("uid", userAccess.getId());
}
use of org.hisp.dhis.user.sharing.Sharing in project dhis2-core by dhis2.
the class DefaultGistAccessControl method canReadObject.
@Override
public boolean canReadObject(Class<? extends PrimaryKeyObject> type, String uid) {
if (!IdentifiableObject.class.isAssignableFrom(type)) {
return true;
}
@SuppressWarnings("unchecked") Class<? extends IdentifiableObject> ioType = (Class<? extends IdentifiableObject>) type;
if (!aclService.isClassShareable(ioType)) {
return aclService.canRead(currentUser, ioType);
}
List<?> res = gistService.gist(GistQuery.builder().elementType(ioType).autoType(GistAutoType.M).fields(singletonList(new Field("sharing", Transform.NONE))).filters(singletonList(new Filter("id", Comparison.EQ, uid))).build());
Sharing sharing = res.isEmpty() ? new Sharing() : (Sharing) res.get(0);
BaseIdentifiableObject object = new BaseIdentifiableObject();
object.setSharing(sharing);
return aclService.canRead(currentUser, object, ioType);
}
use of org.hisp.dhis.user.sharing.Sharing in project dhis2-core by dhis2.
the class AnalyticsSecurityManagerTest method setUpTest.
@Override
public void setUpTest() {
userService = _userService;
createAndInjectAdminUser();
coA = createCategoryOption('A');
coB = createCategoryOption('B');
coNotReadable = createCategoryOption('N');
categoryService.addCategoryOption(coA);
categoryService.addCategoryOption(coB);
long nonReadableCatOption = categoryService.addCategoryOption(coNotReadable);
coNotReadable = categoryService.getCategoryOption(nonReadableCatOption);
Sharing sharing = Sharing.builder().owner("cannotRead").publicAccess(AccessStringHelper.DEFAULT).build();
coNotReadable.setSharing(sharing);
coNotReadable.setPublicAccess(AccessStringHelper.DEFAULT);
caA = createCategory('A', coA, coB, coNotReadable);
categoryService.addCategory(caA);
Set<Category> catDimensionConstraints = Sets.newHashSet(caA);
deA = createDataElement('A');
dataElementService.addDataElement(deA);
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B', ouA);
ouC = createOrganisationUnit('C', ouB);
ouD = createOrganisationUnit('D', ouC);
ouE = createOrganisationUnit('E', ouC);
ouF = createOrganisationUnit('F', ouA);
organisationUnitService.addOrganisationUnit(ouA);
organisationUnitService.addOrganisationUnit(ouB);
organisationUnitService.addOrganisationUnit(ouC);
organisationUnitService.addOrganisationUnit(ouD);
organisationUnitService.addOrganisationUnit(ouE);
userOrgUnits = Sets.newHashSet(ouB, ouC);
User user = createUser("A", "F_VIEW_EVENT_ANALYTICS");
user.setOrganisationUnits(userOrgUnits);
user.setDataViewOrganisationUnits(userOrgUnits);
user.setDataViewMaxOrganisationUnitLevel(3);
user.setCatDimensionConstraints(catDimensionConstraints);
userService.addUser(user);
injectSecurityContext(user);
}
Aggregations