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);
}
}
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;
}
Aggregations