Search in sources :

Example 1 with Sharing

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());
}
Also used : Sharing(org.hisp.dhis.user.sharing.Sharing) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) Test(org.junit.jupiter.api.Test)

Example 2 with Sharing

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());
}
Also used : Sharing(org.hisp.dhis.user.sharing.Sharing) UserAccess(org.hisp.dhis.user.sharing.UserAccess) Test(org.junit.jupiter.api.Test)

Example 3 with Sharing

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());
}
Also used : Sharing(org.hisp.dhis.user.sharing.Sharing) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) Test(org.junit.jupiter.api.Test)

Example 4 with Sharing

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);
}
Also used : Field(org.hisp.dhis.gist.GistQuery.Field) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) Filter(org.hisp.dhis.gist.GistQuery.Filter) Sharing(org.hisp.dhis.user.sharing.Sharing) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject)

Example 5 with Sharing

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);
}
Also used : Category(org.hisp.dhis.category.Category) User(org.hisp.dhis.user.User) Sharing(org.hisp.dhis.user.sharing.Sharing)

Aggregations

Sharing (org.hisp.dhis.user.sharing.Sharing)27 Test (org.junit.jupiter.api.Test)21 UserAccess (org.hisp.dhis.user.sharing.UserAccess)12 User (org.hisp.dhis.user.User)10 UserGroupAccess (org.hisp.dhis.user.sharing.UserGroupAccess)8 DataElement (org.hisp.dhis.dataelement.DataElement)7 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)6 Dashboard (org.hisp.dhis.dashboard.Dashboard)5 HashMap (java.util.HashMap)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 List (java.util.List)3 UserGroup (org.hisp.dhis.user.UserGroup)3 Date (java.util.Date)2 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)2 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)2 TypeReport (org.hisp.dhis.feedback.TypeReport)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 Period (org.hisp.dhis.period.Period)2 Program (org.hisp.dhis.program.Program)2 PreparedStatement (java.sql.PreparedStatement)1