dradis-html_export 3.15.0 → 3.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3bb233fc308356f8613baeef2ed7351abe6e92b95d166b5f15b33d76af86e222
4
- data.tar.gz: c3f4e9a1fd1c71759f09a853c4f2d02a9860708e5ba0e4e2751f4cff3c77542d
3
+ metadata.gz: 5f6ac583114b620b0f712eec9d0d4635012a0566e1b6b5bf6e331b708991c223
4
+ data.tar.gz: 571a3c231cddac14d08577f6811dd8beab715a0387fc763a99ce57b8340e9110
5
5
  SHA512:
6
- metadata.gz: 9464ccc7a9ea7f6cb1e66fa70444e5c699dfe4dc6230953ab5eee4e77690429862afce59dee11006aaaab901c34c3e50a4e7d9be94a974d637bfca94c29a9507
7
- data.tar.gz: f3ee8071c3b12efffc403e159a11f39aef17beaf0a657e081a3aa0a399f38d91c4338f9d4dba76c40bc91abd9cdef89d2df7125dd1751184c2919f88fdf1976c
6
+ metadata.gz: 6700179c827068d2810787d028bdc0621f918e86588d7c666547e7ea00be5425e141b15740cab0b0afe359021f13e28e1300c4a03edd87e7e2b86cd0b6adb1b8
7
+ data.tar.gz: 36b73d54c2167cf49063882d9521e6954562331a3edc4464ec77b3f951302ad8ebc20ded1b9a7d996acc369e2000364ee916b0d2e6a5b1a2038d43ae6a7b1800
@@ -1,11 +1,29 @@
1
- ## Dradis Framework 3.15 (November, 2019) ##
1
+ ## Dradis Framework 3.20 (December, 2020) ##
2
+
3
+ * Add an option in the exporter to pass a controller for rendering.
4
+ * Use NamingService to build export filename.
5
+
6
+ ## Dradis Framework 3.19 (September, 2020) ##
2
7
 
3
8
  * No changes.
4
9
 
5
- ## Dradis Framework 3.15 (August, 2019) ##
10
+ ## Dradis Framework 3.18 (July, 2020) ##
6
11
 
7
12
  * No changes.
8
13
 
14
+ ## Dradis Framework 3.17 (May, 2020) ##
15
+
16
+ * Render report using main app's ApplicationController#render.
17
+
18
+ ## Dradis Framework 3.16 (February, 2020) ##
19
+
20
+ * No changes.
21
+
22
+ ## Dradis Framework 3.15 (November, 2019) ##
23
+
24
+ * No changes.
25
+
26
+
9
27
  ## Dradis Framework 3.14 (August, 2019) ##
10
28
 
11
29
  * No changes.
@@ -3,75 +3,96 @@ module Dradis
3
3
  module HtmlExport
4
4
 
5
5
  class Exporter < Dradis::Plugins::Export::Base
6
- # Add auto_link support to the ERB processor (see rails_autolink)
7
- include ::ActionView::Helpers::TextHelper
8
- # For auto_link feature (requires #mail_to)
9
- include ::ActionView::Helpers::UrlHelper
10
6
 
11
7
  def export(args = {})
12
- template_path = options.fetch(:template)
13
- template_properties = ::ReportTemplateProperties.find_by_template_file(File.basename(template_path)) rescue nil
14
-
15
- # Build title
16
- title = if Dradis.constants.include?(:Pro)
17
- "Dradis Professional Edition v#{Dradis::Pro.version}"
18
- else
19
- "Dradis Community Edition v#{Dradis::CE.version}"
20
- end
21
- logger.debug{ "Report title: #{title}"}
22
-
23
- # Prepare notes
24
- reporting_cat = content_service.report_category
25
- notes = content_service.all_notes
26
- logger.debug{ "Found #{notes.count} notes assigned to the reporting category."}
27
-
28
- # Prepare issues
29
- issues = content_service.all_issues
30
- if issues
31
- # Sort our issues based on the ReportTemplateProperties rules.
32
- if template_properties && template_properties.sort_field
33
- sort_by = template_properties.sort_field
34
-
35
- logger.debug{ "Template properties define a sort field: #{sort_by}. Sorting..." }
36
-
37
- # FIXME: Assume the Field :type is :number, so cast .to_f and sort
38
- issues.to_a.sort! do |a, b|
39
- b.fields.fetch(sort_by, '0').to_f <=> a.fields.fetch(sort_by, '0').to_f
40
- end
41
-
42
- logger.debug{ "Done." }
43
- end
8
+ log_report
9
+
10
+ controller = args[:controller] || ApplicationController
11
+
12
+ # Render template
13
+ controller.render(
14
+ file: options.fetch(:template),
15
+ layout: false,
16
+ locals: {
17
+ categorized_issues: categorized_issues,
18
+ content_service: content_service,
19
+ issues: issues,
20
+ nodes: nodes,
21
+ notes: notes,
22
+ project: project,
23
+ reporting_cat: content_service.report_category,
24
+ tags: tags,
25
+ title: title,
26
+ user: options[:user]
27
+ }
28
+ )
29
+ end
44
30
 
45
- # FIXME: This is an ugly piece of code and the list of nodes should
46
- # come from the ContentService.
47
- nodes = issues.map(&:evidence).flatten.map(&:node).uniq
31
+ private
32
+ def log_report
33
+ logger.debug { "Report title: #{title}" }
34
+ logger.debug { "Template properties define a sort field: #{sort_field}" }
48
35
 
