summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/.gitkeep0
-rw-r--r--app/models/bug.rb46
-rw-r--r--app/models/comment.rb44
-rw-r--r--app/models/cpe.rb29
-rw-r--r--app/models/cve.rb177
-rw-r--r--app/models/cve_assignment.rb3
-rw-r--r--app/models/cve_change.rb4
-rw-r--r--app/models/cve_comment.rb4
-rw-r--r--app/models/cve_reference.rb3
-rw-r--r--app/models/glsa.rb311
-rw-r--r--app/models/package.rb48
-rw-r--r--app/models/reference.rb15
-rw-r--r--app/models/revision.rb103
-rw-r--r--app/models/template.rb2
-rw-r--r--app/models/user.rb65
15 files changed, 0 insertions, 854 deletions
diff --git a/app/models/.gitkeep b/app/models/.gitkeep
deleted file mode 100644
index e69de29..0000000
--- a/app/models/.gitkeep
+++ /dev/null
diff --git a/app/models/bug.rb b/app/models/bug.rb
deleted file mode 100644
index 00e2d6d..0000000
--- a/app/models/bug.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-# ===GLSAMaker v2
-# Copyright (C) 2009-2011 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.
-
-# Bug model
-class Bug < ActiveRecord::Base
- belongs_to :revision
-
- def cc
- self.arches
- end
-
- include Glsamaker::Bugs::StatusMixin
- include Glsamaker::Bugs::ArchesMixin
- include Glsamaker::Bugs::BugReadyMixin
-
- # Returns the Gentoo Bugzilla URI for the bug.
- # Set +secure+ to false to get a HTTP instead of a HTTPS URI
- def bug_url(secure = true)
- if secure
- "https://#{GLSAMAKER_BUGZIE_HOST}/show_bug.cgi?id=#{self.bug_id}"
- else
- "http://#{GLSAMAKER_BUGZIE_HOST}/show_bug.cgi?id=#{self.bug_id}"
- end
- end
-
- # Updates the cached bug metadata
- def update_cached_metadata
- b = Glsamaker::Bugs::Bug.load_from_id(bug_id)
-
- update_attributes!(
- :title => b.summary,
- :whiteboard => b.status_whiteboard,
- :arches => b.arch_cc.join(', ')
- )
- rescue Exception => e
- raise "Could not update cached metadata: " + e.message
- end
-end
diff --git a/app/models/comment.rb b/app/models/comment.rb
deleted file mode 100644
index fa285a4..0000000
--- a/app/models/comment.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-# ===GLSAMaker v2
-# Copyright (C) 2009-2011 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.
-
-# Comment model
-class Comment < ActiveRecord::Base
- belongs_to :glsa, :class_name => "Glsa", :foreign_key => "glsa_id"
- belongs_to :user
-
- include ActiveModel::Validations
- validates :glsa_id, :presence => true
- validates :user_id, :presence => true
- validates :rating, :inclusion => { :in => %w[neutral approval rejection]}
- validates :rating, :uniqueness => { :scope => [:glsa_id, :user_id], :if => Proc.new {|comment| comment.rating != 'neutral'}, :message => 'You have already approved or rejected this draft' }
-
- class CommentValidator < ActiveModel::Validator
- def validate(record)
- if record.glsa.is_owner? record.user
- if record.rating != 'neutral'
- record.errors[:rating] << 'The owner of a draft cannot make approvals or rejections'
- end
- end
-
- if record.glsa.submitter.nil?
- record.errors[:rating] << 'You may not approve or reject advisories that have not been filled in yet'
- end
-
- if record.user.access < 2
- if record.rating != 'neutral'
- record.errors[:rating] << 'You may not approve or reject drafts'
- end
- end
- end
- end
-
- validates_with CommentValidator
-end
diff --git a/app/models/cpe.rb b/app/models/cpe.rb
deleted file mode 100644
index 243cced..0000000
--- a/app/models/cpe.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# ===GLSAMaker v2
-# Copyright (C) 2010 Alex Legler <a3li@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.
-
-class Cpe < ActiveRecord::Base
- has_and_belongs_to_many :cves, :class_name => 'Cve'
-
- def split
- self.cpe.split(':')
- end
-
- def vendor
- split[2]
- end
-
- def product
- split[3]
- end
-
- def version
- split[4]
- end
-end
diff --git a/app/models/cve.rb b/app/models/cve.rb
deleted file mode 100644
index d9a05c6..0000000
--- a/app/models/cve.rb
+++ /dev/null
@@ -1,177 +0,0 @@
-# ===GLSAMaker v2
-# Copyright (C) 2010 Alex Legler <a3li@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 'glsamaker/helpers'
-
-class Cve < ActiveRecord::Base
- has_many :references, :class_name => "CveReference"
- has_many :comments, :class_name => "CveComment"
- has_and_belongs_to_many :cpes, :class_name => "Cpe"
- has_many :cve_changes, :class_name => "CveChange", :foreign_key => "cve_id"
- has_many :assignments, :class_name => "CveAssignment", :foreign_key => "cve_id"
-
- def to_s(line_length = 78)
- str = "#{self.cve_id} #{"(%s):" % url}\n"
- str += " " + Glsamaker::help.word_wrap(self.summary, :line_width => line_length-2).gsub(/\n/, "\n ")
- end
-
- # Returns the URL for this CVE at NVD (<tt>:nvd</tt>, default) or MITRE (<tt>:mitre</tt>)
- def url(site = :nvd)
- if site == :nvd
- "https://nvd.nist.gov/vuln/detail/%s" % self.cve_id
- elsif site == :mitre
- "https://cve.mitre.org/cgi-bin/cvename.cgi?name=%s" % self.cve_id
- else
- raise ArgumentError, 'Invalid site'
- end
- end
-
- # Concatenates the CVE descriptions of many cves, separated by separator
- def self.concat(cves, separator = "\n\n")
- txt = ""
- cves.each do |cve|
- txt += Cve.find(cve).to_s
- txt += separator
- end
- txt
- end
-
- # Assigns the CVE to a certain bug, creating a history entry
- def assign(bugnr, user, action = 'assign')
- bugnr = Integer(bugnr)
-
- case action
- when 'assign', :assign
- act = 'assign'
- when 'file', :file
- act = 'file'
- else
- raise ArgumentError, "Invalid action specified"
- end
-
- a = self.assignments.create!(:bug => bugnr)
-
- ch = self.cve_changes.create!(
- :user => user,
- :action => act,
- :object => a.id
- )
-
- self.state = 'ASSIGNED'
- save!
- end
-
- # Mark the CVE as Not-For-Us, creating a history entry
- def nfu(user, reason = nil)
- self.cve_changes.create!(
- :user => user,
- :action => 'nfu',
- :object => reason
- )
-
- self.state = 'NFU'
- save!
- end
-
- # Mark the CVE as INVALID, creating a history entry
- def invalidate(user, reason = nil)
- self.cve_changes.create!(
- :user => user,
- :action => 'invalid',
- :object => reason
- )
-
- self.state = 'INVALID'
- save!
- end
-
- def later(user, reason = nil)
- self.cve_changes.create!(
- :user => user,
- :action => 'later',
- :object => reason
- )
-
- self.state = 'LATER'
- save!
- end
-
- def mark_new(user, reason = nil)
- self.cve_changes.create!(
- :user => user,
- :action => 'new',
- :object => reason
- )
-
- self.state = 'NEW'
- save!
- end
-
- def add_comment(user, comment, confidential = false)
- self.comments << CveComment.create!(
- :user => user,
- :confidential => confidential,
- :comment => comment
- )
- end
-
- # Decorates the output of field with a color, depending on the status
- def colorize(field = :cve_id)
- "<span class='cvename cve-%s'>%s</span>" % [state.downcase, self[field]]
- end
-
- # Looks for Gentoo packages that might be affected by this CVE
- def package_hints
- def search(s)
- return [] if s.nil? or s == ""
-
- Glsamaker::Portage.find_packages(
- Regexp.compile(Regexp.escape(s).gsub(/[^a-zA-Z0-9]/, '.*?'), Regexp::IGNORECASE)
- )
- end
-
- package_hints = []
- my_cpes = cpes.map {|c| c.product }.uniq
- package_hints << my_cpes.map {|c| search c }.flatten
-
- # stolen from the old cvetools.py
- if summary =~ / in (\S+\.\S+) in (?:the )?(?:a )?(\D+) \d+/
- match = $2
- if match.end_with? 'before'
- package_hints << search(match[0, match.length - 7])
- else
- package_hints << search(match)
- end
- end
-
- if summary =~ / in (?:the )?(?:a )?(\D+) \d+/
- match = $1
- if match.end_with? 'before'
- package_hints << search(match[0, match.length - 7])
- else
- package_hints << search(match)
- end
- end
-
- if summary =~ / in (\S+\.\S+) in (?:the )?(?:a )?(\S+) /
- package_hints << search($1)
- end
-
- if summary =~ / in (?:the )?(?:a )?(\S+) /
- package_hints << search($1)
- end
-
- if summary =~ /(?:The )?(\S+) /
- package_hints << search($1)
- end
-
- package_hints.flatten.uniq
- end
-end
diff --git a/app/models/cve_assignment.rb b/app/models/cve_assignment.rb
deleted file mode 100644
index af1559a..0000000
--- a/app/models/cve_assignment.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-class CveAssignment < ActiveRecord::Base
- belongs_to :cve
-end
diff --git a/app/models/cve_change.rb b/app/models/cve_change.rb
deleted file mode 100644
index 71ff974..0000000
--- a/app/models/cve_change.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-class CveChange < ActiveRecord::Base
- belongs_to :user, :class_name => "User", :foreign_key => "user_id"
- belongs_to :cve
-end
diff --git a/app/models/cve_comment.rb b/app/models/cve_comment.rb
deleted file mode 100644
index 73357dc..0000000
--- a/app/models/cve_comment.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-class CveComment < ActiveRecord::Base
- belongs_to :cve
- belongs_to :user, :class_name => "User", :foreign_key => "user_id"
-end
diff --git a/app/models/cve_reference.rb b/app/models/cve_reference.rb
deleted file mode 100644
index 1f11e01..0000000
--- a/app/models/cve_reference.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-class CveReference < ActiveRecord::Base
- belongs_to :cve
-end
diff --git a/app/models/glsa.rb b/app/models/glsa.rb
deleted file mode 100644
index bee70be..0000000
--- a/app/models/glsa.rb
+++ /dev/null
@@ -1,311 +0,0 @@
-# ===GLSAMaker v2
-# Copyright (C) 2009-2011 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 model
-class Glsa < ActiveRecord::Base
- validates_uniqueness_of :glsa_id, :message => "must be unique"
- validates_presence_of :glsa_id, :message => "GLSA ID needed"
-
- belongs_to :submitter, :class_name => "User", :foreign_key => "submitter"
- belongs_to :requester, :class_name => "User", :foreign_key => "requester"
- belongs_to :bugreadymaker, :class_name => "User", :foreign_key => "bugreadymaker"
-
- has_many :revisions, :dependent => :destroy
- has_many :comments, :dependent => :destroy
-
- # Returns the last revision object, referring to the current state of things
- def last_revision
- @last_revision ||= self.revisions.order("revid DESC").first
- end
-
- # Returns the last revision object that was a release
- def last_release_revision
- self.revisions.where(:is_release => true).order('release_revision DESC').first
- end
-
- # Invalidates the last revision cache
- def invalidate_last_revision_cache
- @last_revision = nil
- end
-
- # Returns the next revision ID to be given for this GLSA
- def next_revid
- if (rev = last_revision)
- rev.revid + 1
- else
- 0
- end
- end
-
- # Returns the next release revision ID to be given for this GLSA
- def next_releaseid
- if (rev = last_release_revision)
- rev.release_revision + 1
- else
- 1
- end
- end
-
- # Returns the best available release date
- def release_date
- return first_released_at if status == 'release'
- last_revision.created_at
- end
-
- # Returns the best available revision date
- def revised_date
- if status == 'release' and last_revision.created_at < first_released_at
- first_released_at
- else
- last_revision.created_at
- end
- end
-
- # Returns all approving comments
- def approvals
- comments.where(:rating => 'approval')
- end
-
- # Returns all rejecting comments
- def rejections
- comments.where(:rating => 'rejection')
- end
-
- # Returns true if the draft is ready for sending
- def is_approved?
- count = 0
- users_who_approved = approvals.map { |a| a.user_id }
- users_who_rejected = rejections.map { |a| a.user_id }
-
- common_users = (users_who_approved & users_who_rejected)
- common_users.each do |user|
- approval = approvals.where(:user_id => user).order('created_at DESC').first
- rejection = rejections.where(:user_id => user).order('created_at DESC').first
-
- # if the approval was before a rejection => 0
- if approval.created_at < rejection.created_at
- count += 0
- elsif approval.created_at > rejection.created_at
- count += 1
- end
- end
-
- (users_who_approved - common_users).each do |user|
- count += 1
- end
-
- (users_who_rejected - common_users).each do |user|
- count -= 1
- end
-
- (count >= 1)
- end
-
- # Returns true if it has comments
- def has_comments?
- comments.count > 0
- end
-
- # The approval status of the GLSA, either :approved, :commented, or :none
- def approval_status
- if is_approved?
- return :approved
- elsif has_comments?
- if has_pending_comments?
- return :comments_pending
- else
- return :commented
- end
- end
- return :none
- end
-
- # Returns true if user is the owner of this GLSA.
- def is_owner?(user)
- return false if user.nil?
- luser = (status == "request" ? requester : submitter)
- luser == user
- end
-
- # Returns the workflow status of this GLSA for a given user.
- # Return values: :own (own draft), :approved (approval given), :commented (comment or rejection given)
- def workflow_status(user)
- if is_owner?(user)
- return :own
- end
-
- if comments.where(:rating => 'approval', :user_id => user.id).count > 0
- return :approved
- end
-
- if comments.where(:user_id => user.id, :read => false).count > 0
- return :commented
- end
-
- return :todo
- end
-
- # Returns true if there are any pending comments left
- def has_pending_comments?
- comments.where(:read => false).all.count > 0
- end
-
- # Returns all CVEs linked to this GLSA
- def related_cves
- last_revision.bugs.map do |bug|
- CveAssignment.where(bug: bug.bug_id).map {|assignment| assignment.cve}.uniq
- end.flatten
- end
-
- # Bulk addition of references.
- # Expects an array of hashes <tt>{:title => ..., :url => ...}</tt>
- def add_references(refs)
- rev = last_revision.deep_copy
-
- refs.each do |reference|
- rev.references.create(reference)
- end
-
- invalidate_last_revision_cache
- self
- end
-
- # Performs the steps to release the GLSA, performing santiy checks.
- def release
- raise GLSAReleaseError, 'Cannot release the GLSA as it is not approved' if not is_approved?
- raise GLSAReleaseError, 'Cannot release the GLSA as there are comments pending' if has_pending_comments?
- # TODO: releasing someone else's draft
- release!
- end
-
- # Performs the steps to release the GLSA, performing not as many checks. The +release+ method is to be preferred.
- def release!
- # This one is not avoidable. Some information is only filled in during the first edit, thus making it required.
- raise GLSAReleaseError, 'Cannot release the GLSA as it is not in "draft" or "release" status' if not (self.status == 'draft' or self.status == 'release')
-
- rev = last_revision.deep_copy
- rev.is_release = true
- rev.release_revision = next_releaseid
- rev.save!
-
- unless self.status == 'release'
- self.glsa_id = Glsa.next_id
- self.first_released_at = Time.now
- end
-
- self.status = 'release'
- save!
- end
-
- # Closes all bugs linked to this advisory and refreshes the metadata
- def close_bugs(message)
- last_revision.bugs.each do |bug|
- logger.info "Closing bug #{bug.bug_id}"
- b = Glsamaker::Bugs::Bug.load_from_id(bug.bug_id)
-
- changes = {}
- changes[:comment] = message
- changes[:whiteboard] = b.status_whiteboard.gsub(/(ebuild\+?|upstream\+?|stable\+?|glsa)\??/, 'glsa+').gsub(/glsa\/glsa/, 'glsa+')
- changes[:status] = "RESOLVED"
- changes[:resolution] = "FIXED"
-
- Bugzilla.update_bug(bug.bug_id, changes)
- bug.update_cached_metadata
- end
- end
-
- # Returns a publically accessible URL for the advisory if it's a released GLSA
- def to_url
- "https://security.gentoo.org/glsa/#{self.glsa_id}"
- end
-
- # Calculates the next GLSA ID for the given month, or the current month
- def self.next_id(month = Time.now)
- month_id = month.strftime("%Y%m")
- items = Glsa.where("glsa_id LIKE ? AND status = ?", month_id + '%', 'release').order('glsa_id DESC')
-
- return "#{month_id}-01" if items.length == 0
-
- items.first.glsa_id =~ /^#{month_id}-(\d+)$/
- next_id = $1.to_i + 1
- "#{month_id}-#{format "%02d", next_id}"
- end
-
- # Files a new GLSA request
- def self.new_request(title, bugs, comment, access, import_references, user)
- glsa = Glsa.new
- glsa.requester = user
- glsa.glsa_id = Digest::MD5.hexdigest(title + Time.now.to_s)[0...9]
- glsa.restricted = (access == "confidential")
- glsa.status = "request"
-
- begin
- glsa.save!
- rescue Exception => e
- raise Exception, "Error while saving the GLSA object: #{e.message}"
- end
-
- # unless comment.strip.blank?
- # glsa.comments << Comment.new(:rating => "neutral", :text => comment, :user => user)
-
- # begin
- # glsa.save!
- # rescue Exception => e
- # raise Exception, "Error while saving the comment: #{e.message}"
- # end
- # end
-
- revision = Revision.new
- revision.revid = glsa.next_revid
- revision.glsa = glsa
- revision.title = title
- revision.user = user
-
- begin
- revision.save!
- rescue Exception => e
- glsa.delete
- raise Exception, "Error while saving Revision object: #{e.message}"
- end
-
- bugs = Bugzilla::Bug.str2bugIDs(bugs)
-
- bugs.each do |bug|
- begin
- b = Glsamaker::Bugs::Bug.load_from_id(bug)
-
- revision.bugs.create(
- :bug_id => bug,
- :title => b.summary,
- :whiteboard => b.status_whiteboard,
- :arches => b.arch_cc.join(', ')
- )
- rescue Exception => e
- # In case of bugzilla errors, just keep the bug #
- revision.bugs.create(:bug_id => bug)
- end
- end
-
- if import_references
- logger.debug { "importing references" }
- refs = []
- glsa.related_cves.each do |cve|
- refs << {:title => cve.cve_id, :url => cve.url}
- end
- glsa.add_references refs
- end
-
- glsa
- end
-
-end
-
-class GLSAReleaseError < StandardError; end
diff --git a/app/models/package.rb b/app/models/package.rb
deleted file mode 100644
index 30fb1bd..0000000
--- a/app/models/package.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-# ===GLSAMaker v2
-# Copyright (C) 2009-2011 Alex Legler <a3li@gentoo.org>
-# Copyright (C) 2009 Pierre-Yves Rofes <py@gentoo.org>
-# Copyright (C) 2017 Robin H. Johnson <robbat2@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.
-
-# Package model
-class Package < ActiveRecord::Base
- # Mapping XML comparators to internally used ones
- COMP_MAP = {
- '>=' => 'ge',
- '>' => 'gt',
- '=' => 'eq',
- '<=' => 'le',
- '<' => 'lt',
- '*<' => 'rlt',
- '*<=' => 'rle',
- '*>' => 'rgt',
- '*>=' => 'rge'
- }.freeze
-
- # Arches (from $PORTDIR/profiles/arch.list)
- ARCHLIST_BASE = %w{alpha amd64 arm arm64 hppa ia64 m68k mips nios2 ppc ppc64 riscv s390 sh sparc x86}.freeze
- ARCHLIST_FBSD = %w{amd64-fbsd sparc-fbsd x86-fbsd}.freeze
- ARCHLIST_PREFIX = %w{ppc-aix amd64-linux arm-linux arm64-linux ppc64-linux x86-linux ppc-macos x86-macos x64-macos m68k-mint sparc-solaris sparc64-solaris x64-solaris x86-solaris x86-winnt x64-cygwin x86-cygwin}.freeze
- ARCHLIST = (ARCHLIST_BASE+ARCHLIST_FBSD+ARCHLIST_PREFIX).freeze
- ARCHLIST_REGEX = %r{(?:#{ARCHLIST.join('|')})}.freeze
-
- # Model properties
- belongs_to :revision
- validates :comp, :inclusion => { :in => COMP_MAP.keys }
- validates :arch, :format => { :with => /\A(\*|(#{ARCHLIST_REGEX} )*#{ARCHLIST_REGEX})\z/ }
-
- # Returns the comparator in the format needed for the XML
- def xml_comp
- COMP_MAP[self.comp]
- end
-
- def self.reverse_comp(cmp)
- COMP_MAP.invert[cmp]
- end
-end
diff --git a/app/models/reference.rb b/app/models/reference.rb
deleted file mode 100644
index f378cd4..0000000
--- a/app/models/reference.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# ===GLSAMaker v2
-# Copyright (C) 2009-2011 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.
-
-# Reference model
-class Reference < ActiveRecord::Base
- belongs_to :revision
-end
diff --git a/app/models/revision.rb b/app/models/revision.rb
deleted file mode 100644
index 26cfd82..0000000
--- a/app/models/revision.rb
+++ /dev/null
@@ -1,103 +0,0 @@
-# ===GLSAMaker v2
-# Copyright (C) 2009-2011 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, :dependent => :destroy
- has_many :references, :dependent => :destroy
- has_many :packages, :dependent => :destroy
- has_many :vulnerable_packages, -> { where :my_type => "vulnerable" }, :class_name => "Package"
- has_many :unaffected_packages, -> { where :my_type => "unaffected" }, :class_name => "Package"
- belongs_to :user
-
- validates_numericality_of :user_id, :message => "user id needed"
- validates_presence_of :title
-
-=begin
- 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
-=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 = dup
- new_rev.revid = glsa.next_revid
-
- references.each {|reference| new_rev.references << reference.dup }
- packages.each {|package| new_rev.packages << package.dup }
- bugs.each {|bug| new_rev.bugs << bug.dup }
-
- new_rev.save!
- new_rev
- end
-
- # Returns the packages linked to this revision grouped by atoms
- def packages_by_atom
- packages_list = {}
- self.packages.each do |p|
- packages_list[p[:atom]] ||= {}
- (packages_list[p[:atom]][p[:my_type]] ||= []) << p
- end
-
- packages_list
- end
-
- def to_s
- s = "r#{self.revid}"
- if self.is_release?
- s << " (release #{self.release_revision})"
- end
-
- s
- end
-
- def release_access
- if self.access == "both"
- "local, remote"
- else
- self.access
- end
- end
-end
diff --git a/app/models/template.rb b/app/models/template.rb
deleted file mode 100644
index d974347..0000000
--- a/app/models/template.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-class Template < ActiveRecord::Base
-end
diff --git a/app/models/user.rb b/app/models/user.rb
deleted file mode 100644
index 88d5eff..0000000
--- a/app/models/user.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-# ===GLSAMaker v2
-# Copyright (C) 2009-2011 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.
-
-# =Access levels
-#
-# [<b>0 (Contributor)</b>] Can see own drafts, can fill in requests
-# [<b>1 (Padawan)</b>] all of the above, plus see and edit all drafts
-# [<b>2 (Full member)</b>] all of the above, plus voting
-# [<b>3 (Confidential member)</b>] all of the above, including restricted drafts
-class User < ActiveRecord::Base
- has_many :submitted_glsas, :class_name => "Glsa", :foreign_key => "submitter"
- has_many :requested_glsas, :class_name => "Glsa", :foreign_key => "requester"
- has_many :bugreadymade_glsas, :class_name => "Glsa", :foreign_key => "bugreadymaker"
- has_many :cve_changes, :class_name => "CveChange", :foreign_key => "user_id"
-
- has_many :revisions
-
- serialize :preferences
-
- validates_uniqueness_of :login, :message => "User name must be unique"
- validates_presence_of :login, :message => "User name can't be blank"
-
- validates_presence_of :name, :message => "Name can't be blank"
-
- validates_presence_of :access, :message => "Access level needed"
- validates_numericality_of :access, :greater_than_or_equal_to => 0, :less_than_or_equal_to => 3, :message => "Access level must be between 0 and 3"
-
- validates_format_of :email, :with => /[\w.%+-]+?@[\w.-]+?\.\w{2,6}\z/, :message => "Invalid Email address format"
-
- scope :active, -> { where(:disabled => false).where('id > ?', 0) }
-
- # Is the user an admin? ;)
- def is_el_jefe?
- self.jefe
- end
-
- # Checks access to a given GLSA
- def can_access?(glsa)
- return false if disabled?
- return false if access == 0 and not glsa.is_owner? self
- return false if access < 3 and glsa.restricted
-
- true
- end
-
- def to_s
- "#{name} (#{login})"
- end
-
- # Returns a certain category form the user's preferences
- # or an empty hash if that category does not exist
- def get_pref_category(category)
- return {} if self.preferences == nil or self.preferences[category] == nil
-
- self.preferences[category]
- end
-end