diff --git a/app/lib/actions/katello/content_view_environment/destroy.rb b/app/lib/actions/katello/content_view_environment/destroy.rb index cf3b71be1cb..0daca78f1d2 100644 --- a/app/lib/actions/katello/content_view_environment/destroy.rb +++ b/app/lib/actions/katello/content_view_environment/destroy.rb @@ -7,6 +7,11 @@ def plan(cv_env, options = {}) organization_destroy = options.fetch(:organization_destroy, false) content_view = cv_env.content_view environment = cv_env.environment + if cv_env.activation_keys.any?(&:multi_content_view_environment?) + remove_activation_key_associations(cv_env) + plan_self(:id => cv_env.id, :docker_cleanup => false) + return true + end content_view.check_remove_from_environment!(environment) unless organization_destroy docker_cleanup = false sequence do @@ -34,6 +39,12 @@ def finalize end ::Katello::DockerMetaTag.cleanup_tags if input[:docker_cleanup] end + + def remove_activation_key_associations(cv_env) + cv_env.activation_keys.each do |key| + key.content_view_environments = key.content_view_environments - [cv_env] + end + end end end end diff --git a/webpack/scenes/ContentViews/Details/Versions/Delete/RemoveSteps/CVReassignActivationKeysForm.js b/webpack/scenes/ContentViews/Details/Versions/Delete/RemoveSteps/CVReassignActivationKeysForm.js index cffab1454af..cef6d7a3463 100644 --- a/webpack/scenes/ContentViews/Details/Versions/Delete/RemoveSteps/CVReassignActivationKeysForm.js +++ b/webpack/scenes/ContentViews/Details/Versions/Delete/RemoveSteps/CVReassignActivationKeysForm.js @@ -1,12 +1,13 @@ import React, { useState, useContext } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import useDeepCompareEffect from 'use-deep-compare-effect'; -import { ExpandableSection, SelectOption } from '@patternfly/react-core'; +import { ExpandableSection, SelectOption, Alert, AlertActionCloseButton } from '@patternfly/react-core'; import { STATUS } from 'foremanReact/constants'; import { translate as __ } from 'foremanReact/common/I18n'; import EnvironmentPaths from '../../../../components/EnvironmentPaths/EnvironmentPaths'; import getContentViews from '../../../../ContentViewsActions'; import { selectContentViewError, selectContentViews, selectContentViewStatus } from '../../../../ContentViewSelectors'; +import { selectCVActivationKeys } from '../../../ContentViewDetailSelectors'; import AffectedActivationKeys from '../affectedActivationKeys'; import DeleteContext from '../DeleteContext'; import ContentViewSelect from '../../../../components/ContentViewSelect/ContentViewSelect'; @@ -17,9 +18,12 @@ const CVReassignActivationKeysForm = () => { const contentViewsInEnvResponse = useSelector(selectContentViews); const contentViewsInEnvStatus = useSelector(selectContentViewStatus); const contentViewsInEnvError = useSelector(selectContentViewError); + const activationKeysResponse = useSelector(selectCVActivationKeys); const cvInEnvLoading = contentViewsInEnvStatus === STATUS.PENDING; + const [alertDismissed, setAlertDismissed] = useState(false); const [cvSelectOpen, setCVSelectOpen] = useState(false); const [cvSelectOptions, setCvSelectionOptions] = useState([]); + const [multiCVWarning, setMultiCVWarning] = useState(false); const [showActivationKeys, setShowActivationKeys] = useState(false); const { currentStep, selectedEnvForAK, versionEnvironments, cvId, selectedEnvSet, @@ -72,6 +76,14 @@ const CVReassignActivationKeysForm = () => { contentViewsInEnvError, selectedEnvForAK, setSelectedCVForAK, setSelectedCVNameForAK, cvInEnvLoading, selectedCVForAK, cvId, versionEnvironments, selectedEnvSet]); + useDeepCompareEffect(() => { + if (activationKeysResponse?.results) { + const hasMultiCVEnv = activationKeysResponse.results.some(key => + key.multi_content_view_environment); + setMultiCVWarning(hasMultiCVEnv); + } + }, [activationKeysResponse]); + const fetchSelectedCVName = (id) => { const { results } = contentViewsInEnvResponse ?? { }; return results.filter(cv => cv.id === id)[0]?.name; @@ -102,8 +114,21 @@ const CVReassignActivationKeysForm = () => { cvSelectOptions, }); + const multiCVRemovalInfo = __('The current version will be removed from the multi-CV activation keys. The reassignment will not be added to these activation keys in this step. See hammer activation-key --help for more details.'); + return ( <> + {!alertDismissed && multiCVWarning && ( + setAlertDismissed(true)} />} + > +

{multiCVRemovalInfo}

+
+ )} - {results?.map(({ name, id, environment }) => ( + {results?.map(({ + name, id, environment, multi_content_view_environment: multiContentViewEnvironment, + }) => ( {name} + { multiContentViewEnvironment ? 'Yes' : 'No' } )) }