All reporting engine controllers must implement allowed_to? and current_user for the widgets to use

pull/6827/head
Tim Felgentreff 14 years ago
parent 2d36ce426c
commit 3152cb7eab
  1. 17
      lib/report/controller.rb
  2. 8
      lib/widget.rb

@ -2,6 +2,8 @@ module Report::Controller
def self.included(base)
base.class_eval do
attr_accessor :report_engine
helper_method :current_user
helper_method :allowed_to?
include ReportingHelper
helper ReportingHelper
@ -302,6 +304,21 @@ module Report::Controller
'user_id'
end
##
# Fallback: @current_user needs to be set for the engine
def current_user
if @current_user.nil?
raise NotImplementedError, "The #{self.class} should have set @current_user before this request"
end
@current_user
end
##
# Abstract: Implementation required in application
def allowed_to?(action, subject, user = current_user)
raise NotImplementedError, "The #{self.class} should have implemented #allowed_to?(action, subject, user)"
end
##
# Find a report if :id was passed as parameter.
# Raises RecordNotFound if an invalid :id was passed.

@ -27,6 +27,14 @@ class Widget < ActionView::Base
false
end
def method_missing(name, *args, &block)
begin
controller.send(name, *args, &block)
rescue NoMethodError
throw NoMethodError, "undefined method `#{name}' for #<#{self.class}:0x#{self.object_id}>"
end
end
module RenderWidgetInstanceMethods
def render_widget(widget, subject, options = {}, &block)
i = widget.new(subject)

Loading…
Cancel
Save