Permalink
Browse files

abstracted the acl hanlers

ungrouped requesters/targets
spec
  • Loading branch information...
1 parent fa01ed3 commit e8a1797e9df935604d0f9f35a0aa50be3ca3ee01 @pschrammel committed Mar 4, 2009
Showing with 563 additions and 364 deletions.
  1. +8 −0 .gitignore
  2. +7 −1 CHANGELOG
  3. +109 −45 README.rdoc
  4. +13 −14 Rakefile
  5. +4 −5 active_acl_plus.gemspec
  6. +1 −1 {generators/active_acl/templates → app}/controllers/privileges_controller.rb
  7. +5 −5 {lib → app/models}/active_acl/acl.rb
  8. +3 −3 {lib → app/models}/active_acl/acl_section.rb
  9. +1 −1 {lib → app/models}/active_acl/controller_action.rb
  10. +1 −1 {lib → app/models}/active_acl/controller_group.rb
  11. 0 {lib → app/models}/active_acl/privilege.rb
  12. 0 {lib → app/models}/active_acl/requester_group_link.rb
  13. 0 {lib → app/models}/active_acl/requester_link.rb
  14. 0 {lib → app/models}/active_acl/target_group_link.rb
  15. 0 {lib → app/models}/active_acl/target_link.rb
  16. 0 {generators/active_acl/templates/views → app/view}/privileges/_privilege_form.rhtml
  17. 0 {generators/active_acl/templates/views → app/view}/privileges/edit.rhtml
  18. 0 {generators/active_acl/templates/views → app/view}/privileges/list.rhtml
  19. +7 −4 db/migrate/001_base_table_setup.rb
  20. +0 −29 generators/active_acl/active_acl_generator.rb
  21. +1 −1 init.rb
  22. +11 −5 lib/active_acl.rb
  23. +17 −22 lib/active_acl/acts_as_access_group.rb
  24. +41 −208 lib/active_acl/acts_as_access_object.rb
  25. +17 −0 lib/active_acl/base.rb
  26. +4 −4 lib/active_acl/cache/memcache_adapter.rb
  27. +5 −5 lib/active_acl/cache/no_cache_adapter.rb
  28. +3 −3 lib/active_acl/db/active_record_adapter.rb
  29. +2 −2 lib/active_acl/db/mysql_adapter.rb
  30. +38 −0 lib/active_acl/grant.rb
  31. +29 −0 lib/active_acl/handler/nested_set.rb
  32. +233 −0 lib/active_acl/handler/object_handler.rb
  33. +1 −3 lib/active_acl/load_controller_actions.rb
  34. +2 −2 lib/active_acl/privilege_const_set.rb
