permission.rb 769 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. class Permission < ApplicationModel
  3. include ChecksClientNotification
  4. include ChecksHtmlSanitized
  5. include HasCollectionUpdate
  6. has_and_belongs_to_many :roles
  7. validates :name, presence: true
  8. store :preferences
  9. validates :note, length: { maximum: 500 }
  10. sanitized_html :note
  11. =begin
  12. permissions = Permission.with_parents('some_key.sub_key')
  13. returns
  14. ['some_key.sub_key', 'some_key']
  15. =end
  16. def self.with_parents(key)
  17. names = []
  18. part = ''
  19. key.split('.').each do |local_part|
  20. if part != ''
  21. part += '.'
  22. end
  23. part += local_part
  24. names.push part
  25. end
  26. names
  27. end
  28. def to_s
  29. name
  30. end
  31. end