Bug 2270505

Summary: No way to print the current time along with current date while generating a report template in Red Hat Satellite 6
Product: Red Hat Satellite Reporter: Sayan Das <saydas>
Component: ReportingAssignee: satellite6-bugs <satellite6-bugs>
Status: CLOSED MIGRATED QA Contact: Satellite QE Team <sat-qe-bz-list>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.14.2CC: pcreech, rlavi
Target Milestone: UnspecifiedKeywords: EasyFix, MigratedToJIRA, Triaged
Target Release: Unused   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2024-06-06 17:26:31 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Sayan Das 2024-03-20 15:50:03 UTC
Description of problem:

For some end-users it might be needed to print the report generation time and date both in the report itself. 

We have a global macro present for printing the date only i.e. current_date . We also have a macro present to format the time if a valid time input present i.e. forman_time but none of them can give me the Full date and time.

The end-result always is just Date or else Date with broken time.


Version-Release number of selected component (if applicable):

Any version of Red Hat Satellite 6 ( Tested on 6.14 )


How reproducible:

100%


Steps to Reproduce:
1. Create a report template by name test and just add these lines

<%= current_date + "\n" -%>
<%= format_time(current_date) + "\n" -%>

2. Preview\Render the template

3. Check in the Help tab for a current_time macro to work with


Actual results:

3. No such macro exists

2. Rendering results:

2024-03-20
2024-03-20  0:00:00 +0530

The time is wrong


Expected results:

There should be a macro present to print the current time as well. 

Additional info:

NA

Comment 1 Sayan Das 2024-03-20 15:51:17 UTC
This fixes the issue:

# git diff
diff --git a/app/services/foreman/renderer/configuration.rb b/app/services/foreman/renderer/configuration.rb
index 4d8b65e..db7744f 100644
--- a/app/services/foreman/renderer/configuration.rb
+++ b/app/services/foreman/renderer/configuration.rb
@@ -58,6 +58,7 @@ module Foreman
         :shell_escape,
         :join_with_line_break,
         :current_date,
+        :current_time,
         :truthy?,
         :falsy?,
         :previous_revision,
diff --git a/app/services/foreman/renderer/scope/macros/helpers.rb b/app/services/foreman/renderer/scope/macros/helpers.rb
index f91f54a..1d4cf58 100644
--- a/app/services/foreman/renderer/scope/macros/helpers.rb
+++ b/app/services/foreman/renderer/scope/macros/helpers.rb
@@ -109,6 +109,15 @@ module Foreman
             Time.zone.today.strftime(format)
           end
 
+          apipie :method, 'Returns current time' do
+            keyword :format, String, desc: 'Format string to format time according to the directives in this string', default: '%T %z'
+            returns String
+            example '<%= current_time %> #=> "21:05:09 +0530"'
+          end
+          def current_time(format: '%T %z')
+            Time.zone.now.strftime(format)
+          end
+
           apipie :method, 'Checks whether a value is truthy or not' do
             optional :value, Object, desc: 'Value to check'
             returns one_of: [true, false], desc: 'Returns true if the value can be considered as truthy, false otherwise'



And now I can use this i.e. 

<%= current_date + ' ' + current_time + "\n" -%>

which will print 

2024-03-20 21:20:56 +0530


I will send a upstream PR about it

Comment 2 Sayan Das 2024-03-20 16:06:52 UTC
Connecting:

Feature #37282: Add current time macro - Foreman
https://projects.theforeman.org/issues/37282

Fixes #37282 - Adding the current_time macro by sayan3296 · Pull Request #10105 · theforeman/foreman
https://github.com/theforeman/foreman/pull/10105

Comment 3 Bryan Kearney 2024-03-21 16:07:38 UTC
Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/37282 has been resolved.

Comment 4 Eric Helms 2024-06-06 17:26:31 UTC
This BZ has been automatically migrated to the issues.redhat.com Red Hat Issue Tracker. All future work related to this report will be managed there.

Due to differences in account names between systems, some fields were not replicated.  Be sure to add yourself to Jira issue's "Watchers" field to continue receiving updates and add others to the "Need Info From" field to continue requesting information.

To find the migrated issue, look in the "Links" section for a direct link to the new issue location. The issue key will have an icon of 2 footprints next to it, and begin with "SAT-" followed by an integer.  You can also find this issue by visiting https://issues.redhat.com/issues/?jql= and searching the "Bugzilla Bug" field for this BZ's number, e.g. a search like:

"Bugzilla Bug" = 1234567

In the event you have trouble locating or viewing this issue, you can file an issue by sending mail to rh-issues. You can also visit https://access.redhat.com/articles/7032570 for general account information.