From 0a9b48cc85fb7e16ebd5eda71d8f7b5a065995fc Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 15 Mar 2011 16:12:15 +0100 Subject: [PATCH] make user_id key flexible --- lib/report/controller.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/report/controller.rb b/lib/report/controller.rb index d6a8e54521..3761d1ef4c 100644 --- a/lib/report/controller.rb +++ b/lib/report/controller.rb @@ -36,7 +36,7 @@ module Report::Controller def create @query.name = params[:query_name].present? ? params[:query_name] : ::I18n.t(:label_default) @query.is_public = !!params[:query_is_public] - @query.user_id = current_user_id.to_i + @query.send("#{user_key}=", current_user.id) @query.save! if request.xhr? # Update via AJAX - return url for redirect render :text => url_for(:action => "show", :id => @query.id) @@ -257,13 +257,19 @@ module Report::Controller session[report_engine.name.underscore.to_sym] = cookie end + ## + # Override in subclass if user key + def user_key + 'user_id' + end + ## # Find a report if :id was passed as parameter. # Raises RecordNotFound if an invalid :id was passed. def find_optional_report if params[:id] @query = report_engine.find(params[:id].to_i, - :conditions => ["(is_public = 1) OR (user_id = ?)", current_user_id]) + :conditions => ["(is_public = 1) OR (#{user_key} = ?)", current_user.id]) if @query @query.deserialize else