tender_permission_check.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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* tenderPermissionCheck(next) {
  19. try {
  20. // 读取标段数据
  21. if (this.session.sessionUser.is_admin) {
  22. this.permission = this.service.tenderPermission.getAdminPermission();
  23. } else {
  24. this.permission = yield this.service.tenderPermission.getUserPermission(this.tender.id, this.session.sessionUser.accountId);
  25. }
  26. yield next;
  27. } catch (err) {
  28. this.log(err);
  29. if (this.helper.isAjax(this.request)) {
  30. this.ajaxErrorBody(err, '未知错误');
  31. } else {
  32. this.postError(err, '未知错误');
  33. this.redirect(this.request.headers.referer);
  34. }
  35. }
  36. };
  37. };