1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

M #~: disable inputs restricted attributes (#2305)

(cherry picked from commit 66442e00a00a85f3d9ad74b083fb37ae100afcbf)
This commit is contained in:
Jorge Miguel Lobo Escalona 2022-10-13 13:56:18 +02:00 committed by Tino Vázquez
parent cef0e5f8b0
commit 732c8e007f
4 changed files with 51 additions and 9 deletions

View File

@ -15,6 +15,7 @@
* ------------------------------------------------------------------------- */
import { string, number } from 'yup'
import { INPUT_TYPES, T, HYPERVISORS, Field } from 'client/constants'
import { useDisableInputByUserAndConfig } from 'client/features/Auth'
const { vcenter, firecracker, lxc } = HYPERVISORS
@ -216,6 +217,8 @@ export const THROTTLING_BYTES_FIELDS = [
type: INPUT_TYPES.TEXT,
htmlType: 'number',
notOnHypervisors: [lxc, firecracker, vcenter],
fieldProps: () =>
useDisableInputByUserAndConfig('DISK/READ_BYTES_SEC_MAX_LENGTH'),
validation: number()
.min(0)
.notRequired()
@ -227,6 +230,7 @@ export const THROTTLING_BYTES_FIELDS = [
type: INPUT_TYPES.TEXT,
htmlType: 'number',
notOnHypervisors: [lxc, firecracker, vcenter],
fieldProps: () => useDisableInputByUserAndConfig('DISK/WRITE_BYTES_SEC'),
validation: number()
.min(0)
.notRequired()
@ -238,6 +242,8 @@ export const THROTTLING_BYTES_FIELDS = [
type: INPUT_TYPES.TEXT,
htmlType: 'number',
notOnHypervisors: [lxc, firecracker, vcenter],
fieldProps: () =>
useDisableInputByUserAndConfig('DISK/WRITE_BYTES_SEC_MAX'),
validation: number()
.min(0)
.notRequired()
@ -249,6 +255,8 @@ export const THROTTLING_BYTES_FIELDS = [
type: INPUT_TYPES.TEXT,
htmlType: 'number',
notOnHypervisors: [lxc, firecracker, vcenter],
fieldProps: () =>
useDisableInputByUserAndConfig('DISK/WRITE_BYTES_SEC_MAX_LENGTH'),
validation: number()
.min(0)
.notRequired()
@ -264,6 +272,7 @@ export const THROTTLING_IOPS_FIELDS = [
type: INPUT_TYPES.TEXT,
htmlType: 'number',
notOnHypervisors: [lxc, firecracker, vcenter],
fieldProps: () => useDisableInputByUserAndConfig('DISK/TOTAL_IOPS_SEC'),
validation: number()
.min(0)
.notRequired()
@ -275,6 +284,7 @@ export const THROTTLING_IOPS_FIELDS = [
type: INPUT_TYPES.TEXT,
htmlType: 'number',
notOnHypervisors: [lxc, firecracker, vcenter],
fieldProps: () => useDisableInputByUserAndConfig('DISK/TOTAL_IOPS_SEC_MAX'),
validation: number()
.min(0)
.notRequired()
@ -286,6 +296,8 @@ export const THROTTLING_IOPS_FIELDS = [
type: INPUT_TYPES.TEXT,
htmlType: 'number',
notOnHypervisors: [lxc, firecracker, vcenter],
fieldProps: () =>
useDisableInputByUserAndConfig('DISK/TOTAL_IOPS_SEC_MAX_LENGTH'),
validation: number()
.min(0)
.notRequired()
@ -297,6 +309,7 @@ export const THROTTLING_IOPS_FIELDS = [
type: INPUT_TYPES.TEXT,
htmlType: 'number',
notOnHypervisors: [lxc, firecracker, vcenter],
fieldProps: () => useDisableInputByUserAndConfig('DISK/READ_IOPS_SEC'),
validation: number()
.min(0)
.notRequired()
@ -308,6 +321,7 @@ export const THROTTLING_IOPS_FIELDS = [
type: INPUT_TYPES.TEXT,
htmlType: 'number',
notOnHypervisors: [lxc, firecracker, vcenter],
fieldProps: () => useDisableInputByUserAndConfig('DISK/READ_IOPS_SEC_MAX'),
validation: number()
.min(0)
.notRequired()
@ -319,6 +333,8 @@ export const THROTTLING_IOPS_FIELDS = [
type: INPUT_TYPES.TEXT,
htmlType: 'number',
notOnHypervisors: [lxc, firecracker, vcenter],
fieldProps: () =>
useDisableInputByUserAndConfig('DISK/READ_IOPS_SEC_MAX_LENGTH'),
validation: number()
.min(0)
.notRequired()
@ -330,6 +346,7 @@ export const THROTTLING_IOPS_FIELDS = [
type: INPUT_TYPES.TEXT,
htmlType: 'number',
notOnHypervisors: [lxc, firecracker, vcenter],
fieldProps: () => useDisableInputByUserAndConfig('DISK/WRITE_IOPS_SEC'),
validation: number()
.min(0)
.notRequired()
@ -341,6 +358,7 @@ export const THROTTLING_IOPS_FIELDS = [
type: INPUT_TYPES.TEXT,
htmlType: 'number',
notOnHypervisors: [lxc, firecracker, vcenter],
fieldProps: () => useDisableInputByUserAndConfig('DISK/WRITE_IOPS_SEC_MAX'),
validation: number()
.min(0)
.notRequired()
@ -352,6 +370,8 @@ export const THROTTLING_IOPS_FIELDS = [
type: INPUT_TYPES.TEXT,
htmlType: 'number',
notOnHypervisors: [lxc, firecracker, vcenter],
fieldProps: () =>
useDisableInputByUserAndConfig('DISK/WRITE_IOPS_SEC_MAX_LENGTH'),
validation: number()
.min(0)
.notRequired()

View File

@ -24,6 +24,8 @@ import {
} from 'client/utils'
import { T, INPUT_TYPES, HYPERVISORS, VN_DRIVERS, Nic } from 'client/constants'
import { useDisableInputByUserAndConfig } from 'client/features/Auth'
const { firecracker } = HYPERVISORS
const { ovswitch, vcenter } = VN_DRIVERS
@ -248,6 +250,7 @@ const OVERRIDE_IPV4_FIELDS = [
label: T.MAC,
tooltip: T.MACConcept,
type: INPUT_TYPES.TEXT,
fieldProps: () => useDisableInputByUserAndConfig('NIC/MAC'),
validation: string()
.trim()
.notRequired()
@ -353,6 +356,7 @@ const OVERRIDE_IN_QOS_FIELDS = [
type: INPUT_TYPES.TEXT,
notOnHypervisors: [firecracker],
htmlType: 'number',
fieldProps: () => useDisableInputByUserAndConfig('NIC/INBOUND_AVG_BW'),
validation: number()
.notRequired()
.default(() => undefined),
@ -364,6 +368,7 @@ const OVERRIDE_IN_QOS_FIELDS = [
type: INPUT_TYPES.TEXT,
notOnHypervisors: [firecracker],
htmlType: 'number',
fieldProps: () => useDisableInputByUserAndConfig('NIC/INBOUND_PEAK_BW'),
validation: number()
.notRequired()
.default(() => undefined),
@ -376,6 +381,7 @@ const OVERRIDE_IN_QOS_FIELDS = [
notOnHypervisors: [firecracker],
notOnDrivers: [vcenter],
htmlType: 'number',
fieldProps: () => useDisableInputByUserAndConfig('NIC/INBOUND_PEAK_KB'),
validation: number()
.notRequired()
.default(() => undefined),
@ -392,6 +398,7 @@ const OVERRIDE_OUT_QOS_FIELDS = [
notOnHypervisors: [firecracker],
notOnDrivers: [ovswitch],
htmlType: 'number',
fieldProps: () => useDisableInputByUserAndConfig('NIC/OUTBOUND_AVG_BW'),
validation: number()
.notRequired()
.default(() => undefined),
@ -404,6 +411,7 @@ const OVERRIDE_OUT_QOS_FIELDS = [
notOnHypervisors: [firecracker],
notOnDrivers: [ovswitch],
htmlType: 'number',
fieldProps: () => useDisableInputByUserAndConfig('NIC/OUTBOUND_PEAK_BW'),
validation: number()
.notRequired()
.default(() => undefined),
@ -416,6 +424,7 @@ const OVERRIDE_OUT_QOS_FIELDS = [
notOnHypervisors: [firecracker],
notOnDrivers: [ovswitch, vcenter],
htmlType: 'number',
fieldProps: () => useDisableInputByUserAndConfig('NIC/OUTBOUND_PEAK_KB'),
validation: number()
.notRequired()
.default(() => undefined),

View File

@ -17,8 +17,7 @@ import { useMemo, useCallback, ReactElement } from 'react'
import PropTypes from 'prop-types'
import loadable, { LoadableLibrary } from '@loadable/component'
import { Backdrop, CircularProgress } from '@mui/material'
import { useAuth } from 'client/features/Auth'
import { useGetOneConfigQuery } from 'client/features/OneApi/system'
import { useSystemData } from 'client/features/Auth'
import { CreateFormCallback, CreateStepsCallback } from 'client/utils/schema'
/**
@ -98,13 +97,7 @@ const MemoizedForm = ({
[]
)
const { data: oneConfig = {} } = useGetOneConfigQuery()
const { user } = useAuth()
const userGroup = Array.isArray(user?.GROUPS?.ID)
? user?.GROUPS?.ID
: [user?.GROUPS?.ID]
const adminGroup = userGroup?.includes?.('0')
const { oneConfig, adminGroup } = useSystemData()
const handleTriggerSubmit = useCallback(
(data) =>

View File

@ -97,6 +97,26 @@ export const useAuth = () => {
)
}
export const useSystemData = () => {
const { data: oneConfig = {} } = systemApi.useGetOneConfigQuery()
const { user } = useAuth()
const userGroup = Array.isArray(user?.GROUPS?.ID)
? user?.GROUPS?.ID
: [user?.GROUPS?.ID]
const adminGroup = userGroup?.includes?.('0')
return { oneConfig, adminGroup }
}
export const useDisableInputByUserAndConfig = (input = '') => {
const { adminGroup, oneConfig } = useSystemData()
return {
disabled: !adminGroup && oneConfig.VM_RESTRICTED_ATTR?.includes?.(input),
}
}
export const useAuthApi = () => {
const dispatch = useDispatch()