Skip to content

Commit

Permalink
importing codebase
Browse files Browse the repository at this point in the history
git-svn-id: http://activescaffold.googlecode.com/svn/trunk@2 561dde7e-7729-0410-be8e-ef83869d6c7d
  • Loading branch information
cainlevy committed Feb 20, 2007
1 parent c640547 commit 341ff06
Show file tree
Hide file tree
Showing 122 changed files with 7,172 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
3.2.1 ========

* Fixed bug with :class_name attribute being ignored

3.2.0 ==========

* Initial release
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2006 Richard White

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 changes: 16 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
********************************************************************************
** For all documentation see the project website: http://www.ActiveScaffold.com **
********************************************************************************

ActiveScaffold plugin by Scott Rutherford (scott@caronsoftware.com), Richard White (rrwhite@gmail.com), Lance Ivy (lance@cainlevy.net), and Ed Moss

Uses DhtmlHistory by Brad Neuberg (bkn3@columbia.edu)
http://codinginparadise.org

Uses Querystring by Adam Vandenberg
http://adamv.com/dev/javascript/querystring

Uses Paginator by Bruce Williams
http://paginator.rubyforge.org/

Released under the MIT license (included)
71 changes: 71 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require 'rake'
require 'rake/testtask'
require 'rake/packagetask'
require 'rake/rdoctask'
require 'find'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test ActiveScaffold.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for ActiveScaffold.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'ActiveScaffold'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end

# Globals

PKG_NAME = 'active_scaffold_plugin'
PKG_VERSION = '3.2.2'

PKG_FILES = ['README', 'CHANGELOG', 'MIT-LICENSE', 'init.rb', 'install.rb']
PKG_DIRECTORIES = ['app/', 'lib/', 'public/', 'tasks/', 'test/']
PKG_DIRECTORIES.each do |dir|
Find.find(dir) do |f|
if FileTest.directory?(f) and f =~ /\.svn/
Find.prune
else
PKG_FILES << f
end
end
end

# Tasks

task :package
Rake::PackageTask.new(PKG_NAME, PKG_VERSION) do |p|
p.need_tar = true
p.package_files = PKG_FILES
end

# "Gem" part of the Rakefile
begin
require 'rake/gempackagetask'

spec = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.summary = "ActiveScaffold is a Rails plugin for rich ActiveRecord CRUD."
s.name = PKG_NAME
s.version = PKG_VERSION
s.requirements << 'none'
s.files = PKG_FILES
s.description = "ActiveScaffold is a Rails plugin for rich ActiveRecord CRUD."
end

task :package_gem
Rake::GemPackageTask.new(spec) do |pkg|
pkg.need_zip = true
pkg.need_tar = true
end
rescue LoadError
end
101 changes: 101 additions & 0 deletions environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
##
## Check for dependencies
##
begin
Paginator rescue require('paginator')
rescue NameError, MissingSourceFile
message = <<-EOM
************************************************************************
Paginator gem is required! Try `sudo gem install paginator`,'
or see http://rubyforge.org/projects/paginator/ for more.'
************************************************************************
EOM
ActionController::Base::logger.error message
puts message
raise
end

##
## Load the library
##
require 'active_scaffold'
require 'configurable'
require 'finder'
require 'localization'

require 'helpers/active_scaffold_helpers'
require 'helpers/id_helpers'
require 'helpers/list_helpers'
require 'helpers/form_helpers'

require 'extensions/action_view'
require 'extensions/action_controller'
require 'extensions/active_record'
require 'extensions/array'

##
## Autoloading for some directories
## (this could probably be optimized more -lance)
##
def autoload_dir(directory, namespace)
Dir.entries(directory).each do |file|
next if file =~ /^\./
constant = File.basename(file, '.rb').camelcase
eval(namespace).autoload constant, File.join(directory, file)
end
end

module ActiveScaffold
module Config; end
module Actions; end
module DataStructures; end
end

autoload_dir "#{File.dirname __FILE__}/lib/config", "ActiveScaffold::Config"
autoload_dir "#{File.dirname __FILE__}/lib/actions", "ActiveScaffold::Actions"
autoload_dir "#{File.dirname __FILE__}/lib/data_structures", "ActiveScaffold::DataStructures"

##
## Inject includes for ActiveScaffold libraries
##

ActionController::Base.send(:include, ActiveScaffold)
ActionController::Base.send(:include, ActionView::Helpers::ActiveScaffoldIdHelpers)
ActionController::Base.send(:include, Localization)
ActionView::Base.send(:include, ActionView::Helpers::ActiveScaffoldHelpers)
ActionView::Base.send(:include, ActionView::Helpers::ActiveScaffoldIdHelpers)
ActionView::Base.send(:include, ActionView::Helpers::ActiveScaffoldListHelpers)
ActionView::Base.send(:include, ActionView::Helpers::ActiveScaffoldFormHelpers)

