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
const required = attrs.needed ?? attrs.required;
delete attrs.needed;
const path = widget.options.path ?? attrs.path;
const select_attrs = {
...attrs,
// Filemanager select
@ -939,7 +940,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac
mode: widget.options.multiple ? 'open-multiple' : 'open',
multiple: widget.options.multiple,
method: 'EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link_existing',
methodId: widget.options.path ?? attrs.path,
methodId: path,
buttonLabel: this.egw().lang('Link')
},
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';
// 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.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
$path_parts = explode('.', Api\Vfs::basename($path));
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
$path .= '.'.$extension;
@ -363,14 +363,22 @@ class Vfs extends File
{
case 'vfs-upload':
if(!is_array($value)) $value = array();
/* Check & skip files that made it asynchronously
list($app,$id,$relpath) = explode(':',$this->id,3);
//...
foreach($value as $tmp => $file)
/* Check & skip files that made it asynchronously, or they */
list($app, $id, $relpath) = explode(':', $this->attrs['path'], 3);
if($app && $id)
{
if(Api\Vfs::file_exists(self::get_vfs_path($id) . $relpath)) {}
}*/
parent::validate($cname, $expand, $content, $validated);
foreach($value as $index => $file)
{
if(!empty($file['path']) && Api\Vfs::file_exists($file['path']))
{
unset($value[$index]);
}
}
}
if(count($value))
{
parent::validate($cname, $expand, $content, $validated);
}
break;
case 'vfs-name':
case 'et2-vfs-name':