1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- 'use strict';
- /**
- *
- *
- * @author Ellisran
- * @date 2020/10/15
- * @version
- */
- const status = require('../const/audit').flow.status;
- const shenpiConst = require('../const/shenpi');
- const _ = require('lodash');
- module.exports = options => {
- /**
- * 标段校验 中间件
- * 1. 读取标段数据(包括属性)
- * 2. 检验用户是否可见标段(不校验具体权限)
- *
- * @param {function} next - 中间件继续执行的方法
- * @return {void}
- */
- return function* changeCheck(next) {
- try {
- // 获取revise
- const cid = this.params.cid || this.request.body.cid;
- if (!cid) {
- throw '您访问的变更令不存在';
- }
- const change = yield this.service.change.getDataByCondition({ cid });
- // 读取原报、审核人数据
- change.auditors = yield this.service.changeAudit.getListGroupByTimes(change.cid, change.times);
- change.curAuditor = yield this.service.changeAudit.getCurAuditor(change.cid, change.times);
- console.log(change.curAuditor);
- if (!change) throw '变更令数据有误';
- // 权限相关
- // todo 校验权限 (变更参与人)
- const accountId = this.session.sessionUser.accountId,
- auditorIds = _.map(change.auditors, 'uid'),
- shareIds = [];
- const permission = this.session.sessionUser.permission;
- if (accountId === change.uid) { // 原报
- if (change.curAuditor) {
- change.readOnly = change.curAuditor.uid !== accountId;
- } else {
- change.readOnly = change.status !== status.uncheck && change.status !== status.back;
- }
- } else if (auditorIds.indexOf(accountId) !== -1) { // 审批人
- if (change.status === status.uncheck) {
- throw '您无权查看该数据';
- }
- change.readOnly = true;
- } else if (shareIds.indexOf(accountId) !== -1 || (permission !== null && permission.tender !== undefined && permission.tender.indexOf('2') !== -1)) { // 分享人
- if (change.status === status.uncheck) {
- throw '您无权查看该数据';
- }
- change.readOnly = true;
- } else { // 其他不可见
- throw '您无权查看该数据';
- }
- this.change = 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);
- }
- };
- };
|