permission.rb 632 B

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class Permission < ApplicationModel
  3. include NotifiesClients
  4. include LatestChangeObserved
  5. has_and_belongs_to_many :roles
  6. validates :name, presence: true
  7. store :preferences
  8. =begin
  9. permissions = Permission.with_parents('some_key.sub_key')
  10. returns
  11. ['some_key.sub_key', 'some_key']
  12. =end
  13. def self.with_parents(key)
  14. names = []
  15. part = ''
  16. key.split('.').each { |local_part|
  17. if part != ''
  18. part += '.'
  19. end
  20. part += local_part
  21. names.push part
  22. }
  23. names
  24. end
  25. end