import localsHelper from '../utils/localsHelper.js';

const reportAuthoriser = (services, layoutPath) => {
    return async (req, res, next) => {
        const { token, definitionsPath } = localsHelper.getValues(res);
        const { reportId } = req.params;
        const definitionSummary = res.locals['reportDefinitionSummary'] ??
            (await services.reportingService.getDefinitionSummary(token, reportId, definitionsPath));
        const userIsAuthorisedToViewReport = definitionSummary.authorised ?? false;
        if (!userIsAuthorisedToViewReport || !token) {
            res.render(`dpr/routes/journeys/view-report/unauthorised`, {
                layoutPath,
                ...req.body,
            });
        }
        else {
            next();
        }
    };
};

export { reportAuthoriser as default, reportAuthoriser };
//# sourceMappingURL=reportAuthoriser.js.map
