From d83081f39fae168f361a68d71aa39725f9d64b47 Mon Sep 17 00:00:00 2001 From: Girija Soni Date: Thu, 25 Jan 2024 16:09:40 +0530 Subject: [PATCH] Fixes #36595 - Don't show the value for hidden ansible variables --- .../ansible_variable_overrides/update.rb | 1 + .../overriden_ansible_variable_presenter.rb | 2 +- app/models/ansible_variable.rb | 4 ++ .../AnsibleVariableOverridesTable.js | 41 +++++++++++++++---- .../AnsibleVariableOverridesTableHelper.js | 5 ++- .../EditableAction.js | 1 + .../AnsibleVariableOverrides/EditableValue.js | 8 ---- .../updateAnsibleVariableOverride.gql | 6 ++- .../graphql/queries/hostVariableOverrides.gql | 1 + 9 files changed, 48 insertions(+), 21 deletions(-) diff --git a/app/graphql/mutations/ansible_variable_overrides/update.rb b/app/graphql/mutations/ansible_variable_overrides/update.rb index fe3122ae7..1c623b1fb 100644 --- a/app/graphql/mutations/ansible_variable_overrides/update.rb +++ b/app/graphql/mutations/ansible_variable_overrides/update.rb @@ -11,6 +11,7 @@ class Update < ::Mutations::UpdateMutation argument :omit, Boolean, required: false argument :host_id, Int, required: true argument :ansible_variable_id, Int, required: true + argument :hidden_value, Boolean, required: true field :overriden_ansible_variable, ::Types::OverridenAnsibleVariable, :null => true diff --git a/app/graphql/presenters/overriden_ansible_variable_presenter.rb b/app/graphql/presenters/overriden_ansible_variable_presenter.rb index ae4003a76..13e52ec6f 100644 --- a/app/graphql/presenters/overriden_ansible_variable_presenter.rb +++ b/app/graphql/presenters/overriden_ansible_variable_presenter.rb @@ -3,7 +3,7 @@ class OverridenAnsibleVariablePresenter attr_reader :ansible_variable delegate :id, :key, :description, :override?, - :parameter_type, :hidden_value?, :omit, :required, + :parameter_type, :hidden_value, :omit, :required, :validator_type, :validator_rule, :default_value, :ansible_role, :current_value, :to => :ansible_variable diff --git a/app/models/ansible_variable.rb b/app/models/ansible_variable.rb index fd8518fd6..b211964e3 100644 --- a/app/models/ansible_variable.rb +++ b/app/models/ansible_variable.rb @@ -15,6 +15,10 @@ def ansible? true end + def hidden_value + hidden_value? + end + def self.humanize_class_name(options = nil) if options.present? super diff --git a/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverridesTable.js b/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverridesTable.js index a0389561f..17e193248 100644 --- a/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverridesTable.js +++ b/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverridesTable.js @@ -13,7 +13,7 @@ import { Th, Td, } from '@patternfly/react-table'; -import { Flex, FlexItem } from '@patternfly/react-core'; +import { Flex, FlexItem, Checkbox } from '@patternfly/react-core'; import Pagination from 'foremanReact/components/Pagination'; import deleteAnsibleVariableOverride from '../../../../graphql/mutations/deleteAnsibleVariableOverride.gql'; @@ -26,6 +26,7 @@ import { validateValue, onCompleted, onError, + formatValue, } from './AnsibleVariableOverridesTableHelper'; import withLoading from '../../../withLoading'; @@ -44,6 +45,7 @@ const initState = vars => value: variable.currentValue ? variable.currentValue.value : variable.defaultValue, + hiddenValue: variable.hiddenValue, validation: { key: 'noval', msg: '' }, working: false, })); @@ -77,6 +79,10 @@ const AnsibleVariableOverridesTable = ({ innerDispatch({ idx, payload: { open: flag } }); }; + const setHiddenValue = idx => isHide => { + innerDispatch({ idx, payload: { hiddenValue: isHide } }); + }; + const onValueChange = (idx, variable) => value => { const payload = { value, @@ -174,14 +180,31 @@ const AnsibleVariableOverridesTable = ({ {variable.ansibleRoleName} {variable.parameterType} - + {!editableState[idx].open ? ( + formatValue(variable) + ) : ( + <> + + + + )} {formatSourceAttr(variable)} diff --git a/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverridesTableHelper.js b/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverridesTableHelper.js index 4864c2601..27c9aef2f 100644 --- a/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverridesTableHelper.js +++ b/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/AnsibleVariableOverridesTableHelper.js @@ -12,6 +12,7 @@ function formatSourceLink(currentValue) { return `${__(element)}: ${currentValue.elementName}`; } +//here we can add the condition for hidden value to "*****" export const formatSourceAttr = variable => variable.currentValue ? formatSourceLink(variable.currentValue) @@ -21,7 +22,9 @@ export const formatValue = variable => { const value = variable.currentValue ? variable.currentValue.value : variable.defaultValue; - + if (variable.hiddenValue) { + return '••••••••'; + } switch (variable.parameterType) { case 'boolean': return value ? : ; diff --git a/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableAction.js b/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableAction.js index b59a18e94..b2df2db1e 100644 --- a/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableAction.js +++ b/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableAction.js @@ -73,6 +73,7 @@ const EditableAction = ({ variables: { id: lookupValue.id, value: state.value, + hiddenValue: state.hiddenValue, hostId, ansibleVariableId: decodeModelId(variable), match, diff --git a/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js b/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js index e4d03b7e0..ef36a85de 100644 --- a/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js +++ b/webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js @@ -1,9 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; import { translate as __ } from 'foremanReact/common/I18n'; - -import { formatValue } from './AnsibleVariableOverridesTableHelper'; - import { TextAreaField, TextInputField, @@ -11,10 +8,6 @@ import { } from './EditableValueHelper'; const EditableValue = props => { - if (!props.editing) { - return formatValue(props.variable); - } - const type = props.variable.parameterType; if (['json', 'yaml', 'array', 'hash'].includes(type)) { @@ -61,7 +54,6 @@ const EditableValue = props => { }; EditableValue.propTypes = { - editing: PropTypes.bool.isRequired, variable: PropTypes.object.isRequired, onChange: PropTypes.func.isRequired, value: PropTypes.any, diff --git a/webpack/graphql/mutations/updateAnsibleVariableOverride.gql b/webpack/graphql/mutations/updateAnsibleVariableOverride.gql index 069b2614f..02e8c132e 100644 --- a/webpack/graphql/mutations/updateAnsibleVariableOverride.gql +++ b/webpack/graphql/mutations/updateAnsibleVariableOverride.gql @@ -3,8 +3,9 @@ mutation UpdateAnsibleVariableOverride( $hostId: Int!, $ansibleVariableId: Int!, $value: RawJson! - $match: String!) { - updateAnsibleVariableOverride(input: { id: $id, hostId: $hostId, value: $value, ansibleVariableId: $ansibleVariableId }) { + $match: String! + $hiddenValue: Boolean!) { + updateAnsibleVariableOverride(input: { id: $id, hostId: $hostId, value: $value, ansibleVariableId: $ansibleVariableId, hiddenValue: $hiddenValue }) { overridenAnsibleVariable { id lookupValues(match: $match) { @@ -15,6 +16,7 @@ mutation UpdateAnsibleVariableOverride( omit } } + hiddenValue currentValue { element value diff --git a/webpack/graphql/queries/hostVariableOverrides.gql b/webpack/graphql/queries/hostVariableOverrides.gql index 69039008c..938d6265f 100644 --- a/webpack/graphql/queries/hostVariableOverrides.gql +++ b/webpack/graphql/queries/hostVariableOverrides.gql @@ -13,6 +13,7 @@ query($id: String!, $match: String, $first: Int, $last: Int) { canEdit } defaultValue + hiddenValue parameterType ansibleRoleName validatorType