budget_check.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // 读取标段数据
  21. const id = parseInt(this.params.id);
  22. if (!id) throw '参数错误';
  23. this.budget = yield this.service.budget.getCurBudget(id);
  24. if (!this.budget) throw '项目不存在';
  25. if (this.session.sessionUser.is_admin) {
  26. this.budget.readOnly = false;
  27. } else {
  28. const bp = yield this.service.budgetPermission.getBudgetUserPermission(id);
  29. if (!bp) throw '您无权查看该项目';
  30. this.budget.readOnly = bp.permission.indexOf(this.service.budgetPermission.PermissionConst.edit.value) < 0;
  31. }
  32. yield next;
  33. } catch (err) {
  34. this.log(err);
  35. if (this.helper.isAjax(this.request)) {
  36. this.ajaxErrorBody(err, '概算投资项目未知错误');
  37. } else {
  38. this.postError(err, '概算投资项目未知错误');
  39. this.redirect(this.request.headers.referer);
  40. }
  41. }
  42. };
  43. };