Skip to content

Commit

Permalink
Merge pull request #9173 from GilbertCherrie/fix_vm_reconfigure_form_…
Browse files Browse the repository at this point in the history
…privelages

Fix vm reconfigure form privelages
  • Loading branch information
jeffibm authored May 6, 2024
2 parents 8e8a98d + 0308f90 commit 3e0cd03
Show file tree
Hide file tree
Showing 6 changed files with 5,034 additions and 519 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import { setNetworkData } from './helpers/network';
import { setDrivesData } from './helpers/drive';
import { TYPES } from './helpers/general';

const memoryField = (roles) => ({
const memoryField = () => ({
component: 'switch',
name: 'cb_memory',
label: __('Memory'),
onText: __('Yes'),
offText: __('No'),
isDisabled: roles.allowMemoryChange === false,
});

const memoryValueField = () => ({
Expand Down Expand Up @@ -56,13 +55,12 @@ const memoryFormFields = (memory) => ({
],
});

const processorField = (roles) => ({
const processorField = () => ({
component: 'switch',
name: 'processor',
label: __('Processor'),
onText: __('Yes'),
offText: __('No'),
isDisabled: roles.allowCpuChange === false,
});

const socketField = (data, setData, options) => ({
Expand Down Expand Up @@ -123,6 +121,7 @@ const diskTable = (data, roles, setData, onCellClick, buttonClick) => ({
formType: TYPES.DISK,
addButtonLabel: __('Add Disk'),
buttonClick,
roleAllowed: roles.allowDiskChange,
});

const networkTable = (data, roles, setData, onCellClick, buttonClick) => ({
Expand All @@ -135,6 +134,7 @@ const networkTable = (data, roles, setData, onCellClick, buttonClick) => ({
formType: TYPES.NETWORK,
addButtonLabel: __('Add Network Adapter'),
buttonClick,
roleAllowed: roles.allowNetworkChange,
});

const driveTable = (data, roles, setData, onCellClick) => ({
Expand All @@ -147,19 +147,23 @@ const driveTable = (data, roles, setData, onCellClick) => ({
addButton: false,
formType: TYPES.DRIVE,
hideField: !data.dataTable.drives || data.dataTable.drives.length === 0,
roleAllowed: roles.allowCdromsChange,
});

const renderDatatables = (recordId, data, roles, setData, onCellClick, buttonClick) => [diskTable(data, roles, setData, onCellClick, buttonClick),
networkTable(data, roles, setData, onCellClick, buttonClick),
driveTable(data, roles, setData, onCellClick)];

export const reconfigureFormFields = (recordId, roles, memory, data, setData, options, onCellClick, buttonClick) => {
const formFields = [
memoryField(roles),
memoryFormFields(memory),
processorField(roles),
processorFormFields(data, setData, options, memory.max_cpu),
];
const formFields = [];
if (roles.allowMemoryChange) {
formFields.push(memoryField());
formFields.push(memoryFormFields(roles));
}
if (roles.allowCpuChange) {
formFields.push(processorField());
formFields.push(processorFormFields(data, setData, options, memory.max_cpu));
}
if (recordId.length === 1) {
formFields.push(renderDatatables(recordId, data, roles, setData, onCellClick, buttonClick));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import classNames from 'classnames';
import MiqDataTable from '../../miq-data-table';

const ReconfigureTable = ({
label, headers, rows, addButtonLabel, buttonClick, onCellClick, formType,
label, headers, rows, addButtonLabel, buttonClick, onCellClick, formType, roleAllowed,
}) => {
const renderAddButton = () => addButtonLabel && (
<Button
Expand All @@ -18,7 +18,7 @@ const ReconfigureTable = ({
{addButtonLabel}
</Button>
);
return (
return roleAllowed ? (
<div className={classNames(`${formType}-table`, 'reconfigure-form-table')}>
<div className="form-section-title">
<h3>{label}</h3>
Expand All @@ -31,7 +31,7 @@ const ReconfigureTable = ({
mode={`${formType}-table-list`}
/>
</div>
);
) : null;
};

ReconfigureTable.propTypes = {
Expand All @@ -42,6 +42,7 @@ ReconfigureTable.propTypes = {
formType: PropTypes.string,
onCellClick: PropTypes.func,
buttonClick: PropTypes.func,
roleAllowed: PropTypes.bool,
};

ReconfigureTable.defaultProps = {
Expand All @@ -52,5 +53,6 @@ ReconfigureTable.defaultProps = {
addButtonLabel: '',
formType: '',
label: '',
roleAllowed: false,
};
export default ReconfigureTable;
Loading

0 comments on commit 3e0cd03

Please sign in to comment.