浏览代码

fix: cannot create shortcut for shared file

Closes #1263
KernelDeimos 1 周之前
父节点
当前提交
72a45500d5

+ 5 - 3
src/backend/src/filesystem/hl_operations/hl_mkshortcut.js

@@ -42,7 +42,7 @@ class HLMkShortcut extends HLFilesystemOperation {
         const { context, values } = this;
         const fs = context.get('services').get('filesystem');
 
-        const { target, parent, user } = values;
+        const { target, parent, user, actor } = values;
         let { name, dedupe_name } = values;
 
         if ( ! await target.exists() ) {
@@ -55,8 +55,10 @@ class HLMkShortcut extends HLFilesystemOperation {
         }
 
         {
-            const has_perm = await chkperm(target.entry, values.user.id, 'read');
-            if ( ! has_perm ) throw APIError.create('permission_denied');
+            const svc_acl = context.get('services').get('acl');
+            if ( ! await svc_acl.check(actor, target, 'read') ) {
+                throw await svc_acl.get_safe_acl_error(actor, target, 'read');
+            }
         }
 
         if ( ! await parent.exists() ) {

+ 5 - 1
src/gui/src/UI/UIItem.js

@@ -924,6 +924,7 @@ function UIItem(options){
             if(!are_trashed && window.feature_flags.create_shortcut){
                 menu_items.push({
                     html: i18n('create_shortcut'),
+                    html: is_shared_with_me ? i18n('create_desktop_shortcut_s') : i18n('create_shortcut_s'),
                     onClick: async function(){
                         $selected_items.each(function() {
                             let base_dir = path.dirname($(this).attr('data-path'));
@@ -931,6 +932,7 @@ function UIItem(options){
                             if($(this).attr('data-path') && $(this).closest('.item-container').attr('data-path') === window.desktop_path){
                                 base_dir = window.desktop_path;
                             }
+                            if ( is_shared_with_me ) base_dir = window.desktop_path;
                             // create shortcut
                             window.create_shortcut(
                                 path.basename($(this).attr('data-path')), 
@@ -1273,7 +1275,7 @@ function UIItem(options){
             // -------------------------------------------
             if(!is_trashed && window.feature_flags.create_shortcut){
                 menu_items.push({
-                    html: i18n('create_shortcut'),
+                    html: is_shared_with_me ? i18n('create_desktop_shortcut') : i18n('create_shortcut'),
                     onClick: async function(){
                         let base_dir = path.dirname($(el_item).attr('data-path'));
                         // Trash on Desktop is a special case
@@ -1281,6 +1283,8 @@ function UIItem(options){
                             base_dir = window.desktop_path;
                         }
 
+                        if ( is_shared_with_me ) base_dir = window.desktop_path;
+
                         window.create_shortcut(
                             path.basename($(el_item).attr('data-path')), 
                             options.is_dir, 

+ 1 - 2
src/gui/src/helpers.js

@@ -933,14 +933,13 @@ window.available_templates = async () => {
 }
 
 window.create_shortcut = async(filename, is_dir, basedir, appendto_element, shortcut_to, shortcut_to_path)=>{
-    let dirname = basedir;
     const extname = path.extname(filename);
     const basename = path.basename(filename, extname) + ' - Shortcut';
     filename = basename + extname;
 
     // create file shortcut
     try{
-        await puter.fs.upload(new File([], filename), dirname, {
+        await puter.fs.upload(new File([], filename), basedir, {
             overwrite: false,
             shortcutTo: shortcut_to_path ?? shortcut_to,
             dedupeName: true,

+ 3 - 0
src/gui/src/i18n/translations/en.js

@@ -83,7 +83,10 @@ const en = {
         cover: 'Cover',
         create_account: "Create Account",
         create_free_account: "Create Free Account",
+        create_desktop_shortcut: "Create Shortcut (Desktop)",
+        create_desktop_shortcut_s: "Create Shortcuts (Desktop)",
         create_shortcut: "Create Shortcut",
+        create_shortcut_s: "Create Shortcuts",
         credits: "Credits",
         current_password: "Current Password",
         cut: 'Cut',