Skip to content

Commit

Permalink
Fixes #37895 - Handle version removal for multi-CV activation key
Browse files Browse the repository at this point in the history
  • Loading branch information
pavanshekar committed Dec 13, 2024
1 parent 363db98 commit eed4a44
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/lib/actions/katello/content_view_environment/destroy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 && (
<Alert
ouiaId="multi-cv-warning-alert"
variant="warning"
isInline
title={__('Warning')}
actionClose={<AlertActionCloseButton onClose={() => setAlertDismissed(true)} />}
>
<p>{multiCVRemovalInfo}</p>
</Alert>
)}
<EnvironmentPaths
userCheckedItems={selectedEnvForAK}
setUserCheckedItems={setSelectedEnvForAK}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const AffectedActivationKeys = ({
const columnHeaders = [
__('Name'),
__('Environment'),
__('Multi Content View Environment'),
];
const emptyContentTitle = __('No matching activation keys found.');
const emptyContentBody = __("Given criteria doesn't match any activation keys. Try changing your rule.");
Expand Down Expand Up @@ -65,12 +66,15 @@ const AffectedActivationKeys = ({
</Tr>
</Thead>
<Tbody>
{results?.map(({ name, id, environment }) => (
{results?.map(({
name, id, environment, multi_content_view_environment: multiContentViewEnvironment,
}) => (
<Tr ouiaId={id} key={id}>
<Td>
<a rel="noreferrer" target="_blank" href={urlBuilder(`activation_keys/${id}`, '')}>{name}</a>
</Td>
<Td><EnvironmentLabels environments={environment} /></Td>
<Td>{ multiContentViewEnvironment ? 'Yes' : 'No' }</Td>
</Tr>
))
}
Expand Down

0 comments on commit eed4a44

Please sign in to comment.