123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- 'use strict';
- /**
- *
- *
- * @author Ellisran
- * @date 2020/10/15
- * @version
- */
- const status = require('../const/audit').changeProject.status;
- const _ = require('lodash');
- module.exports = options => {
- /**
- * 标段校验 中间件
- * 1. 读取标段数据(包括属性)
- * 2. 检验用户是否可见标段(不校验具体权限)
- *
- * @param {function} next - 中间件继续执行的方法
- * @return {void}
- */
- return function* changeProjectCheck(next) {
- try {
- // 获取revise
- if (!this.session.sessionProject.page_show.openChangeProject) {
- throw '该功能已关闭';
- }
- const cpid = this.params.cpid || this.request.body.cpid;
- if (!cpid) {
- throw '您访问的变更立项不存在';
- }
- const change = yield this.service.changeProject.getDataById(cpid);
- if (!change) throw '变更立项数据有误';
- // 读取原报、审核人数据
- yield this.service.changeProject.loadChangeUser(change);
- // change.auditors = yield this.service.changeProjectAudit.getAuditors(change.id, change.times);
- // change.curAuditor = yield this.service.changeProjectAudit.getCurAuditor(change.id, change.times);
- change.xsAuditors = yield this.service.changeProjectXsAudit.getAuditList(change.id);
- // 权限相关
- // todo 校验权限 (标段参与人、分享)
- const accountId = this.session.sessionUser.accountId,
- xsAuditorIds = _.map(change.xsAuditors, 'aid'),
- shareIds = [];
- const permission = this.session.sessionUser.permission;
- if (accountId === change.uid) { // 原报
- change.curTimes = change.times;
- change.filePermission = true;
- } else if (change.auditorIds.indexOf(accountId) !== -1 || xsAuditorIds.indexOf(accountId) !== -1) { // 审批人或者协审人
- if (change.status === status.uncheck) {
- throw '您无权查看该数据';
- }
- change.curTimes = change.status === status.back || change.status === status.revise ? change.times - 1 : change.times;
- change.filePermission = true;
- } else if ((change.status === status.back || change.status === status.revise) && change.uid !== accountId) {
- const preAuditors = yield this.service.changeProjectAudit.getAuditors(change.id, change.times - 1);
- const preAuditorIds = _.map(preAuditors, 'aid');
- if (preAuditorIds.indexOf(accountId) === -1) {
- throw '您无权查看该数据';
- }
- change.filePermission = true;
- } else if (this.tender.isTourist || this.session.sessionUser.is_admin) {
- change.curTimes = change.times;
- change.filePermission = this.tender.touristPermission.file || change.auditorIds.indexOf(accountId) !== -1;
- } else if (shareIds.indexOf(accountId) !== -1 || (permission !== null && permission.tender !== undefined && permission.tender.indexOf('2') !== -1)) { // 分享人
- if (change.status === status.uncheck) {
- throw '您无权查看该数据';
- }
- change.curTimes = change.status === status.back || change.status === status.revise ? change.times - 1 : change.times;
- change.filePermission = false;
- } else { // 其他不可见
- throw '您无权查看该数据';
- }
- // 调差的readOnly 指表格和页面只能看不能改,和审批无关
- change.readOnly = !((change.status === status.uncheck || change.status === status.back || change.status === status.revise) && accountId === change.uid);
- this.change = change;
- yield this.service.changeProject.doCheckChangeCanCancel(this.change);
- yield next;
- } catch (err) {
- console.log(err);
- // 输出错误到日志
- if (err.stack) {
- this.logger.error(err);
- } else {
- this.getLogger('fail').info(JSON.stringify({
- error: err,
- project: this.session.sessionProject,
- user: this.session.sessionUser,
- body: this.session.body,
- }));
- }
- // 重定向值标段管理
- this.redirect(this.request.headers.referer);
- }
- };
- };
|