budget_check.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = options => {
  10. /**
  11. * 标段校验 中间件
  12. * 1. 读取标段数据(包括属性)
  13. * 2. 检验用户是否可见标段(不校验具体权限)
  14. *
  15. * @param {function} next - 中间件继续执行的方法
  16. * @return {void}
  17. */
  18. return function* budgetCheck(next) {
  19. try {
  20. if (!this.session.sessionProject.showBudget) {
  21. throw '该功能已关闭或无法查看';
  22. }
  23. // 读取标段数据
  24. const id = parseInt(this.params.id);
  25. if (!id) throw '参数错误';
  26. this.budget = yield this.service.budget.getCurBudget(id);
  27. if (!this.budget) throw '项目不存在';
  28. if (this.session.sessionUser.is_admin) {
  29. this.budget.readOnly = false;
  30. } else {
  31. const bp = yield this.service.subProjPermission.getBudgetUserPermission(id);
  32. if (!bp) throw '您无权查看该项目';
  33. this.budget.readOnly = bp.budget_permission.indexOf(this.service.subProjPermission.PermissionConst.budget.edit.value) < 0;
  34. }
  35. yield next;
  36. } catch (err) {
  37. this.log(err);
  38. if (this.helper.isAjax(this.request)) {
  39. this.ajaxErrorBody(err, '概算投资项目未知错误');
  40. } else {
  41. this.postError(err, '概算投资项目未知错误');
  42. err === '该功能已关闭或无法查看' ? this.redirect('/dashboard') : this.redirect(this.request.headers.referer);
  43. }
  44. }
  45. };
  46. };