Browse Source

拷贝用户权限问题

MaiXinRong 3 weeks atrás
parent
commit
5b261f5c75
2 changed files with 17 additions and 10 deletions
  1. 17 9
      app/service/sub_proj_permission.js
  2. 0 1
      app/view/budget/compare_modal.ejs

+ 17 - 9
app/service/sub_proj_permission.js

@@ -341,24 +341,32 @@ module.exports = app => {
             return updateData;
         }
 
-        async _copyUserPermission(copyData) {
+        async _copyUserPermission(copyData, force = false) {
             const copyPermission = await this.getAllDataByCondition({ where: { spid: this.ctx.subProject.id, uid: copyData.uid }});
             if (copyPermission.length === 0) throw '选择的用户不存在';
 
-            const insertData = [];
+            const insertData = [], updateData = [];
             for (const spid of copyData.spid) {
                 const exist = await this.getAllDataByCondition({ columns: ['uid'], where: { spid } });
                 copyPermission.forEach(cp => {
-                    if (exist.find(x => { return x.uid === cp.uid; })) return;
-
-                    const idata = { id: this.uuid.v4(), spid, pid: cp.pid, uid: cp.uid };
-                    for (const prop in cp) {
-                        if (prop.indexOf('_permission') > 1) idata[prop] = cp[prop];
+                    const ecp = exist.find(x => { return x.uid === cp.uid; });
+                    if (ecp && force) {
+                        const udata = { id: ecp.id };
+                        for (const prop in cp) {
+                            if (prop.indexOf('_permission') > 1) udata[prop] = cp[prop];
+                        }
+                        updateData.push(udata)
+                    } else {
+                        const idata = { id: this.uuid.v4(), spid, pid: cp.pid, uid: cp.uid };
+                        for (const prop in cp) {
+                            if (prop.indexOf('_permission') > 1) idata[prop] = cp[prop];
+                        }
+                        insertData.push(idata);
                     }
-                    insertData.push(idata);
                 });
             }
-            await this.db.insert(this.tableName, insertData);
+            if (insertData.length > 0) await this.db.insert(this.tableName, insertData);
+            if (force && updateData.length > 0) await this.db.updateRows(this.tableName, updateData);
         }
 
         async updatePermission(subProject, data) {

+ 0 - 1
app/view/budget/compare_modal.ejs

@@ -15,7 +15,6 @@
                     <label class="form-check-label" for="inlineRadio2">编号</label>
                 </div>
                 <div class="form-check form-check-inline" style="margin-right: 136px">
-                    <% console.log(ctx.budget) %>
                     <input class="form-check-input" type="radio" name="final_type" id="inlineRadio3" value="code_name" <%if (ctx.budget.final_type === 'code_name') {%> checked <% }%>>
                     <label class="form-check-label" for="inlineRadio3">编号+名称</label>
                 </div>