use of org.hisp.dhis.dataapproval.DataApprovalLevel in project dhis2-core by dhis2.
the class DefaultAnalyticsSecurityManager method withDataApprovalConstraints.
@Override
public DataQueryParams withDataApprovalConstraints(DataQueryParams params) {
DataQueryParams.Builder paramsBuilder = DataQueryParams.newBuilder(params);
User user = currentUserService.getCurrentUser();
boolean hideUnapprovedData = systemSettingManager.hideUnapprovedDataInAnalytics();
boolean canViewUnapprovedData = user != null ? user.getUserCredentials().isAuthorized(DataApproval.AUTH_VIEW_UNAPPROVED_DATA) : true;
if (hideUnapprovedData && user != null) {
Map<OrganisationUnit, Integer> approvalLevels = null;
if (params.hasApprovalLevel()) {
// Set approval level from query
DataApprovalLevel approvalLevel = approvalLevelService.getDataApprovalLevel(params.getApprovalLevel());
if (approvalLevel == null) {
throw new IllegalQueryException(String.format("Approval level does not exist: %s", params.getApprovalLevel()));
}
approvalLevels = approvalLevelService.getUserReadApprovalLevels(approvalLevel);
} else if (!canViewUnapprovedData) {
// Set approval level from user level
approvalLevels = approvalLevelService.getUserReadApprovalLevels();
}
if (approvalLevels != null && !approvalLevels.isEmpty()) {
paramsBuilder.withDataApprovalLevels(approvalLevels);
log.debug(String.format("User: %s constrained by data approval levels: %s", user.getUsername(), approvalLevels.values()));
}
}
return paramsBuilder.build();
}
use of org.hisp.dhis.dataapproval.DataApprovalLevel in project dhis2-core by dhis2.
the class DataApprovalController method saveApproval.
// -------------------------------------------------------------------------
// Post, approval
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')")
@RequestMapping(value = APPROVALS_PATH, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void saveApproval(@RequestParam(required = false) String ds, @RequestParam(required = false) String wf, @RequestParam String pe, @RequestParam String ou, HttpServletResponse response) throws WebMessageException {
DataApprovalWorkflow workflow = getAndValidateWorkflow(ds, wf);
Period period = getAndValidatePeriod(pe);
OrganisationUnit organisationUnit = getAndValidateOrgUnit(ou);
DataApprovalLevel dataApprovalLevel = getAndValidateApprovalLevel(organisationUnit);
User user = currentUserService.getCurrentUser();
List<DataApproval> dataApprovalList = getApprovalsAsList(dataApprovalLevel, workflow, period, organisationUnit, false, new Date(), //TODO fix category stuff
user);
dataApprovalService.approveData(dataApprovalList);
}
use of org.hisp.dhis.dataapproval.DataApprovalLevel in project dhis2-core by dhis2.
the class DataApprovalController method acceptApprovalMultiple.
@PreAuthorize("hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')")
@RequestMapping(value = MULTIPLE_ACCEPTANCES_RESOURCE_PATH, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void acceptApprovalMultiple(@RequestBody DataApprovalStateRequests dataApprovalStateRequests, HttpServletResponse response) throws WebMessageException {
List<DataApproval> dataApprovalList = new ArrayList<>();
for (DataApprovalStateRequest approvalStateRequest : dataApprovalStateRequests) {
DataApprovalWorkflow workflow = getAndValidateWorkflow(approvalStateRequest.getDs(), null);
Period period = getAndValidatePeriod(approvalStateRequest.getPe());
OrganisationUnit organisationUnit = getAndValidateOrgUnit(approvalStateRequest.getOu());
DataApprovalLevel dataApprovalLevel = getAndValidateApprovalLevel(organisationUnit);
User user = approvalStateRequest.getAb() == null ? currentUserService.getCurrentUser() : userService.getUserCredentialsByUsername(approvalStateRequest.getAb()).getUserInfo();
Date approvalDate = (approvalStateRequest.getAd() == null) ? new Date() : approvalStateRequest.getAd();
dataApprovalList.addAll(getApprovalsAsList(dataApprovalLevel, workflow, period, organisationUnit, false, approvalDate, user));
}
dataApprovalService.acceptData(dataApprovalList);
}
use of org.hisp.dhis.dataapproval.DataApprovalLevel in project dhis2-core by dhis2.
the class DataApprovalController method saveApprovalMultiple.
@PreAuthorize("hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')")
@RequestMapping(value = MULTIPLE_SAVE_RESOURCE_PATH, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void saveApprovalMultiple(@RequestBody DataApprovalStateRequests dataApprovalStateRequests, HttpServletResponse response) throws WebMessageException {
List<DataApproval> dataApprovalList = new ArrayList<>();
for (DataApprovalStateRequest approvalStateRequest : dataApprovalStateRequests) {
DataApprovalWorkflow workflow = getAndValidateWorkflow(approvalStateRequest.getDs(), null);
Period period = getAndValidatePeriod(approvalStateRequest.getPe());
OrganisationUnit organisationUnit = getAndValidateOrgUnit(approvalStateRequest.getOu());
DataApprovalLevel dataApprovalLevel = getAndValidateApprovalLevel(organisationUnit);
User user = approvalStateRequest.getAb() == null ? currentUserService.getCurrentUser() : userService.getUserCredentialsByUsername(approvalStateRequest.getAb()).getUserInfo();
Date approvalDate = approvalStateRequest.getAd() == null ? new Date() : approvalStateRequest.getAd();
dataApprovalList.addAll(getApprovalsAsList(dataApprovalLevel, workflow, period, organisationUnit, false, approvalDate, user));
}
dataApprovalService.approveData(dataApprovalList);
}
Aggregations