-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #38116 - Handle version removal for multi-CV hosts #11282
base: master
Are you sure you want to change the base?
Conversation
3f31f26
to
30729ca
Compare
a5ddfe2
to
fef992a
Compare
fcced92
to
fb6ccbf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good! some initial comments
const multiCVWarning = hostResponse?.results?.some?.(host => | ||
host.content_facet_attributes?.multi_content_view_environment); | ||
|
||
const multiCVRemovalInfo = __('This environment is used in one or more hosts. The environment will simply be removed from the multi-environment hosts. The content view and lifecycle environment you select here will only apply to single-environment host. See hammer activation-key --help for more details.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const multiCVRemovalInfo = __('This environment is used in one or more hosts. The environment will simply be removed from the multi-environment hosts. The content view and lifecycle environment you select here will only apply to single-environment host. See hammer activation-key --help for more details.'); | |
const multiCVRemovalInfo = __('This content view version is used in one or more multi-environment hosts. The version will simply be removed from the multi-environment hosts. The content view and lifecycle environment you select here will only apply to single-environment hosts. See hammer activation-key --help for more details.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack...
<FlexItem><ExclamationTriangleIcon /></FlexItem> | ||
<FlexItem> | ||
<p> | ||
{__(`Content view environment will be removed from ${pluralize(multiCVHostsCount, 'multi-environment host')}.`)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also include the content view environment's label? "Content view environment envX/cvX will be removed.."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have included and pushed the updated code
plan_action(Host::Reassign, host, options[:system_content_view_id], options[:system_environment_id]) | ||
content_facet_attributes = host.content_facet | ||
if content_facet_attributes.multi_content_view_environment? | ||
content_facet_attributes.content_view_environments -= [content_view_environment] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to self for testing: Need to make sure this calls #content_view_environments=
so that the priority is properly updated.
fb6ccbf
to
bf66961
Compare
1a5884f
to
7b52bbd
Compare
<p> | ||
{__(`Content view environment | ||
${selectedEnv | ||
?.map(({ name }) => `${name}/${multiCVHosts[0]?.content_facet_attributes?.content_view?.name}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sjha4 Is there a less awkward way this CVE label could be assembled?
{__(`Content view environment | ||
${selectedEnv | ||
?.map(({ name }) => `${name}/${multiCVHosts[0]?.content_facet_attributes?.content_view?.name}`) | ||
.join(', ')} | ||
will be removed from ${pluralize(multiCVHostsCount, 'multi-environment host')}.`)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using ${...}
, the __()
won't properly translate the string. We should use something similar to this:
katello/webpack/scenes/Hosts/ChangeContentSource/components/ContentSourceForm.js
Lines 248 to 264 in 527df0a
<FormattedMessage | |
defaultMessage={__('After configuring Foreman, configuration must also be updated on {hosts}. Choose one of the following options to update {hosts}:')} | |
values={{ | |
hosts: ( | |
<FormattedMessage | |
defaultMessage="{count, plural, one {{singular}} other {# {plural}}}" | |
values={{ | |
count: hostCount, | |
singular: __('the host'), | |
plural: __('hosts'), | |
}} | |
id="ccs-options-i18n" | |
/> | |
), | |
}} | |
id="ccs-options-description-i18n" | |
/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack...
{singleCVActivationKeysCount > 0 && ( | ||
<Flex> | ||
<FlexItem><ExclamationTriangleIcon /></FlexItem> | ||
<FlexItem><p>{__(`${pluralize(singleCVActivationKeysCount, 'activation key')} will be moved to content view ${selectedCVNameForAK} in `)}</p></FlexItem> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here; please use FormattedMessage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack...
}) => ( | ||
<Tr ouiaId={id} key={id}> | ||
<Td> | ||
<a rel="noreferrer" target="_blank" href={urlBuilder(`new/hosts/${id}`, '')}>{name}</a> | ||
</Td> | ||
<Td><EnvironmentLabels environments={environment} /></Td> | ||
<Td>{ multiContentViewEnvironment ? 'Yes' : 'No' }</Td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<Td>{ multiContentViewEnvironment ? 'Yes' : 'No' }</Td> | |
<Td>{ multiContentViewEnvironment ? __('Yes') : __('No') }</Td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made the suggested changes and pushed the code
c9c6b5a
to
a019aca
Compare
@@ -192,7 +193,7 @@ test('Can open Remove wizard and remove version from environment with hosts', as | |||
fireEvent.click(getByText('Next')); | |||
await patientlyWaitFor(() => { | |||
expect(getByText('Review details')).toBeInTheDocument(); | |||
expect(getByText('1 host will be moved to content view cv2 in')).toBeInTheDocument(); | |||
expect(getByTestId('single-cv-hosts-remove')).toBeInTheDocument(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated test case to use getTestById for reliable assertion of FormattedMessage, as its text spans multiple elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and seems to work as expected, except for one comment below.
<FlexItem data-testid="single-cv-hosts-remove"> | ||
<FormattedMessage | ||
id="single-cv-hosts-remove" | ||
defaultMessage="{count, plural, one {{singular}} other {# {plural}}} will be moved to content view {cvName} in {envName}." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<FlexItem data-testid="single-cv-activation-keys-remove"> | ||
<FormattedMessage | ||
id="single-cv-activation-keys-remove" | ||
defaultMessage="{count, plural, one {{singular}} other {# {plural}}} will be moved to content view {cvName} in {envName}." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultMessage="{count, plural, one {{singular}} other {# {plural}}} will be moved to content view {cvName} in {envName}." | |
defaultMessage="{count, plural, one {# {singular}} other {# {plural}}} will be moved to content view {cvName} in {envName}." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another edge case I found:
The correct content view environment label for "Library/Default Organization View" should just be "Library" (without the "Default Organization View").
I'm thinking it may be best to alter the rabl somehow to provide the correct content view environment labels, and then we wouldn't have to assemble them on the frontend..
defaultMessage="Content view {envSingularOrPlural} {envCV} will be removed from {count, plural, one {# {keySingular}} other {# {keyPlural}}}." | ||
values={{ | ||
envSingularOrPlural: selectedEnv?.length === 1 ? __('environment') : __('environments'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These plurals will not be properly translated, since plural rules can be different in different languages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have resolved the edge case and the plurals translation issue and pushed the updated code. The changes have been implemented in the frontend because other pages are using rabl for rendering. Please let me know if this approach is okay.
a019aca
to
2c5fdfd
Compare
<FormattedMessage | ||
id="environment.plural" | ||
defaultMessage="{count, plural, one {environment} other {environments}}" | ||
values={{ count: selectedEnv?.length }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values
object must contain values for every placeholder in the defaultMessage
string. Looks like this one is missing environment
and environments
<FlexItem> | ||
<FormattedMessage | ||
id="multi-cv-hosts-remove" | ||
defaultMessage="Content view {envSingularOrPlural} {envCV} will be removed from {count, plural, one {# {hostSingular}} other {# {hostPlural}}}." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plural
isn't defined. I think maybe it needs this?
defaultMessage="Content view {envSingularOrPlural} {envCV} will be removed from {count, plural, one {# {hostSingular}} other {# {hostPlural}}}." | |
defaultMessage="Content view {envSingularOrPlural} {envCV} will be removed from {count, hostPlural, one {# {hostSingular}} other {# {hostPlural}}}." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the formatted message for correct translations. The plural
keyword is used to handle singular and plural forms based on the hostCount
value.
</p> | ||
<FormattedMessage | ||
id="multi-cv-activation-keys-remove" | ||
defaultMessage="Content view {envSingularOrPlural} {envCV} will be removed from {count, plural, one {# {keySingular}} other {# {keyPlural}}}." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, missing definition for plural
2c5fdfd
to
b2b0a88
Compare
), | ||
envCV: selectedCVE | ||
?.map(cve => cve.label) | ||
.join(', '), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated and optimized the logic, making it more concise.
b2b0a88
to
74bb1c8
Compare
What are the changes introduced in this pull request?
Added checks for multi-CV host associations and helper methods to handle version removal from the environment, ensuring that relevant content facets and environment links are cleaned up. This ensures that only the targeted version is removed without affecting unrelated associations or environments.
Considerations taken when implementing this change?
Ensured selective removal of associations for multi-CV hosts to avoid reassigning hosts linked to single CVEs or impacting unrelated environments, while preserving existing associations and removing only the targeted version from the hosts' content facets. Existing methods were reused for consistency and to minimize duplication, and checks were added to handle edge cases, such as multiple hosts linked to the same environment, to prevent unintended side effects.
What are the testing steps for this pull request?
Create a multi-CV activation key
Example command: hammer activation-key update --organization="Default Organization" --id=1 --content-view-environments="ABC/cv1,XYZ/cv1"
Assign and register multiple hosts using the multi-CV activation key
Remove the version from the environment