Просмотр исходного кода

项目概况,编辑文件权限

MaiXinRong 6 часов назад
Родитель
Сommit
5e1b2cd853

+ 7 - 5
app/public/js/shares/tools_att.js

@@ -84,14 +84,15 @@
             const tipType = 'title='; //'data-toggle="tooltip" data-html="true" data-placement="left" data-original-title=';
             html.push(`<td file-id="${att.id}"><div class="d-flex"><a href="javascript:void(0)" ${tipType}"${tipHtml}" class="pl-0 col-11" file-id=${att.id}>${att.filename}${att.fileext}</a></div></td>`);
             html.push(`<td>${att[fileInfo.user_name]}</td>`);
-            const canDel = setting.readOnly ? false : att[fileInfo.user_id] === userID && (!setting.checked || att.extra_upload);
-            const moveHtml = setting.moveUrl ? `<a href="javascript: void(0);" class="ml-1 text-primary" name="att-move" file-id="${att.id}" ${tipType}"移动"><i class="fa fa-exchange fa-fw"></i></a>` : '';
-            const editHtml = setting.saveUrl ? `<a href="javascript: void(0);" class="ml-1 text-primary" name="att-edit" file-id="${att.id}" ${tipType}"重命名"><i class="fa fa-pencil fa-fw"></i></a>` : '';
+            const canDel = setting.readOnly ? false : (att[fileInfo.user_id] === userID || setting.editfile) && (!setting.checked || att.extra_upload);
+            const moveHtml = canDel && setting.moveUrl ? `<a href="javascript: void(0);" class="ml-1 text-primary" name="att-move" file-id="${att.id}" ${tipType}"移动"><i class="fa fa-exchange fa-fw"></i></a>` : '';
+            const editHtml = canDel && setting.saveUrl ? `<a href="javascript: void(0);" class="ml-1 text-primary" name="att-edit" file-id="${att.id}" ${tipType}"重命名"><i class="fa fa-pencil fa-fw"></i></a>` : '';
+            const delHtml = canDel ? `<a class="ml-1 text-danger" href="javascript:void(0)" name="att-delete" file-id="${att.id}"><i class="fa fa-close" ${tipType}"删除"></i></a>` : '';
             html.push('<td width="80">',
                 `<a class="ml-1" href="javascript:void(0)" ${tipType}"定位" name="att-locate" file-id="${att.id}"><i class="fa fa-crosshairs"></i></a>`,
                 att.viewpath ? `<a class="ml-1" href="${att.viewpath}" ${tipType}"预览"  target="_blank"><i class="fa fa-eye"></i></a>` : '',
                 `<a class="ml-1" href="javascript:void(0)" ${tipType}"下载" onclick="AliOss.downloadFile('${att.filepath}', '${att.filename}${att.fileext}')"><i class="fa fa-download"></i></a>`,
-                canDel ? `<a class="ml-1 text-danger" href="javascript:void(0)" name="att-delete" file-id="${att.id}"><i class="fa fa-close" ${tipType}"删除"></i></a>` : '', moveHtml, editHtml,
+                delHtml, moveHtml, editHtml,
                 '</td>');
             html.push('</tr>');
             return html.join('');
@@ -253,7 +254,7 @@
                 const oxi = nodeIndexes[this.file[setting.masterKey]];
                 if (oxi) {
                     const oxii = findFileIndex(oxi, this.file.id);
-                    if (oxii) oxi.splice(oxii, 1);
+                    if (oxii >= 0) oxi.splice(oxii, 1);
                 }
                 if (!nodeIndexes[data[setting.masterKey]]) {
                     nodeIndexes[data[setting.masterKey]] = [this.file];
@@ -261,6 +262,7 @@
                     nodeIndexes[data[setting.masterKey]].unshift(this.file);
                 }
                 this.file[setting.masterKey] = data[setting.masterKey];
+                setting.getRelaNode(this.file);
             }
         };
         const findFile = setting.fileIdType === 'string'

