Search in sources :

Example 6 with DataApprovalLevel

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();
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) User(org.hisp.dhis.user.User)

Example 7 with DataApprovalLevel

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) DataApproval(org.hisp.dhis.dataapproval.DataApproval) User(org.hisp.dhis.user.User) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) Date(java.util.Date) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with DataApprovalLevel

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);
}
Also used : DataApproval(org.hisp.dhis.dataapproval.DataApproval) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) User(org.hisp.dhis.user.User) DataApprovalStateRequest(org.hisp.dhis.dataapproval.DataApprovalStateRequest) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) Date(java.util.Date) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with DataApprovalLevel

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);
}
Also used : DataApproval(org.hisp.dhis.dataapproval.DataApproval) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) User(org.hisp.dhis.user.User) DataApprovalStateRequest(org.hisp.dhis.dataapproval.DataApprovalStateRequest) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) Date(java.util.Date) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataApprovalLevel (org.hisp.dhis.dataapproval.DataApprovalLevel)9 User (org.hisp.dhis.user.User)9 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 Date (java.util.Date)7 DataApproval (org.hisp.dhis.dataapproval.DataApproval)7 DataApprovalWorkflow (org.hisp.dhis.dataapproval.DataApprovalWorkflow)6 Period (org.hisp.dhis.period.Period)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)6 ArrayList (java.util.ArrayList)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 DataApprovalStateRequest (org.hisp.dhis.dataapproval.DataApprovalStateRequest)2 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)1 DataApprovalState (org.hisp.dhis.dataapproval.DataApprovalState)1 DataApprovalStatus (org.hisp.dhis.dataapproval.DataApprovalStatus)1 DataSet (org.hisp.dhis.dataset.DataSet)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 SqlRowSet (org.springframework.jdbc.support.rowset.SqlRowSet)1