2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2016-08-12 16:39:09 +00:00
|
|
|
|
|
|
|
class Permission < ApplicationModel
|
2017-05-02 15:21:13 +00:00
|
|
|
include ChecksClientNotification
|
|
|
|
include ChecksLatestChangeObserved
|
2020-02-20 13:34:03 +00:00
|
|
|
include HasCollectionUpdate
|
2017-01-31 17:13:45 +00:00
|
|
|
|
2016-08-12 16:39:09 +00:00
|
|
|
has_and_belongs_to_many :roles
|
|
|
|
validates :name, presence: true
|
|
|
|
store :preferences
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
permissions = Permission.with_parents('some_key.sub_key')
|
|
|
|
|
2016-12-13 13:58:13 +00:00
|
|
|
returns
|
2016-08-12 16:39:09 +00:00
|
|
|
|
|
|
|
['some_key.sub_key', 'some_key']
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.with_parents(key)
|
|
|
|
names = []
|
|
|
|
part = ''
|
2017-10-01 12:25:52 +00:00
|
|
|
key.split('.').each do |local_part|
|
2016-08-12 16:39:09 +00:00
|
|
|
if part != ''
|
|
|
|
part += '.'
|
|
|
|
end
|
|
|
|
part += local_part
|
|
|
|
names.push part
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-08-12 16:39:09 +00:00
|
|
|
names
|
|
|
|
end
|
|
|
|
|
2019-01-15 12:55:59 +00:00
|
|
|
def to_s
|
|
|
|
name
|
|
|
|
end
|
|
|
|
|
2016-08-12 16:39:09 +00:00
|
|
|
end
|