Fix vfs custom fields with no extension could get renamed on save

Also disabled vfs-select customfields when there's no app ID since there's no server handling
This commit is contained in:
nathan 2024-10-28 11:54:32 -06:00
parent e3c7831bc5
commit 6ab9915e91
2 changed files with 22 additions and 9 deletions

View File

@ -931,6 +931,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
// Add a link to existing VFS file // Add a link to existing VFS file
const required = attrs.needed ?? attrs.required; const required = attrs.needed ?? attrs.required;
delete attrs.needed; delete attrs.needed;
const path = widget.options.path ?? attrs.path;
const select_attrs = { const select_attrs = {
...attrs, ...attrs,
// Filemanager select // Filemanager select
@ -939,7 +940,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
mode: widget.options.multiple ? 'open-multiple' : 'open', mode: widget.options.multiple ? 'open-multiple' : 'open',
multiple: widget.options.multiple, multiple: widget.options.multiple,
method: 'EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link_existing', method: 'EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link_existing',
methodId: widget.options.path ?? attrs.path, methodId: path,
buttonLabel: this.egw().lang('Link') buttonLabel: this.egw().lang('Link')
}, },
type: 'et2-vfs-select', type: 'et2-vfs-select',
@ -947,6 +948,10 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
} }
select_attrs.id = attrs.id + '_vfs_select'; select_attrs.id = attrs.id + '_vfs_select';
// No links if no ID - server can't handle links
let s = path.split(":");
select_attrs.disabled = (s.length != 3 || s[1] == '');
// This controls where the button is placed in the DOM // This controls where the button is placed in the DOM
this.rows[select_attrs.id] = cf[0]; this.rows[select_attrs.id] = cf[0];

View File

@ -304,7 +304,7 @@ class Vfs extends File
// check if path already contains a valid extension --> don't add another one // check if path already contains a valid extension --> don't add another one
$path_parts = explode('.', Api\Vfs::basename($path)); $path_parts = explode('.', Api\Vfs::basename($path));
if ((!($path_ext = array_pop($path_parts)) || Api\MimeMagic::ext2mime($path_ext) === 'application/octet-stream') && if ((!($path_ext = array_pop($path_parts)) || Api\MimeMagic::ext2mime($path_ext) === 'application/octet-stream') &&
($extension = array_pop($parts) ?: Api\MimeMagic::mime2ext($file['mime']))) (($extension = array_pop($parts) ?: Api\MimeMagic::mime2ext($file['mime'])) && $extension != $filename))
{ {
// add extension to path // add extension to path
$path .= '.'.$extension; $path .= '.'.$extension;
@ -363,14 +363,22 @@ class Vfs extends File
{ {
case 'vfs-upload': case 'vfs-upload':
if(!is_array($value)) $value = array(); if(!is_array($value)) $value = array();
/* Check & skip files that made it asynchronously /* Check & skip files that made it asynchronously, or they */
list($app,$id,$relpath) = explode(':',$this->id,3); list($app, $id, $relpath) = explode(':', $this->attrs['path'], 3);
//... if($app && $id)
foreach($value as $tmp => $file)
{ {
if(Api\Vfs::file_exists(self::get_vfs_path($id) . $relpath)) {} foreach($value as $index => $file)
}*/ {
parent::validate($cname, $expand, $content, $validated); if(!empty($file['path']) && Api\Vfs::file_exists($file['path']))
{
unset($value[$index]);
}
}
}
if(count($value))
{
parent::validate($cname, $expand, $content, $validated);
}
break; break;
case 'vfs-name': case 'vfs-name':
case 'et2-vfs-name': case 'et2-vfs-name':