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.

group_builtin.rb 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 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 GroupBuiltin < Group
  19. validate :validate_uniqueness, :on => :create
  20. def validate_uniqueness
  21. errors.add :base, 'The builtin group already exists.' if self.class.exists?
  22. end
  23. def builtin?
  24. true
  25. end
  26. def destroy
  27. false
  28. end
  29. def user_added(user)
  30. raise 'Cannot add users to a builtin group'
  31. end
  32. class << self
  33. def load_instance
  34. return nil if self == GroupBuiltin
  35. instance = unscoped.order('id').first || create_instance
  36. end
  37. def create_instance
  38. raise 'The builtin group already exists.' if exists?
  39. instance = unscoped.new
  40. instance.lastname = name
  41. instance.save :validate => false
  42. raise 'Unable to create builtin group.' if instance.new_record?
  43. instance
  44. end
  45. private :create_instance
  46. end
  47. end