make user_id key flexible

pull/6827/head
Konstantin Haase 14 years ago
parent 439ec1c29c
commit 0a9b48cc85
  1. 10
      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

Loading…
Cancel
Save