+ 4 - 0
app/public/js/sp_progress.js

@@ -615,6 +615,10 @@ $(document).ready(() => {
             create_time: 'create_time',
         },
         search: true,
+        editfile: editfile,
+        getRelaNode: function(file) {
+            file.node = progressObj.tree.datas.find(x => { return x.id === file.rela_id; });
+        },
         relaTree: progressObj.tree,
         relaTreeSpreadSetting: {
             cols: [

+ 1 - 0
app/public/js/sp_push.js

@@ -423,6 +423,7 @@ $(document).ready(() => {
             user_id: 'user_id',
             create_time: 'create_time',
         },
+        editfile: editfile,
         getCurHint: function(node) { return ''; },
         locate: function (att) {
             if (!att) return;

+ 7 - 4
app/service/sub_proj_file.js

@@ -75,6 +75,11 @@ module.exports = app => {
             if (files.length === 0) return;
 
             const fileDatas = await this.getAllDataByCondition({ where: { id: files } });
+            if (this.ctx.subProject.permission.info_permission.indexOf(this.ctx.service.subProjPermission.PermissionConst.info.editfile.value) < 0) {
+                for (const f of fileDatas) {
+                    if (f.user_id !== this.ctx.session.sessionUser.accountId) throw '您无权编辑该文件';
+                }
+            }
             const result = {};
 
             const conn = await this.db.beginTransaction();
@@ -93,8 +98,7 @@ module.exports = app => {
         async saveFile(id, filename){
             const file = await this.getDataById(id);
             if (!file) throw '文件不存在';
-            // if (file.user_id !== this.ctx.session.sessionUser.accountId && this.ctx.subProject.permission.file_permission.indexOf(this.ctx.service.subProjPermission.PermissionConst.file.editfile.value) < 0) throw '您无权编辑该文件';
-            if (file.user_id !== this.ctx.session.sessionUser.accountId) throw '您无权编辑该文件';
+            if (file.user_id !== this.ctx.session.sessionUser.accountId && this.ctx.subProject.permission.info_permission.indexOf(this.ctx.service.subProjPermission.PermissionConst.info.editfile.value) < 0) throw '您无权编辑该文件';
 
             const info = path.parse(filename);
             const updateData = { id, filename: info.name, fileext: info.ext};
@@ -105,8 +109,7 @@ module.exports = app => {
         async moveFile(id, rela_id) {
             const file = await this.getDataById(id);
             if (!file) throw '文件不存在';
-            // if (file.user_id !== this.ctx.session.sessionUser.accountId && this.ctx.subProject.permission.file_permission.indexOf(this.ctx.service.subProjPermission.PermissionConst.file.editfile.value) < 0) throw '您无权编辑该文件';
-            if (file.user_id !== this.ctx.session.sessionUser.accountId) throw '您无权编辑该文件';
+            if (file.user_id !== this.ctx.session.sessionUser.accountId && this.ctx.subProject.permission.info_permission.indexOf(this.ctx.service.subProjPermission.PermissionConst.info.editfile.value) < 0) throw '您无权移动该文件';
             const updateData = { id, rela_id };
             await this.defaultUpdate(updateData);
             return updateData;

+ 1 - 0
app/view/sub_proj/progress.ejs

@@ -116,4 +116,5 @@
 <script>
     const readOnly = <%- readOnly %>;
     const fileReferenceList = JSON.parse('<%- JSON.stringify(fileReferenceList) %>');
+    const editfile = <%- ctx.subProject.permission.info_permission.indexOf(ctx.service.subProjPermission.PermissionConst.info.editfile.value) >= 0 %>;
 </script>

+ 1 - 0
app/view/sub_proj/push.ejs

@@ -85,4 +85,5 @@
 </div>
 <script>
     const readOnly = <%- readOnly %>;
+    const editfile = <%- ctx.subProject.permission.info_permission.indexOf(ctx.service.subProjPermission.PermissionConst.info.editfile.value) >= 0 %>;
 </script>