summaryrefslogtreecommitdiff
blob: b21eded2dca94a81e1c2c652529aa46b296db957 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# ===GLSAMaker v2
#  Copyright (C) 2009 Alex Legler <a3li@gentoo.org>
#  Copyright (C) 2009 Pierre-Yves Rofes <py@gentoo.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# For more information, see the LICENSE file.

# GLSA Helper
module GlsaHelper
  
  def glsa_content(g, field)
    (params[:glsa][field.to_sym] if params[:glsa]) || g[field]
  end
  
  def lastrev_content(g, field)
    (params[:glsa][field.to_sym] if params[:glsa]) || g.last_revision[field]
  end
  
  def add_vulnerable_package_link(name)
    link_to_function name, :title => "Add package" do |page|
      page.insert_html :bottom, :packages_table_vulnerable, :partial => 'package', :object => Package.new(:comp => "<", :arch => "*", :my_type => "vulnerable")
    end
  end

  def add_unaffected_package_link(name)
    link_to_function name, :title => "Add package" do |page|
      page.insert_html :bottom, :packages_table_unaffected, :partial => 'package', :object => Package.new(:comp => ">=", :arch => "*", :my_type => "unaffected")
    end
  end
  
  def add_reference_link(name)
    link_to_function name, :title => "Add reference" do |page|
      page.insert_html :bottom, :references_table, :partial => 'reference', :object => Reference.new
    end
  end
  
  def status_icon(status)
    if status == "request"
      image_tag "icons/request.png", :title => "This item is a request."
    elsif status == "draft"
      image_tag "icons/draft.png", :title => "This item is a draft."
    elsif status == "release"
      image_tag "icons/sent.png", :title => "This item is a sent GLSA."
    else
      "?"
    end
  end
  
  def bugready_icon(status)
    if status
      image_tag "icons/bug.png", :title => "This item is bug ready."
    else
      image_tag "icons/bug-grey.png", :title => "This item is NOT bug ready."
    end
  end
  
  def approval_icon(status)
    if status == :approved
      image_tag "icons/status-green.png", :title => "This item is approved for sending."
    elsif status == :commented
      image_tag "icons/status-red.png", :title => "This item has received comments."
    elsif status == :comments_pending
      image_tag "icons/status-yellow.png", :title => "This item has received comments."
    else
      image_tag "icons/status-grey.png", :title => "This item has no comments."
    end
  end

  def workflow_icon(status)
    if status == :commented
      image_tag "icons/commented.png", :title => "You have commented on this item."
    elsif status == :approved
      image_tag "icons/approved.png", :title => "You have approved this item."
    elsif status == :own
      image_tag "icons/user.png", :title => "This is your own draft."
    elsif status == :todo
      image_tag "icons/not-approved.png", :title => "Please comment and/or approve."
    end
  end
  
  def restricted_icon(status)
    if status
      image_tag "icons/confidential.png", :title => "This item is CONFIDENTIAL."
    else
      image_tag "icons/public.png", :title => "This item is public."
    end
  end
  
  def prefixed_item(prefix, text)
    tf = Text::Format.new()
    tf.first_indent = tf.body_indent = prefix.length + 1
    
    str = tf.format(text)
    str[0, prefix.length] = prefix  
    str.chomp
  end
  
  def adv_wrap(text)
    text.gsub!(/\r?\n/, "\n")

    text.gsub!(/<\/?(b|i)>/, '')

    text.gsub!(/(?:<ul>\s*(.*?)<\/ul>(?:\s*\n)?)/m) do |s|
      $1.gsub!(/<li>(.*?)<\/li>\s*/) do |t|
        ('* ' + word_wrap($1, 70)).gsub("\n", "\n  ") + "\n\n"      
      end
    end
    
    text.gsub!(/(?:<ol>\s*(.*?)<\/ol>(?:\s*\n)?)/m) do |s|
      nom = 0
      $1.gsub!(/<li>(.*?)<\/li>\s*/) do |t|
        ("#{nom += 1}. " + word_wrap($1, 69)).gsub("\n", "\n   ") + "\n\n"      
      end
    end
    
    word_wrap(text.chomp, 72)
       
  end  
end