sub_project_check.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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* subProjectCheck(next) {
  19. try {
  20. if (!this.session.sessionProject.page_show.openFile && !this.session.sessionProject.showSubProj) {
  21. throw '该功能已关闭或无法查看';
  22. }
  23. // 读取标段数据
  24. const id = this.params.id || this.query.id;
  25. if (!id) throw '参数错误';
  26. this.subProject = yield this.service.subProject.getDataById(id);
  27. if (!this.subProject) throw '项目不存在';
  28. if (this.session.sessionUser.is_admin) {
  29. this.subProject.readOnly = false;
  30. this.subProject.permission = this.service.subProjPermission.adminPermission;
  31. } else {
  32. const bp = yield this.service.subProjPermission.getSubProjectUserPermission(id, this.session.sessionUser.accountId);
  33. if (!bp) throw '您无权查看该项目';
  34. this.subProject.permission = bp;
  35. }
  36. yield next;
  37. } catch (err) {
  38. this.log(err);
  39. if (this.helper.isAjax(this.request)) {
  40. this.ajaxErrorBody(err, '未知错误');
  41. } else {
  42. this.postError(err, '未知错误');
  43. err === '该功能已关闭或无法查看' ? this.redirect('/dashboard') : this.redirect(this.request.headers.referer);
  44. }
  45. }
  46. };
  47. };