Method: Osm::Api#get_user_permissions

Defined in:
lib/osm/api.rb

#get_user_permissions(options = {}) ⇒ Object

Get API user’s permissions

Returns:

  • nil if an error occured or the user does not have access to that section

  • (Hash)

    => permissions_hash



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/osm/api.rb', line 225

def get_user_permissions(options={})
  cache_key = ['permissions', user_id]

  if !options[:no_cache] && Osm::Model.cache_exist?(self, cache_key)
    return Osm::Model.cache_read(self, cache_key)
  end

  all_permissions = Hash.new
  get_user_roles(options).each do |item|
    unless item['section'].eql?('discount')  # It's not an actual section
      all_permissions.merge!(Osm::to_i_or_nil(item['sectionid']) => Osm.make_permissions_hash(item['permissions']))
    end
  end
  Osm::Model.cache_write(self, cache_key, all_permissions)

  return all_permissions
end