Skip to content

Fixes #39328 - Add macro for fetching activation_key_names#11745

Merged
jturel merged 1 commit into
Katello:masterfrom
sayan3296:subs_facet
May 28, 2026
Merged

Fixes #39328 - Add macro for fetching activation_key_names#11745
jturel merged 1 commit into
Katello:masterfrom
sayan3296:subs_facet

Conversation

@sayan3296
Copy link
Copy Markdown
Contributor

@sayan3296 sayan3296 commented May 15, 2026

What are the changes introduced in this pull request?

Added a new macro called activation_key_names that, if used correctly, would help to extract the names of activation keys used to register a content host.

If more than one key was used, then the key names are printed in comma-separated values.

Considerations taken when implementing this change?

While we expose subscription_facet and allow rendering registered_at\through and last_checkin, we don't have any macro that exposes the activation key names, used to register a system, and users are demanding the same.

We already have host_subscription_facet macro present in https://github.com/Katello/katello/blob/master/app/lib/katello/concerns/base_template_scope_extensions.rb#L316-L318 i.e.

      def host_subscription_facet(host)
        host.subscription_facet
      end

We needed to simply do host_subscription_facet(host)&.activation_keys&.map(&:name) to get the activation key names associated with a registered content host.

What are the testing steps for this pull request?

  • Apply the changes from this PR on a centos9-katello-devel env.
  • Register a system with that katello server , using an activation key.
  • Clone the last_checking report template in UI, to a new name, and make it look something like this:
<%- include_unknown_search = input('Include unknown') == 'true' ? ' or null? last_checkin' : '' %>
<%- search += "and #{input('Host filter')}" if input('Host filter').present? -%>
<%- report_headers('Name', 'IP', 'IPv6', 'Last Checkin', 'Registered through', 'AK') -%>
<%- load_hosts(search: search, preload: [ :subscription_facet, :interfaces ]).each_record do |host| -%>
<%-   report_row(
        'Name': host.name,
        'IP': host.ip,
        'IPv6': host.ip6,
        'Last Checkin': last_checkin(host).to_s,
        'Registered through': registered_through(host),
        'AK': activation_key_names(host),
      ) -%>
<%- end -%>
<%= report_render order: 'Last Checkin' -%>

( make sure that you don't have this line there <%- search = "(last_checkin < \"#{input('Interval')} ago\"#{include_unknown_search})" -%> )

  • Now try doing either a preview of this template or else simply generate a csv\html\json report to see how it behaves.

I would expect the AK fields to get populated with right activation key names.

Summary by CodeRabbit

  • New Features
    • Templates can now access activation key names for hosts, allowing template authors to reference host activation keys during configuration and deployment.
    • Safely handles hosts without activation keys by returning an empty result, avoiding errors when keys are absent.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e6641695-a5e4-4197-a953-ba69bf0d16bf

📥 Commits

Reviewing files that changed from the base of the PR and between df1275f and 6ce8c26.

📒 Files selected for processing (1)
  • app/lib/katello/concerns/base_template_scope_extensions.rb
💤 Files with no reviewable changes (1)
  • app/lib/katello/concerns/base_template_scope_extensions.rb

📝 Walkthrough

Walkthrough

Adds activation_key_names(host) to BaseTemplateScopeExtensions; the Apipie-documented method returns a host's activation key names via host_subscription_facet(host).activation_key_names or [] when unavailable.

Changes

Activation Key Names Extension

Layer / File(s) Summary
Activation key names retrieval method
app/lib/katello/concerns/base_template_scope_extensions.rb
Adds activation_key_names(host) instance method with Apipie documentation that safely retrieves activation keys from a host's subscription facet, defaulting to an empty array when unavailable.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

  • nofaralfasi
  • jeremylenz
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a new template macro/method for fetching activation key names to fix issue #39328.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread app/lib/katello/concerns/base_template_scope_extensions.rb Outdated
@jturel jturel self-assigned this May 27, 2026
Copy link
Copy Markdown
Member

@jturel jturel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well, thanks Sayan

@jturel jturel merged commit e52bb97 into Katello:master May 28, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants