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
|
# ===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.
require 'rexml/document'
# Revision model
class Revision < ActiveRecord::Base
belongs_to :glsa, :class_name => "Glsa", :foreign_key => "glsa_id"
has_many :bugs
has_many :references
has_many :packages
has_many :vulnerable_packages, :class_name => "Package", :conditions => { :my_type => "vulnerable" }
has_many :unaffected_packages, :class_name => "Package", :conditions => { :my_type => "unaffected" }
belongs_to :user
validates_numericality_of :user_id, :message => "user id needed"
validates_presence_of :title
validates_each :description, :resolution do |record, attr, value|
# XML well-formedness test
begin
REXML::Document.new("<?xml version='1.0'?><root>#{value}</root>")
rescue REXML::ParseException => e
record.errors.add attr, "is not well-formed XML"
end
end
# Returns an Array of Integers of the bugs linked to this revision
def get_linked_bugs
self.bugs.map do |bug|
bug.bug_id.to_i
end
end
# Checks all assigned bugs for bug ready status
def bug_ready?
self.bugs.each do |b|
return false unless b.bug_ready?
end
return true
end
# Updates the cached metadata of all assigned bugs
def update_cached_bug_metadata
self.bugs.each do |b|
b.update_cached_metadata
end
end
# Creates a deep copy of a previous revision, copying all bugs, references and packages,
# incrementing the revision ID by one.
# <b>The caller must take care of deleting this revision again in case any error occurs later.</b>
def deep_copy
new_rev = clone
new_rev.revid = glsa.next_revid
references.each {|reference| new_rev.references << reference.clone }
packages.each {|package| new_rev.packages << package.clone }
bugs.each {|bug| new_rev.bugs << bug.clone }
new_rev.save!
new_rev
end
end
|