Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More docs; among the others, added some info on how to use history.

  • Loading branch information...
commit 4b7c442822a6cc59bfc402dd2cb777c7666c0de5 1 parent fd61ad0
@baldowl authored
View
8 README
@@ -93,6 +93,14 @@ appropriately. So if other parts of your site do the same, things will Just
Work.
+=== History
+
+Admins' actions are automatically recorded and shown if the optional
+<tt>admin_histories</tt> table is available.
+
+See AutoAdminController#history for details.
+
+
== What do you need?
To use AutoAdmin with Rails 2.* you need an extra plugin,
View
20 lib/auto_admin_configuration.rb
@@ -7,7 +7,7 @@ def self.config
module AutoAdminConfiguration
DefaultTheme = :django
- # Returns the name of the active theme module.
+ # Returns the active theme module.
def self.theme; Object.const_get("AutoAdmin#{theme_name.to_s.camelize}Theme"); end
# Returns the name of the active theme.
@@ -21,9 +21,15 @@ def self.theme=(theme_name)
def self.form_processor; theme::FormProcessor; end
def self.form_builder; theme::FormBuilder; end
def self.table_builder; theme::TableBuilder; end
+
+ # The view directory is actually dependent on the active theme.
def self.view_directory; theme.view_directory; end
+
def self.asset_root; theme.asset_root; end
+
+ # Returns the list of the active theme's helpers.
def self.helpers; theme.respond_to?( :helpers ) ? [theme.helpers].flatten : []; end
+
def self.controller_includes; theme.respond_to?( :controller_includes ) ? [theme.controller_includes].flatten : []; end
Site = Struct.new(:url, :short_url, :name)
@@ -82,7 +88,15 @@ def self.admin_model_id=(new_value)
@@admin_model_id = new_value.to_sym
end
+ # The plugin's controller super class; defaults to ActionController::Base.
def self.controller_super_class; @@controller_super_class ||= ActionController::Base; end
+
+ # Allows to set another class as plugin's controller super class. Use it
+ # as:
+ #
+ # AutoAdmin.config do |admin|
+ # admin.controller_super_class = AlternativeController
+ # end
def self.controller_super_class=(klass); @@controller_super_class = klass; end
# The string used as prefix in the custom routes; defaults to +admin+.
@@ -101,10 +115,14 @@ def self.url_prefix= new_value; @@url_prefix = new_value; end
# plugin home.
def self.save_as=(formats); @@save_as_formats = formats; end
+ # Returns the list of active export formats.
def self.save_as; @@save_as_formats ||= []; end
+
+ # Turns a simple string into the model class.
def self.model name
Object.const_get( name.to_s.camelcase )
end
+
def self.grouped_objects
objects = primary_objects.uniq.map { |po| model(po) }
groups = objects.map { |o| o.object_group }.uniq.sort
View
24 lib/auto_admin_controller.rb
@@ -25,6 +25,9 @@ def default_template_name(action_name = self.action_name)
end
before_filter :require_valid_user, :except => [ :login, :asset ]
+
+ # Used as a before filter to check if we have a valid user (i.e., an admin
+ # or something like that)
def require_valid_user
return unless has_user?
@@ -38,6 +41,8 @@ def require_valid_user
end
redirect_to :action => 'login', :model => nil unless valid_user
end
+
+ # A valid user must pass these checks.
def permit_user_to_access_admin user
user &&
(!user.respond_to?( :active? ) || user.active?) &&
@@ -222,6 +227,25 @@ def edit
@object = params[:id] ? model.find( params[:id] ) : model.new
end
+ # Returns a bunch (50, actually) of the latest records from the history
+ # table used to register admins' actions. To use this feature you need to
+ # add a database table like the following one:
+ #
+ # create_table :admin_histories do |t|
+ # t.column :obj_id, :integer
+ # t.column :object_label, :string
+ # t.column :model, :string
+ # t.column :user_id, :integer
+ # t.column :change, :string
+ # t.column :description, :string
+ # t.column :created_at, :datetime
+ # t.column :updated_at, :datetime
+ # t.column :lock_version, :integer, :default => 0
+ # end
+ #
+ # *Nota* *Bene*: the <tt>:user_id</tt> *must* actually be
+ # <em><admin model></em>_id, i.e. the same value of
+ # AutoAdmin::AutoAdminConfiguration#admin_model_id.
def history
@object = params[:id] ? model.find( params[:id] ) : model.new
@histories = AdminHistory.find :all, :conditions => ['model = ? AND obj_id = ?', params[:model], params[:id]], :order => 'admin_histories.created_at DESC', :limit => 50, :include => [*user_history_includes]
Please sign in to comment.
Something went wrong with that request. Please try again.