Class: Gitlab::PDF::Security::GroupVulnerabilitiesProjectsGrades

Inherits:
Object
  • Object
show all
Includes:
Prawn::View
Defined in:
lib/gitlab/pdf/security/group_vulnerabilities_projects_grades.rb

Constant Summary collapse

DEFAULT_COUNTS =
'0 projects'
GRADES_DISPLAY_INFO =
{
  a: { color: '#16a34a', severities: [] },
  b: { color: '#f97316', severities: %w[low] },
  c: { color: '#ea580c', severities: %w[medium] },
  d: { color: '#b91c1c', severities: %w[high unknown] },
  f: { color: '#991b1b', severities: %w[critical] }
}.freeze
SVG_STYLES =
<<~SVG_STYLES.freeze
<defs>
  <style>
    .header-text { font-family: sans-serif; font-size: 18px; font-weight: bold; fill: #1f2937; }
    .subheader { font-family: sans-serif; font-size: 13px; fill: #6b7280; }
    .grade-letter { font-family: sans-serif; font-size: 16px; font-weight: bold; }
    .project-count { font-family: sans-serif; font-size: 14px; fill: #1f2937; }
    .description { font-family: sans-serif; font-size: 12px; fill: #6b7280; }
    .severity-count { font-family: sans-serif; font-size: 11px; }
    .grade-f { fill: #{GRADES_DISPLAY_INFO.dig(:f, :color)}; }
    .grade-d { fill: #{GRADES_DISPLAY_INFO.dig(:d, :color)}; }
    .grade-c { fill: #{GRADES_DISPLAY_INFO.dig(:c, :color)}; }
    .grade-b { fill: #{GRADES_DISPLAY_INFO.dig(:b, :color)}; }
    .grade-a { fill: #{GRADES_DISPLAY_INFO.dig(:a, :color)}; }
  </style>
</defs>
SVG_STYLES

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pdf, data) ⇒ GroupVulnerabilitiesProjectsGrades

Returns a new instance of GroupVulnerabilitiesProjectsGrades.



43
44
45
46
47
48
49
50
51
# File 'lib/gitlab/pdf/security/group_vulnerabilities_projects_grades.rb', line 43

def initialize(pdf, data)
  @pdf = pdf
  @grades = process_raw(data)
  @expanded_grade = data&.fetch(:expanded_grade, 'F')
  @gitlab_host_url = Rails.application.routes.url_helpers.root_url.chomp('/')
  @width = 500
  @height = 700
  @y = pdf.cursor
end

Class Method Details

.render(pdf, data: {}) ⇒ Object



39
40
41
# File 'lib/gitlab/pdf/security/group_vulnerabilities_projects_grades.rb', line 39

def self.render(pdf, data: {})
  new(pdf, data).render
end

Instance Method Details

#renderObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/gitlab/pdf/security/group_vulnerabilities_projects_grades.rb', line 53

def render
  return :noop if @grades.blank?

  @pdf.bounding_box([0, @y], width: @pdf.bounds.right, height: @height) do
    @pdf.save_graphics_state
    @pdf.fill_color "F9F9F9"
    @pdf.fill_rectangle [0, @pdf.bounds.top], @pdf.bounds.right, @height
    @pdf.restore_graphics_state

    @pdf.text_box(
      s_('Project security status'),
      at: [0, @pdf.bounds.top - 10],
      width: @pdf.bounds.right,
      align: :center,
      style: :bold,
      size: 16
    )

    @pdf.text_box(
      s_('Projects are graded based on the highest severity vulnerability present'),
      at: [0, @pdf.bounds.top - 40],
      width: @pdf.bounds.right,
      align: :center,
      size: 12
    )

    svg = build_base_svg
    @pdf.svg svg, at: [0, @pdf.cursor]

    render_project_names
  end
end