49
- logger.debug{ "Found #{issues.count} issues affecting #{nodes.count} nodes" }
36
+ if issues&.any?
37
+ logger.debug { "Found #{issues.count} issues affecting #{nodes.count} nodes" }
50
38
  else
51
- logger.warning { "No issue library node found in this project" }
39
+ logger.warn { 'No issue library node found in this project' }
52
40
  end
53
41
 
54
- # Render template
55
- erb = ERB.new( File.read(template_path) )
56
- erb.result( binding )
42
+ logger.debug { "Found #{notes.count} notes assigned to the reporting category." }
57
43
  end
58
44
 
59
- private
45
+ def nodes
46
+ # FIXME: This is an ugly piece of code and the list of nodes should
47
+ # come from the ContentService.
48
+ @nodes ||= issues.map(&:evidence).flatten.map(&:node).uniq
49
+ end
50
+
51
+ def notes
52
+ @notes ||= content_service.all_notes
53
+ end
60
54
 
61
- # FIXME This method is a behavioural duplicate of ApplicationHelper#markup
62
- # from the main app, it would be better to re-use that code.
63
- def markup(text)
64
- return unless text.present?
55
+ def issues
56
+ @issues ||= sort_issues content_service.all_issues.includes(:tags)
57
+ end
65
58
 
66
- # escape HTML 'manually' instead of using RedCloth's "filter_html"
67
- # for security reasons
68
- output = ERB::Util.html_escape(text.dup)
59
+ def categorized_issues
60
+ @categorized_issues ||= tags
61
+ .each_with_object({}) do |tag, hash|
62
+ hash[tag.id] = issues.select { |issue| issue.tags.include?(tag) }
63
+ end
64
+ .tap do |hash|
65
+ hash[:untagged] = issues.select { |issue| issue.tags.empty? }
66
+ end
67
+ end
69
68
 
70
- Hash[ *text.scan(/#\[(.+?)\]#[\r|\n](.*?)(?=#\[|\z)/m).flatten.collect{ |str| str.strip } ].keys.each do |field|
71
- output.gsub!(/#\[#{Regexp.escape(field)}\]#[\r|\n]/, "h4. #{field}\n\n")
69
+ def sort_field
70
+ @sort_field ||= begin
71
+ template_path = options.fetch(:template)
72
+ properties = ::ReportTemplateProperties.find_by_template_file(File.basename(template_path)) rescue nil
73
+ properties&.sort_field
72
74
  end
75
+ end
76
+
77
+ def sort_issues(unsorted_issues)
78
+ return unsorted_issues unless unsorted_issues.any? && sort_field
79
+
80
+ # FIXME: Assume the Field :type is :number, so cast .to_f and sort
81
+ unsorted_issues.sort do |a, b|
82
+ b.fields.fetch(sort_field, '0').to_f <=> a.fields.fetch(sort_field, '0').to_f
83
+ end
84
+ end
85
+
86
+ def tags
87
+ @tags ||= project.tags
88
+ end
73
89
 
74
- auto_link(RedCloth.new(output, [:no_span_caps]).to_html).html_safe
90
+ def title
91
+ @title ||= if Dradis.constants.include?(:Pro)
92
+ "Dradis Professional Edition v#{Dradis::Pro.version}"
93
+ else
94
+ "Dradis Community Edition v#{Dradis::CE.version}"
95
+ end
75
96
  end
76
97
  end
77
98
  end
@@ -8,7 +8,7 @@ module Dradis
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 3
11
- MINOR = 15
11
+ MINOR = 20
12
12
  TINY = 0
13
13
  PRE = nil
14
14
 
@@ -15,9 +15,15 @@ class HtmlExportTasks < Thor
15
15
 
16
16
  report_path = options.output || Rails.root
17
17
  unless report_path.to_s =~ /\.html\z/
18
- date = DateTime.now.strftime("%Y-%m-%d")
19
- sequence = Dir.glob(File.join(report_path, "dradis-report_#{date}_*.html")).collect { |a| a.match(/_([0-9]+)\.html\z/)[1].to_i }.max || 0
20
- report_path = File.join(report_path, "dradis-report_#{date}_#{sequence + 1}.html")
18
+ date = DateTime.now.strftime("%Y-%m-%d")
19
+ base_filename = "dradis-report_#{date}.html"
20
+
21
+ report_filename = NamingService.name_file(
22
+ original_filename: base_filename,
23
+ pathname: Pathname.new(report_path)
24
+ )
25
+
26
+ report_path = File.join(report_path, report_filename)
21
27
  end
22
28
 
23
29
  if template = options.template
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dradis-html_export
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.15.0
4
+ version: 3.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Martin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-11 00:00:00.000000000 Z
11
+ date: 2021-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dradis-plugins
@@ -87,7 +87,7 @@ homepage: http://dradisframework.org
87
87
  licenses:
88
88
  - GPL-2
89
89
  metadata: {}
90
- post_install_message:
90
+ post_install_message:
91
91
  rdoc_options: []
92
92
  require_paths:
93
93
  - lib
@@ -102,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubygems_version: 3.0.1
106
- signing_key:
105
+ rubygems_version: 3.2.4
106
+ signing_key:
107
107
  specification_version: 4
108
108
  summary: Dradis HTML export plugin
109
109
  test_files: