permission.rb 725 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. sanitized_html :note
  10. =begin
  11. permissions = Permission.with_parents('some_key.sub_key')
  12. returns
  13. ['some_key.sub_key', 'some_key']
  14. =end
  15. def self.with_parents(key)
  16. names = []
  17. part = ''
  18. key.split('.').each do |local_part|
  19. if part != ''
  20. part += '.'
  21. end
  22. part += local_part
  23. names.push part
  24. end
  25. names
  26. end
  27. def to_s
  28. name
  29. end
  30. end