Sha256: a92d6d60590bdcf48886dc11fc70c4aacd44e34f5b8f58d46cfc458907ad2ce6

Contents?: true

Size: 1.92 KB

Versions: 27

Compression:

Stored size: 1.92 KB

Contents

module HammerCLIForeman

  class Audit < HammerCLIForeman::Command

    resource :audits

    class ListCommand < HammerCLIForeman::ListCommand

      def request_params
        params = super
        params['search'] ||= 'time >= "1 month ago"'
        params
      end

      def self.included(base)
        base.extend_help do |h|
          h.section(_('Override audit record pagination')) do
            h.text(_('Audit records for past one month are returned by default. This behavior can be changed by passing --search option.'))
          end
        end
      end

      output do
        field :id, _("Id")
        field :created_at, _("At"), Fields::Date
        field :remote_address, _("IP")
        field nil, _("User"), Fields::SingleReference, :key => :user
        field :action, _("Action")
        field :auditable_type, _("Audit type")
        field nil, _("Audit record"), Fields::SingleReference, :key => :auditable
      end

      build_options
    end


    class InfoCommand < HammerCLIForeman::InfoCommand

      def extend_data(audit)
        audit["changes"] = audit["audited_changes"].map do |attribute, change|
          if change.is_a?(Array)
            {
              'attribute' => attribute,
              'old' => (change[0] ? change[0] : change[0].to_s),
              'new' => change[1]
            }
          elsif !change.nil?
            {
              'attribute' => attribute,
              'value' => change
            }
          end
        end.compact
        audit
      end

      output ListCommand.output_definition do
        collection :changes, _("Audited changes") do
          field :attribute, _("Attribute")
          field :value, _("Value"), Fields::Field, :hide_blank => true
          field :old, _("Old"), Fields::LongText, :hide_blank => true
          field :new, _("New"), Fields::LongText, :hide_blank => true
        end
      end

      build_options
    end

    autoload_subcommands
  end

end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
hammer_cli_foreman-2.1.1 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-2.1.0 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-2.0.2 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-2.0.1 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-2.0.0 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.19.7 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.19.6 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.19.5 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.19.4 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.19.3 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.19.2 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.18.2 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.19.1 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.18.1 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.19.0 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.17.2 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.18.0 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.17.1 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.17.0 lib/hammer_cli_foreman/audit.rb
hammer_cli_foreman-0.15.2 lib/hammer_cli_foreman/audit.rb