class Dradis::Plugins::HtmlExport::Exporter
Public Instance Methods
export(args = {})
click to toggle source
# File lib/dradis/plugins/html_export/exporter.rb, line 6 def export(args = {}) log_report controller = args[:controller] || ApplicationController with_temporary_template(options[:template]) do |temporary_template| # Render template controller.render( template: temporary_template, layout: false, locals: { categorized_issues: categorized_issues, content_service: content_service, issues: issues, nodes: nodes, notes: notes, project: project, reporting_cat: content_service.report_category, tags: tags, title: title, user: options[:user] } ) end end
Private Instance Methods
categorized_issues()
click to toggle source
# File lib/dradis/plugins/html_export/exporter.rb, line 60 def categorized_issues @categorized_issues ||= tags .each_with_object({}) do |tag, hash| hash[tag.id] = issues.select { |issue| issue.tags.include?(tag) } end .tap do |hash| hash[:untagged] = issues.select { |issue| issue.tags.empty? } end end
issues()
click to toggle source
# File lib/dradis/plugins/html_export/exporter.rb, line 56 def issues @issues ||= sort_issues content_service.all_issues.includes(:tags) end
log_report()
click to toggle source
# File lib/dradis/plugins/html_export/exporter.rb, line 33 def log_report logger.debug { "Report title: #{title}" } logger.debug { "Template properties define a sort field: #{sort_field}" } if issues&.any? logger.debug { "Found #{issues.count} issues affecting #{nodes.count} nodes" } else logger.warn { 'No issue library node found in this project' } end logger.debug { "Found #{notes.count} notes assigned to the reporting category." } end
nodes()
click to toggle source
# File lib/dradis/plugins/html_export/exporter.rb, line 46 def nodes # FIXME: This is an ugly piece of code and the list of nodes should # come from the ContentService. @nodes ||= issues.map(&:evidence).flatten.map(&:node).uniq end
notes()
click to toggle source
# File lib/dradis/plugins/html_export/exporter.rb, line 52 def notes @notes ||= content_service.all_notes end
sort_field()
click to toggle source
# File lib/dradis/plugins/html_export/exporter.rb, line 70 def sort_field @sort_field ||= begin template_path = options.fetch(:template) properties = ::ReportTemplateProperties.find_by_template_file(File.basename(template_path)) rescue nil properties&.sort_field end end
sort_issues(unsorted_issues)
click to toggle source
# File lib/dradis/plugins/html_export/exporter.rb, line 78 def sort_issues(unsorted_issues) return unsorted_issues unless unsorted_issues.any? && sort_field # FIXME: Assume the Field :type is :number, so cast .to_f and sort unsorted_issues.sort do |a, b| b.fields.fetch(sort_field, '0').to_f <=> a.fields.fetch(sort_field, '0').to_f end end
title()
click to toggle source
# File lib/dradis/plugins/html_export/exporter.rb, line 91 def title @title ||= if Dradis.constants.include?(:Pro) "Dradis Professional Edition v#{Dradis::Pro.version}" else "Dradis Community Edition v#{Dradis::CE.version}" end end
with_temporary_template(original) { |"tmp/#{filename}"| ... }
click to toggle source
# File lib/dradis/plugins/html_export/exporter.rb, line 99 def with_temporary_template(original, &block) filename = File.basename(Dir::Tmpname.create(['', '.html.erb']) {}) destination_path = Rails.root.join('app', 'views', 'tmp', filename) FileUtils.mkdir_p(File.dirname(destination_path)) FileUtils.cp(original, destination_path) yield("tmp/#{filename}") ensure file_path = Rails.root.join("app/views/tmp/#{filename}") File.delete(file_path) if File.exists?(file_path) end