dradis-html_export 3.16.0 → 3.17.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: 8e2bed448d7dd1b3038207793b3c1b22163d93b8cb8caaacac94c3232ac4b11f
4
- data.tar.gz: f56b207d4739c5eacde0cfa506aef41e41942dc7145cb632737e7f6296c071ec
3
+ metadata.gz: 8ff810f1056abb025188e810af787950b710ed140b919a3c4c8e28750bbdb757
4
+ data.tar.gz: 0bf32f0708e38397d807df364ac6a781f23c2cf4a2aaeaf930830e2745c98f8d
5
5
  SHA512:
6
- metadata.gz: a055468ffac66d7a13bb0d52fd60b4430421d834bc866d70510a70d6e1619fce75b96201c4ca12fe2462eef831ba9f4f4e89a757942132d008565dffed84ca63
7
- data.tar.gz: '096bc01b204b281c1a43f502a5cd6d16d827c7388229acb90f496a7ee858c3d1cf6d70f477869568ee034d69559a7133e2b183e3165521d02c34253438a0f7ab'
6
+ metadata.gz: b85f5c997dbe5664c007ef8b1c40010cf38e123bf57360a5ddf32b6686d33b79ae9d5dc411913945fa5c97f18f8c259c960a1710cb414ee2dea117519234d177
7
+ data.tar.gz: 6a60cacc47c5fbe64431a9f47865dff2f3fa645e53c1d2b13fb733a279b63794cd9e7f6c610bfe996083dc6d3ecb8e9caf723b5f8a77206e8a73a60eaf4cce52
@@ -1,3 +1,7 @@
1
+ ## Dradis Framework 3.17 (May, 2020) ##
2
+
3
+ * Render report using main app's ApplicationController#render.
4
+
1
5
  ## Dradis Framework 3.16 (February, 2020) ##
2
6
 
3
7
  * No changes.
@@ -6,9 +10,6 @@
6
10
 
7
11
  * No changes.
8
12
 
9
- ## Dradis Framework 3.15 (August, 2019) ##
10
-
11
- * No changes.
12
13
 
13
14
  ## Dradis Framework 3.14 (August, 2019) ##
14
15
 
@@ -3,75 +3,94 @@ 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
8
+ log_report
14
9
 
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
10
+ # Render template
11
+ ApplicationController.render(
12
+ file: options.fetch(:template),
13
+ layout: false,
14
+ locals: {
15
+ categorized_issues: categorized_issues,
16
+ content_service: content_service,
17
+ issues: issues,
18
+ nodes: nodes,
19
+ notes: notes,
20
+ project: project,
21
+ reporting_cat: content_service.report_category,
22
+ tags: tags,
23
+ title: title,
24
+ user: options[:user]
25
+ }
26
+ )
27
+ end
34
28
 
35
- logger.debug{ "Template properties define a sort field: #{sort_by}. Sorting..." }
29
+ private
30
+ def log_report
31
+ logger.debug { "Report title: #{title}" }
32
+ logger.debug { "Template properties define a sort field: #{sort_field}" }
36
33
 
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
34
+ if issues&.any?
35
+ logger.debug { "Found #{issues.count} issues affecting #{nodes.count} nodes" }
36
+ else
37
+ logger.warn { 'No issue library node found in this project' }
38
+ end
41
39
 
42
- logger.debug{ "Done." }
43
- end
40
+ logger.debug { "Found #{notes.count} notes assigned to the reporting category." }
41
+ end
44
42
 
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
43
+ def nodes
44
+ # FIXME: This is an ugly piece of code and the list of nodes should
45
+ # come from the ContentService.
46
+ @nodes ||= issues.map(&:evidence).flatten.map(&:node).uniq
47
+ end
48
48
 
49
- logger.debug{ "Found #{issues.count} issues affecting #{nodes.count} nodes" }
50
- else
51
- logger.warning { "No issue library node found in this project" }
52
- end
49
+ def notes
50
+ @notes ||= content_service.all_notes
51
+ end
53
52
 
54
- # Render template
55
- erb = ERB.new( File.read(template_path) )
56
- erb.result( binding )
53
+ def issues
54
+ @issues ||= sort_issues content_service.all_issues.includes(:tags)
57
55
  end
58
56
 
59
- private
57
+ def categorized_issues
58
+ @categorized_issues ||= tags
59
+ .each_with_object({}) do |tag, hash|
60
+ hash[tag.id] = issues.select { |issue| issue.tags.include?(tag) }
61
+ end
62
+ .tap do |hash|
63
+ hash[:untagged] = issues.select { |issue| issue.tags.empty? }
64
+ end
65
+ end
60
66
 
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?
67
+ def sort_field
68
+ @sort_field ||= begin
69
+ template_path = options.fetch(:template)
70
+ properties = ::ReportTemplateProperties.find_by_template_file(File.basename(template_path)) rescue nil
71
+ properties&.sort_field
72
+ end
73
+ end
65
74
 
66
- # escape HTML 'manually' instead of using RedCloth's "filter_html"
67
- # for security reasons
68
- output = ERB::Util.html_escape(text.dup)
75
+ def sort_issues(unsorted_issues)
76
+ return unsorted_issues unless unsorted_issues.any? && sort_field
69
77
 
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")
78
+ # FIXME: Assume the Field :type is :number, so cast .to_f and sort
79
+ unsorted_issues.sort do |a, b|
80
+ b.fields.fetch(sort_field, '0').to_f <=> a.fields.fetch(sort_field, '0').to_f
72
81
  end
82
+ end
83
+
84
+ def tags
85
+ @tags ||= project.tags
86
+ end
73
87
 
74
- auto_link(RedCloth.new(output, [:no_span_caps]).to_html).html_safe
88
+ def title
89
+ @title ||= if Dradis.constants.include?(:Pro)
90
+ "Dradis Professional Edition v#{Dradis::Pro.version}"
91
+ else
92
+ "Dradis Community Edition v#{Dradis::CE.version}"
93
+ end
75
94
  end
76
95
  end
77
96
  end
@@ -8,7 +8,7 @@ module Dradis
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 3
11
- MINOR = 16
11
+ MINOR = 17
12
12
  TINY = 0
13
13
  PRE = nil
14
14
 
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.16.0
4
+ version: 3.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-26 00:00:00.000000000 Z
11
+ date: 2020-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dradis-plugins