app/controllers/application_controller.rb
# Find a record by model name and ID, set flash errors for not found/not authorized
Find a record by model name and ID, set flash errors for not found/not authorized
Find a record by model name and ID set flash errors for not found / not authorized
def find_by_model_and_id_check_rbac(model, id, resource_name = nil)
    rec = model.constantize.find_by_id(id)
    if rec
      begin
        authrec = find_by_id_filtered(model.constantize, id)
      rescue ActiveRecord::RecordNotFound
      rescue StandardError => @bang
      end
    end
    if rec.nil?
      record_name = resource_name ? "#{ui_lookup(:model => model)} '#{resource_name}'" : "The selected record"
      add_flash(_("%{record_name} no longer exists in the database") % {:record_name => record_name}, :error)
    elsif authrec.nil?
      add_flash(_("You are not authorized to view %{model_name} '%{resource_name}'") %
        {:model_name => ui_lookup(:model => rec.class.base_model.to_s), :resource_name => resource_name}, :error)
    end
    rec
  end
def find_by_model_and_id_check_rbac ( model , id , resource_name = nil ) rec = model . constantize . find_by_id ( id ) if rec begin authrec = find_by_id_filtered ( model . constantize , id ) rescue ActiveRecord :: RecordNotFound rescue StandardError => @bang end end if rec . nil? record_name = resource_name ? "#{ui_lookup(:model => model)} '#{resource_name}'" : "The selected record" add_flash ( _ ( "%{record_name} no longer exists in the database" ) % { :record_name => record_name } , :error ) elsif authrec . nil? add_flash ( _ ( "You are not authorized to view %{model_name} '%{resource_name}'" ) % { :model_name => ui_lookup ( :model => rec . class . base_model . to_s ) , :resource_name => resource_name } , :error ) end rec end
Find a record by model name and ID, set flash errors for not found/not authorized
Find a record by model name and ID set flash errors for not found / not authorized
model
<not_specific>
id
<not_specific>
resource_name
<not_specific>