|
|
@@ -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) {
|