uncheck_tender_check.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const auditConst = require('../const/audit').ledger;
  10. const messageType = require('../const/message_type');
  11. module.exports = options => {
  12. /**
  13. * 标段校验 中间件
  14. * 1. 读取标段数据(包括属性)
  15. * 2. 检验用户是否可见标段(不校验具体权限)
  16. *
  17. * @param {function} next - 中间件继续执行的方法
  18. * @return {void}
  19. */
  20. return function* uncheckTenderCheck(next) {
  21. try {
  22. if (this.tender.data.ledger_status === auditConst.status.uncheck) {
  23. if (this.tender.data.user_id !== this.session.sessionUser.accountId && !this.session.sessionUser.is_admin && this.tender.advanceAuditorsId.indexOf(this.session.sessionUser.accountId) === -1 && !this.tender.isTourist && !this.tender.assLedger) {
  24. throw '您无权查看该项目';
  25. } else if (this.tender.advanceAuditorsId.indexOf(this.session.sessionUser.accountId) !== -1 && !this.session.sessionUser.is_admin && !this.tender.isTourist) {
  26. throw '您无权查看该内容';
  27. }
  28. }
  29. yield next;
  30. } catch (err) {
  31. // 输出错误到日志
  32. this.log(err);
  33. if (this.helper.isAjax(this.request)) {
  34. this.ajaxErrorBody(err, '查看标段数据错误');
  35. } else {
  36. this.postError(err, '查看标段数据错误');
  37. if (this.helper.isWap(this.request)) {
  38. this.redirect('/wap/subproj');
  39. } else {
  40. err === '您无权查看该内容' ? this.redirect(this.request.headers.referer) : this.redirect(`/sp/${this.subProject.id}/list`);
  41. }
  42. }
  43. }
  44. };
  45. };