[pve-devel] [PATCH manager 7/7] ui: qemu/HardwareView: add CDROM permission check to edit button

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Feb 3 07:21:39 CET 2021


On 02.02.21 14:41, Aaron Lauterer wrote:
> 
> 
> On 2/2/21 2:13 PM, Dominik Csapak wrote:
>> well this is hardly readable anymore... (not your fault)
>> but, would it now not be disabled if i have no CDROM perms
>> even if it is a disk and i have perms for that,
>> because of short-circuiting ?
> 
> Oh yeah, thanks for catching that. One more comment inline
> 
> 
>>
>> On 2/1/21 3:21 PM, Aaron Lauterer wrote:
>>> Add CDROM permission check to disable the Edit button if they are not
>>> present.
>>>
>>> Signed-off-by: Aaron Lauterer <a.lauterer at proxmox.com>
>>> ---
>>>   www/manager6/qemu/HardwareView.js | 6 +++++-
>>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/www/manager6/qemu/HardwareView.js b/www/manager6/qemu/HardwareView.js
>>> index 252a8e72..56bdc0a1 100644
>>> --- a/www/manager6/qemu/HardwareView.js
>>> +++ b/www/manager6/qemu/HardwareView.js
>>> @@ -600,7 +600,11 @@ Ext.define('PVE.qemu.HardwareView', {
>>>           remove_btn.setText(isUsedDisk && !isCloudInit ? remove_btn.altText : remove_btn.defaultText);
>>>           remove_btn.RESTMethod = isUnusedDisk ? 'POST':'PUT';
>>> -        edit_btn.setDisabled(rec.data.delete || !rowdef.editor || isCloudInit || (!isCDRom && !diskCap));
>>> +        edit_btn.setDisabled(rec.data.delete ||
>>> +                 !rowdef.editor ||
>>> +                 isCloudInit ||
>>> +                 !caps.vms['VM.Config.CDROM'] ||
> 
> It doesn't really help readability but should work if we additionally check if the current selection is a cdrom. This should prevent short-circuiting in that case
> 
>             (isCDRom && !caps.vms['VM.Config.CDROM'])) ||

please also split all lines consistently, i.e., if this would stay as is then it should
be written as

edit_btn.setDisabled(
    rec.data.delete ||
    !rowdef.editor ||
    isCloudInit ||
    !caps.vms['VM.Config.CDROM'] ||
    (!isCDRom && !diskCap)
);

less indentation but also less crowded (as method call and first argument aren't glued together)





More information about the pve-devel mailing list