Search in sources :

Example 1 with EventContext

use of org.hisp.dhis.dxf2.events.event.EventContext in project dhis2-core by dhis2.

the class DefaultTrackerOwnershipManager method hasAccessUsingContext.

@Override
@Transactional(readOnly = true)
public boolean hasAccessUsingContext(User user, String trackedEntityInstanceUid, String programUid, EventContext eventContext) {
    Program program = eventContext.getProgramsByUid().get(programUid);
    if (canSkipOwnershipCheck(user, program)) {
        return true;
    }
    EventContext.TrackedEntityOuInfo trackedEntityOuInfo = eventContext.getTrackedEntityOuInfoByUid().get(trackedEntityInstanceUid);
    if (trackedEntityOuInfo == null) {
        return true;
    }
    OrganisationUnit ou = Optional.ofNullable(eventContext.getOrgUnitByTeiUidAndProgramUidPairs().get(Pair.of(trackedEntityInstanceUid, programUid))).map(organisationUnitUid -> eventContext.getOrgUnitsByUid().get(organisationUnitUid)).orElseGet(() -> organisationUnitService.getOrganisationUnit(trackedEntityOuInfo.getOrgUnitId()));
    if (program.isOpen() || program.isAudited()) {
        return organisationUnitService.isInUserSearchHierarchyCached(user, ou);
    } else {
        return organisationUnitService.isInUserHierarchyCached(user, ou) || hasTemporaryAccess(trackedEntityOuInfo, program, user);
    }
}
Also used : EventContext(org.hisp.dhis.dxf2.events.event.EventContext) LongSupplier(java.util.function.LongSupplier) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) EventContext(org.hisp.dhis.dxf2.events.event.EventContext) ProgramTempOwner(org.hisp.dhis.program.ProgramTempOwner) Supplier(java.util.function.Supplier) Program(org.hisp.dhis.program.Program) ProgramOwnershipHistoryService(org.hisp.dhis.program.ProgramOwnershipHistoryService) Pair(org.apache.commons.lang3.tuple.Pair) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) Service(org.springframework.stereotype.Service) User(org.hisp.dhis.user.User) ProgramTempOwnerService(org.hisp.dhis.program.ProgramTempOwnerService) CHANGELOG_TRACKER(org.hisp.dhis.external.conf.ConfigurationKey.CHANGELOG_TRACKER) ProgramOwnershipHistory(org.hisp.dhis.program.ProgramOwnershipHistory) DhisConfigurationProvider(org.hisp.dhis.external.conf.DhisConfigurationProvider) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ProgramTempOwnershipAuditService(org.hisp.dhis.program.ProgramTempOwnershipAuditService) AccessDeniedException(org.springframework.security.access.AccessDeniedException) CacheProvider(org.hisp.dhis.cache.CacheProvider) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Slf4j(lombok.extern.slf4j.Slf4j) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Environment(org.springframework.core.env.Environment) Cache(org.hisp.dhis.cache.Cache) ProgramType(org.hisp.dhis.program.ProgramType) Optional(java.util.Optional) Hibernate(org.hibernate.Hibernate) ProgramTempOwnershipAudit(org.hisp.dhis.program.ProgramTempOwnershipAudit) Transactional(org.springframework.transaction.annotation.Transactional) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with EventContext

use of org.hisp.dhis.dxf2.events.event.EventContext in project dhis2-core by dhis2.

the class AbstractEventService method getEventRows.

@Transactional(readOnly = true)
@Override
public EventRows getEventRows(EventSearchParams params) {
    User user = currentUserService.getCurrentUser();
    List<OrganisationUnit> organisationUnits = getOrganisationUnits(params, user);
    EventRows eventRows = new EventRows();
    List<EventRow> eventRowList = eventStore.getEventRows(params, organisationUnits);
    EventContext eventContext = eventServiceContextBuilder.build(eventRowList, user);
    for (EventRow eventRow : eventRowList) {
        if (trackerOwnershipAccessManager.hasAccessUsingContext(user, eventRow.getTrackedEntityInstance(), eventRow.getProgram(), eventContext)) {
            eventRows.getEventRows().add(eventRow);
        }
    }
    return eventRows;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) EventRows(org.hisp.dhis.dxf2.events.report.EventRows) EventRow(org.hisp.dhis.dxf2.events.report.EventRow) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 User (org.hisp.dhis.user.User)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Optional (java.util.Optional)1 LongSupplier (java.util.function.LongSupplier)1 Supplier (java.util.function.Supplier)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Pair (org.apache.commons.lang3.tuple.Pair)1 Hibernate (org.hibernate.Hibernate)1 Cache (org.hisp.dhis.cache.Cache)1 CacheProvider (org.hisp.dhis.cache.CacheProvider)1 EventContext (org.hisp.dhis.dxf2.events.event.EventContext)1 EventRow (org.hisp.dhis.dxf2.events.report.EventRow)1 EventRows (org.hisp.dhis.dxf2.events.report.EventRows)1 CHANGELOG_TRACKER (org.hisp.dhis.external.conf.ConfigurationKey.CHANGELOG_TRACKER)1 DhisConfigurationProvider (org.hisp.dhis.external.conf.DhisConfigurationProvider)1 OrganisationUnitService (org.hisp.dhis.organisationunit.OrganisationUnitService)1 Program (org.hisp.dhis.program.Program)1 ProgramOwnershipHistory (org.hisp.dhis.program.ProgramOwnershipHistory)1