You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

issue_category.rb 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. class IssueCategory < ActiveRecord::Base
  19. include Redmine::SafeAttributes
  20. belongs_to :project
  21. belongs_to :assigned_to, :class_name => 'Principal'
  22. has_many :issues, :foreign_key => 'category_id', :dependent => :nullify
  23. validates_presence_of :name
  24. validates_uniqueness_of :name, :scope => [:project_id], :case_sensitive => false
  25. validates_length_of :name, :maximum => 60
  26. safe_attributes 'name', 'assigned_to_id'
  27. scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
  28. alias :destroy_without_reassign :destroy
  29. # Destroy the category
  30. # If a category is specified, issues are reassigned to this category
  31. def destroy(reassign_to = nil)
  32. if reassign_to && reassign_to.is_a?(IssueCategory) && reassign_to.project == self.project
  33. Issue.where({:category_id => id}).update_all({:category_id => reassign_to.id})
  34. end
  35. destroy_without_reassign
  36. end
  37. def <=>(category)
  38. name <=> category.name
  39. end
  40. def to_s; name end
  41. end