##
## Add MIME type for JSON
##

begin
# Edge Rails Method
Mime::Type.register "application/json", :json, %w( text/json )
rescue
# Rails 1.1 Method
# Register a new Mime::Type
Mime::JSON = Mime::Type.new 'application/json', :json, %w( text/json )
Mime::LOOKUP["application/json"] = Mime::JSON
Mime::LOOKUP["text/json"] = Mime::JSON

# Its default handler in responder
class ActionController::MimeResponds::Responder

DEFAULT_BLOCKS[:json] = %q{
Proc.new do
render(:action => "#{action_name}.rjson", :content_type => Mime::JSON, :layout => false)
end
}

for mime_type in %w( json )
eval <<-EOT
def #{mime_type}(&block)
custom(Mime::#{mime_type.upcase}, &block)
end
EOT
end
end
end
9 changes: 9 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
##
## Initialize the environment
##
require File.dirname(__FILE__) + '/environment'

##
## Run the install script, too, just to make sure
##
require File.dirname(__FILE__) + '/install'
25 changes: 25 additions & 0 deletions install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
##
## Copy over asset files (javascript/css/images) from the plugin directory to public/
##

def copy_files(source_path, destination_path, directory)
source, destination = File.join(directory, source_path), File.join(RAILS_ROOT, destination_path)
FileUtils.mkdir(destination) unless File.exist?(destination)
FileUtils.cp_r(Dir.glob(source+'/*.*'), destination)
end

directory = File.dirname(__FILE__)

copy_files("/public", "/public", directory)

available_themes = Dir[File.join(directory, 'themes', '*')].collect { |d| File.basename d }
[ :stylesheets, :javascripts, :images].each do |asset_type|
path = "/public/#{asset_type}/active_scaffold"
copy_files(path, path, directory)

available_themes.each do |theme|
source = "/themes/#{theme}/#{asset_type}/"
destination = "/public/#{asset_type}/active_scaffold/#{theme}"
copy_files(source, destination, directory)
end
end
65 changes: 65 additions & 0 deletions lib/actions/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module ActiveScaffold::Actions
# every action gets basic security control for free. this is accomplished by placing a before_filter on each public method of the action which calls a method that can be overwritten by the developer to enable security controls. the method is named #{action}_authorized?, and by default returns true.
# we also filter params[:record] on a per-action basis, as applicable.
module Base
def self.included(base)
base.extend ClassMethods
end

module ClassMethods
def included(base)
action_name = self.to_s.sub(/(.*::)+/, '')
action = action_name.underscore
config = base.active_scaffold_config
action_config = config.send(action.to_sym)

# overall action security: check controller.#{action}_authorized?
security_method = :"#{action}_authorized?"
base.send(:define_method, security_method) {true}
base.send :before_filter, security_method, :only => self.public_instance_methods(false)

# per-column (per-action) security: record which columns are not allowed for this user and this action. this will make columns.[] and columns.each operate securely for this action.
base.send :before_filter, proc { |controller|
current_user = controller.send(config.current_user_method) rescue nil
config.columns.create_blacklist(current_user, action)
}, :only => self.public_instance_methods(false)

# per-column (per-action) security: try to filter params[:record] so data can't sneak in
base.send :before_filter, proc { |controller|
if controller.params[:record]
controller.params[:record].each do |index, value|
##
## sometimes the parameter doesn't match the column name. here we attempt a couple of rewrites:
##
# first we deal with params like record[date_field(1i)]
column_name = index.sub(/\([a-z0-9]+\)/, '')
# then we check to see if this column is a primary_key_name for some association
config.columns.each do |column|
next unless column.association and column.association.primary_key_name.to_s == column_name
column_name = column.name.to_s and break
end

##
## then we verify that this column is registered for the action
##
unless action_config.columns.include? column_name
controller.logger.info "ActiveScaffold: params[:record][:#{index}] not found in column list (looked for #{column_name})"
controller.params[:record].delete(index)
end

##
## then we verify that the user is authorized to perform this action on this column
##
begin
config.columns[column_name.to_sym]
rescue ActiveScaffold::ColumnNotAllowed
controller.logger.info "ActiveScaffold: params[:record][:#{index}] not allowed for user"
controller.params[:record].delete(index)
end
end
end
}, :only => self.public_instance_methods(false)
end
end
end
end
Loading

0 comments on commit 341ff06

Please sign in to comment.