sub_project_check.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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.project_id !== this.session.sessionProject.id) throw '您无权查看该项目';
  28. if (!this.subProject) throw '项目不存在';
  29. if (this.session.sessionUser.is_admin) {
  30. this.subProject.readOnly = false;
  31. this.subProject.permission = this.service.subProjPermission.adminPermission;
  32. } else {
  33. const bp = yield this.service.subProjPermission.getSubProjectUserPermission(id, this.session.sessionUser.accountId);
  34. if (!bp) throw '您无权查看该项目';
  35. this.subProject.permission = bp;
  36. }
  37. yield next;
  38. } catch (err) {
  39. this.log(err);
  40. if (this.helper.isAjax(this.request)) {
  41. this.ajaxErrorBody(err, '未知错误');
  42. } else {
  43. this.postError(err, '未知错误');
  44. err === '该功能已关闭或无法查看' ? this.redirect('/dashboard') : this.redirect(this.request.headers.referer);
  45. }
  46. }
  47. };
  48. };