View
@@ -0,0 +1,8 @@
+spec
+test
+trash
+pkg
+rdoc
+.project
+.loadpath
+.DS_STORE
View
@@ -1,6 +1,12 @@
ActiveAcl rails authorization system
-Version wip
+Version 0.4.0 - 2008/03/08
+- complete rewrite of the SQL generation
+- abstraction of the grouping
+- added #grant_privilege
+- dropped test, moving to rspec
+- allows ungrouped requesters/targets
+- propper namespace handling of options (THANKS http://github.com/garytaylor)
Version 0.3.1 - 2008/12/11
- forgot active_acl.rb in gem
View
Oops, something went wrong.
View
@@ -18,13 +18,8 @@ Rake::GemPackageTask.new(PKG_GEM) do |p|
p.need_zip = true
end
-desc 'Default: run unit tests.'
-task :default => :test
-
-#desc "Publish the beta gem"
-#task :pgem => [:package] do
-# Rake::SshFilePublisher.new("pluginaweek@pluginaweek.org", "/home/pluginaweek/gems.pluginaweek.org/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
-#end
+desc 'Default: run specs'
+task :default => :spec
desc "Publish the API documentation"
task :pdoc => [:rdoc] do
@@ -67,18 +62,22 @@ task :coverage_diff do
sh "#{RCOV} --rails -T -Ilib -x db/**/* --text-coverage-diff ../../../coverage/active_acl/coverage.info --output ../../../coverage/active_acl test/all_tests.rb"
end
-desc 'Test the active_acl_plus plugin.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.pattern = 'test/unit/**/*_test.rb'
- t.verbose = true
+begin #no spec or spec-rails? ok no tasks
+ require 'spec/rake/spectask'
+
+ desc 'Test the active_acl_plus plugin.'
+ Spec::Rake::SpecTask.new(:spec) do |t|
+ #t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ end
+rescue LoadError => e
+ puts "No spec tasks! - gem install rspec-rails (#{__FILE__})"
end
desc 'Generate documentation for the active_acl_plus plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'ActiveAclPlus'
rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
- rdoc.rdoc_files.include('lib/**/*.rb')
+ rdoc.rdoc_files.include('README.rdoc','lib/**/*.rb','app/**/*.rb')
end
View
@@ -2,7 +2,7 @@
require 'rake'
PKG_NAME='activeaclplus'
-PKG_VERSION= "0.3.1"
+PKG_VERSION= "0.4.0"
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
PKG_GEM=Gem::Specification.new do |s|
@@ -16,14 +16,13 @@ PKG_GEM=Gem::Specification.new do |s|
s.email = ["peter.schrammel@gmx.de"]
s.platform = Gem::Platform::RUBY
s.extra_rdoc_files = []
- s.files = FileList["{lib,tasks,generators,db}/**/*"].to_a + %w(init.rb install.rb LICENSE Rakefile README.rdoc CHANGELOG)
+ s.files = FileList["{lib,tasks,generators,db,app}/**/*"].to_a + %w(init.rb install.rb LICENSE Rakefile README.rdoc CHANGELOG)
s.has_rdoc = true
s.homepage = %q{http://activeaclplus.rubyforge.org/}
- s.rdoc_options = ["--main", "README.rdoc"]
+ s.rdoc_options = [ "--title", "Active Acl Plus", "--main", "README.rdoc"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{activeaclplus}
- s.rubygems_version = %q{0.3.0}
- s.summary = %q{activeaclplus 0.3.0}
+ s.summary = "A new Version (#{PKG_VERSION}) of ActiveAclPlus is available."
s.add_dependency "rails", ">= 2.1.0"
end
@@ -1,4 +1,4 @@
-class <%= privileges_class_name %> < ApplicationController
+class PrivilegesController < ApplicationController
verify :method => :post, :only => [ :create, :update],
:redirect_to => { :action => :list }
@@ -14,20 +14,20 @@ class Acl < ActiveRecord::Base
has_many :requester_group_links, :dependent => :delete_all,:class_name => 'ActiveAcl::RequesterGroupLink'
has_many :target_group_links, :dependent => :delete_all,:class_name => 'ActiveAcl::TargetGroupLink'
- validates_uniqueness_of :note
- validates_presence_of :note
+ validates_uniqueness_of :iname
+ validates_presence_of :iname
def self.reloadable? #:nodoc:
return false
end
# used as instance description in admin screen
def active_acl_description
- if note
+ if iname
if section
- '/' + section.description + '/' + note
+ '/' + section.description + '/' + iname
else
- return note
+ return iname
end
else
return nil
@@ -6,11 +6,11 @@ class AclSection < ActiveRecord::Base
has_many :members, :class_name => 'ActiveAcl::Acl', :foreign_key => 'section_id'
- validates_presence_of :description
- validates_uniqueness_of :description
+ validates_presence_of :iname
+ validates_uniqueness_of :iname
# Make shure there are no associated acls before destroying a section
- def before_destroy
+ def before_destroy #:nodoc:
if members.empty?
true
else
@@ -3,7 +3,7 @@
class ActiveAcl::ControllerAction < ActiveRecord::Base
set_table_name ActiveAcl::OPTIONS[:controller_actions_table]
privilege_const_set('EXECUTE')
-
+
belongs_to :controller_group, :class_name => 'ActiveAcl::ControllerGroup'
acts_as_access_object :grouped_by => :"active_acl/controller_group"
validates_presence_of :action, :controller, :controller_group
@@ -3,7 +3,7 @@ class ActiveAcl::ControllerGroup < ActiveRecord::Base
set_table_name ActiveAcl::OPTIONS[:controller_groups_table]
acts_as_nested_set
has_many :controller_actions,:class_name => 'ActiveAcl::ControllerAction'
- acts_as_access_group
+ acts_as_access_group :type => ActiveAcl::Acts::AccessGroup::NestedSet
validates_presence_of :description
File renamed without changes.
@@ -2,22 +2,25 @@ class BaseTableSetup < ActiveRecord::Migration
def self.up
create_table ActiveAcl::OPTIONS[:acls_table] do |t|
t.column :section_id, :int
+ t.column :iname, :string,:null => false
t.column :allow, :boolean, :null => false, :default => true
t.column :enabled, :boolean, :null => false, :default => true
- t.column :note, :string, :null => true
+ t.column :description, :text, :null => true
t.column :updated_at, :datetime, :null => false
end
add_index ActiveAcl::OPTIONS[:acls_table], :enabled
add_index ActiveAcl::OPTIONS[:acls_table], :section_id
add_index ActiveAcl::OPTIONS[:acls_table], :updated_at
- add_index ActiveAcl::OPTIONS[:acls_table], :note, :unique
+ add_index ActiveAcl::OPTIONS[:acls_table], :iname, :unique
+
create_table ActiveAcl::OPTIONS[:acl_sections_table] do |t|
- t.column :description, :string, :limit => 230, :null => false
+ t.column :iname, :string, :null => false
+ t.column :description, :text, :null => true
end
- add_index ActiveAcl::OPTIONS[:acl_sections_table], :description, :unique
+ add_index ActiveAcl::OPTIONS[:acl_sections_table], :iname, :unique
create_table ActiveAcl::OPTIONS[:privileges_table] do |t|
t.column :section, :string, :limit => 230, :null => false
@@ -1,29 +0,0 @@
-class ActiveAclGenerator < Rails::Generator::Base
- attr_accessor :privileges_class_name, :privileges_file_name, :privileges_view_dir
-
- def initialize(*runtime_args)
- super(*runtime_args)
- @privileges_class_name = (args[0] || 'PrivilegesController')
- @privileges_file_name = @privileges_class_name.underscore
- @privileges_view_dir = File.join('app', 'views', @privileges_file_name.gsub('_controller', ''))
- end
-
- def manifest
- record do |m|
- # Stylesheet, controllers and public directories.
- m.directory File.join('public', 'stylesheets')
- m.directory File.join('app', 'controllers')
- m.directory File.join('app', 'views')
- m.directory privileges_view_dir
-
- m.template 'controllers/privileges_controller.rb', File.join('app', 'controllers', "#{privileges_file_name}.rb")
- m.file 'views/privileges/_privilege_form.rhtml', File.join(privileges_view_dir, '_privilege_form.rhtml')
- m.file 'views/privileges/edit.rhtml', File.join(privileges_view_dir, 'edit.rhtml')
- m.file 'views/privileges/list.rhtml', File.join(privileges_view_dir, 'list.rhtml')
- m.migration_template('../../../db/migrate/001_base_table_setup.rb',
- 'db/migrate',
- :assigns => {:migration_name => "BaseTableSetup"},
- :migration_file_name => "base_table_setup")
- end
- end
-end
View
@@ -1 +1 @@
-require 'active_acl'
+require 'active_acl'
View
@@ -1,26 +1,32 @@
module ActiveAcl
+
+
end
# plugin dependency
require 'has_many_polymorphs'
-ActiveAcl::CONTROLLERS = {}
-
require 'active_acl/options'
+require 'active_acl/base'
+
require 'active_acl/privilege_const_set'
+require 'active_acl/grant'
+
+require 'active_acl/handler/object_handler'
+require 'active_acl/handler/nested_set'
require 'active_acl/db/active_record_adapter'
require 'active_acl/cache/no_cache_adapter'
require 'active_acl/load_controller_actions'
require 'active_acl/acts_as_access_object'
require 'active_acl/acts_as_access_group'
-
require 'active_acl/load_files_from'
+
# call class so its loaded and registered as access object
# wrap in rescue block so migrations don't fail
begin
ActiveAcl::ControllerAction
ActiveAcl::ControllerGroup
-rescue
- nil
+rescue StandardError => e
+ puts "Error #{e.message} #{e.backtrace.join("\n")}(need migrations?)"
end
@@ -7,38 +7,33 @@ module AccessGroup #:nodoc:
def self.included(base)
base.extend(ClassMethods)
end
-
+
module ClassMethods
- # Extend self with access group capabilites. See README for details
- # on usage. Accepts the following options as a hash:
- # left_column:: name of the left column for nested set functionality, default :lft
- # right_column:: name of the right column for nested set functionality, default :rgt
- # Don't use 'left' and 'right' as column names - these are reserved words in most DBMS.
+ # Extend self with access group capabilites.
+ # Options can be:
+ # type:: is mandatory and is one of the group handler classes
+ # left_column:: for ActiveAcl::Acts::AccessGroup::NestedSet grouped objects
+ # right_column:: for ActiveAcl::Acts::AccessGroup::NestedSet grouped objects
+
def acts_as_access_group(options = {})
- configuration = {:left_column => :lft, :right_column => :rgt,
- :controller => ActiveAcl::OPTIONS[:default_group_selector_controller],
- :action => ActiveAcl::OPTIONS[:default_group_selector_action]}
- configuration.update(options) if options.is_a?(Hash)
- ActiveAcl::GROUP_CLASSES[self.name] = configuration
+ type=options.delete(:type) || ActiveAcl::Acts::AccessGroup::NestedSet
+ ActiveAcl::GROUP_CLASSES[self.name] = type.new(options)
+
+ include ActiveAcl::Acts::Grant
+ include InstanceMethods
+ extend SingletonMethods
- from_classes = ActiveAcl::GROUP_CLASSES.keys.collect do |x|
- x.split('::').join('/').underscore.pluralize.to_sym
- end
-
ActiveAcl::Acl.instance_eval do
- has_many_polymorphs :requester_groups, {:from => from_classes,
+ has_many_polymorphs :requester_groups, {:from => ActiveAcl.from_classes,
:through => :"active_acl/requester_group_links",
:rename_individual_collections => true}
-
- has_many_polymorphs :target_groups, {:from => from_classes,
+
+ has_many_polymorphs :target_groups, {:from => ActiveAcl.from_classes,
:through => :"active_acl/target_group_links",
:rename_individual_collections => true}
end
- include InstanceMethods
- extend SingletonMethods
-
- end
+ end
end
module SingletonMethods
Oops, something went wrong.

0 comments on commit e8a1797

Please sign in to comment.