activeaclplus 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,6 +1,6 @@
1
1
  ActiveAcl rails authorization system
2
2
 
3
- Version 0.3.0 - WIP
3
+ Version 0.3.0 - 2008/12/07
4
4
  - Renamed Project to ActiveACLPlus
5
5
  - code cleanup
6
6
  - new repository on github with new maintainer
@@ -0,0 +1,55 @@
1
+ class <%= privileges_class_name %> < ApplicationController
2
+ verify :method => :post, :only => [ :create, :update],
3
+ :redirect_to => { :action => :list }
4
+
5
+ def index
6
+ redirect_to :action => :list
7
+ end
8
+
9
+ def list
10
+ @privileges = ActiveAcl::Privilege.find(:all, :order => 'section ASC, value ASC')
11
+ end
12
+
13
+ def edit
14
+ redirect_to :action => :list and return false unless params[:id]
15
+ begin
16
+ @privilege = ActiveAcl::Privilege.find(params[:id])
17
+ rescue ActiveRecord::RecordNotFound => e
18
+ flash[:error] = 'Privilege not found'
19
+ redirect_to :action => :list and return false
20
+ end
21
+ end
22
+
23
+ def update
24
+ redirect_to :action => :list and return false if params['commit'] == 'Cancel'
25
+
26
+ begin
27
+ @privilege = ActiveAcl::Privilege.find(params[:id].to_i)
28
+ rescue ActiveRecord::RecordNotFound => e
29
+ flash[:error] = 'Privilege not found'
30
+ redirect_to :action => :list and return false
31
+ end
32
+
33
+ if (@privilege.update_attributes(params[:privilege]))
34
+ flash[:success] = 'Privilege successfully updated'
35
+ redirect_to :action => :list and return false
36
+ else
37
+ flash.now[:error] = 'There was an error updating the Privilege'
38
+ @title = 'Edit Privilege'
39
+ render :action => :edit
40
+ end
41
+ end
42
+
43
+ def delete
44
+ redirect_to :action => :list and return false unless params[:id]
45
+ begin
46
+ privilege = ActiveAcl::Privilege.find(params[:id])
47
+ privilege.destroy
48
+ flash[:success] = 'Privilege successfully deleted'
49
+ rescue ActiveRecord::RecordNotFound => e
50
+ flash[:error] = 'Privilege not found'
51
+ end
52
+
53
+ redirect_to :action => :list and return false
54
+ end
55
+ end
@@ -0,0 +1,14 @@
1
+ <table border="0">
2
+ <tr>
3
+ <td>Section:</td>
4
+ <td><%= text_field 'permission', 'section' %></td>
5
+ </tr>
6
+ <tr>
7
+ <td>Value:</td>
8
+ <td><%= text_field 'permission', 'value' %></td>
9
+ </tr>
10
+ <tr>
11
+ <td>Description:</td>
12
+ <td><%= text_field 'permission', 'description' %></td>
13
+ </tr>
14
+ </table>
@@ -0,0 +1,17 @@
1
+ <html>
2
+ <body>
3
+ <% if flash[:error] %>
4
+ <p class="error"><%=h flash[:error] %></p>
5
+ <% elsif flash[:notice] %>
6
+ <p class="notice"><%=h flash[:notice] %></p>
7
+ <% elsif flash[:success] %>
8
+ <p class="notice"><%=h flash[:success] %></p>
9
+ <% else %>
10
+ <p>&nbsp;</p>
11
+ <% end %>
12
+ <%= form_tag({ :action => 'update', :id => @permission.id }) %>
13
+ <%= render_partial 'permission_form' %>
14
+ <%= submit_tag 'Save' %> <%= submit_tag 'Cancel' %>
15
+ </form>
16
+ </body>
17
+ </html>
@@ -0,0 +1,39 @@
1
+ <html>
2
+ <body>
3
+ <% if flash[:error] %>
4
+ <p class="error"><%=h flash[:error] %></p>
5
+ <% elsif flash[:notice] %>
6
+ <p class="notice"><%=h flash[:notice] %></p>
7
+ <% elsif flash[:success] %>
8
+ <p class="notice"><%=h flash[:success] %></p>
9
+ <% else %>
10
+ <p>&nbsp;</p>
11
+ <% end %>
12
+ <table border="0" cellpadding="5">
13
+ <tr>
14
+ <th>Section/Value</th>
15
+ <th>Description</th>
16
+ <th>&nbsp;</th>
17
+ </tr>
18
+ <% oldsection = nil %>
19
+ <% for permission in @permissions do %>
20
+ <% if permission.section != oldsection and oldsection != nil %>
21
+ <tr><td colspan="3">&nbsp;</td></tr>
22
+ <% end %>
23
+ <% unless permission.section == oldsection %>
24
+ <tr>
25
+ <td colspan="3"><b><%=h permission.section %></b></td>
26
+ </tr>
27
+ <% oldsection = permission.section %>
28
+ <% end %>
29
+ <tr>
30
+ <td><img src="/engine_files/gacl_engine/spacer.gif" height="1" width="20"><%= link_to permission.value, :action => 'edit', :id => permission.id %></td>
31
+ <td><%=h permission.description %></td>
32
+ <td>
33
+ <small>[<%= link_to 'delete', {:action => 'delete', :id => permission.id }, {:confirm => 'Shure to delete this Permission?'} %>]</small>
34
+ </td>
35
+ </tr>
36
+ <% end %>
37
+ </table>
38
+ </body>
39
+ </html>
@@ -0,0 +1,44 @@
1
+ # This is a cache adapter for the second level cache
2
+ # using the memcache daemon (http://www.danga.com/memcached).
3
+ # Sets itself as the cache adapter if the source file is loaded so a simple
4
+ # require is enough to activate the memcache. Before using the memcache, make shure to set MemcacheAdapter.cache.
5
+ #
6
+ # In environment.rb:
7
+ # require 'active_acl/cache/memcache_adapter'
8
+ # ActiveAcl::Cache::MemcacheAdapter.cache = MemCache.new('localhost:11211', :namespace => 'my_namespace')
9
+ #
10
+ # Detailed instructions on how to set up the server can be found at http://dev.robotcoop.com/Libraries/memcache-client.
11
+ class ActiveAcl::Cache::MemcacheAdapter
12
+
13
+ # returns the memcache server
14
+ def self.cache
15
+ @@cache
16
+ end
17
+
18
+ # sets the memcache server
19
+ def self.cache= cache
20
+ @@cache = cache
21
+ end
22
+
23
+ # get a value from the cache
24
+ def self.get(key)
25
+ value = @@cache.get(key)
26
+ RAILS_DEFAULT_LOGGER.debug 'GACL::SECOND_LEVEL_CACHE::' + (value.nil? ? 'MISS ' : 'HIT ')+ key.to_s if RAILS_DEFAULT_LOGGER.debug?
27
+ value
28
+ end
29
+
30
+ # set a value to the cache, specifying the time to live (ttl).
31
+ # Set ttl to 0 for unlimited.
32
+ def self.set(key, value, ttl)
33
+ @@cache.set(key, value, ttl)
34
+ RAILS_DEFAULT_LOGGER.debug 'GACL::SECOND_LEVEL_CACHE::SET ' + key.to_s + ' TO ' + value.to_s + ' TTL ' + ttl.to_s if RAILS_DEFAULT_LOGGER.debug?
35
+ end
36
+
37
+ # purge data from cache.
38
+ def self.delete(key)
39
+ @@cache.delete(key)
40
+ RAILS_DEFAULT_LOGGER.debug 'GACL::SECOND_LEVEL_CACHE::DELETE ' + key.to_s if RAILS_DEFAULT_LOGGER.debug?
41
+ end
42
+ end
43
+
44
+ ActiveAcl::OPTIONS[:cache] = ActiveAcl::Cache::MemcacheAdapter
@@ -0,0 +1,22 @@
1
+ # This module contains different second level cache implementations. The second
2
+ # level cache caches the instance cache of an access object between requests.
3
+ # Cache adapter can be set with ActiveAcl::OPTIONS[:cache].
4
+ module ActiveAcl::Cache
5
+
6
+ # The default second level cache dummy implementation, not implementing any
7
+ # caching functionality at all.
8
+ class NoCacheAdapter
9
+ def self.get(key)
10
+ RAILS_DEFAULT_LOGGER.debug 'GACL::SECOND_LEVEL_CACHE::DISABLED::MISS ' + key.to_s if RAILS_DEFAULT_LOGGER.debug?
11
+ nil
12
+ end
13
+
14
+ def self.set(key, value, ttl)
15
+ RAILS_DEFAULT_LOGGER.debug 'GACL::SECOND_LEVEL_CACHE::DISABLED::SET ' + key.to_s + ' TO ' + value.to_s + ' TTL ' + ttl.to_s if RAILS_DEFAULT_LOGGER.debug?
16
+ end
17
+
18
+ def self.delete(key)
19
+ RAILS_DEFAULT_LOGGER.debug 'GACL::SECOND_LEVEL_CACHE::DISABLED::DELETE ' + key.to_s if RAILS_DEFAULT_LOGGER.debug?
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ # Includes different DBMS adapters, some of them using C extensions to speed up DB access.
2
+ # DB adapter can be set with ActiveAcl::OPTIONS[:db].
3
+ module ActiveAcl::DB
4
+
5
+ # Uses ActiveRecord for privilege queries. Should be compatible to all
6
+ # db types.
7
+ class ActiveRecordAdapter
8
+ # Execute sql query against the DB, returning an array of results.
9
+ def self.query(sql)
10
+ ActiveRecord::Base.connection.select_all(sql)
11
+ end
12
+ end
13
+ end
14
+
15
+ ActiveAcl::OPTIONS[:db] = ActiveAcl::DB::ActiveRecordAdapter
@@ -0,0 +1,29 @@
1
+ require 'mysql'
2
+
3
+ # allow access to the real Mysql connection
4
+ class ActiveRecord::ConnectionAdapters::MysqlAdapter #:nodoc:
5
+ attr_reader :connection #:nodoc:
6
+ end
7
+
8
+ # Uses the native MySQL connection to do privilege selects. Should be around 20 % faster than
9
+ # ActiveRecord adapter. Sets itself as the DB adapter if the source file is loaded, so requiring it
10
+ # is enough to get it activated.
11
+ class ActiveAcl::DB::MySQLAdapter
12
+
13
+ # Execute sql query against the DB, returning an array of results.
14
+ def self.query(sql)
15
+ RAILS_DEFAULT_LOGGER.debug 'GACL::DB::EXECUTING QUERY ' + sql if RAILS_DEFAULT_LOGGER.debug?
16
+ connection = ActiveRecord::Base.connection.connection
17
+ connection.query_with_result = true
18
+
19
+ result = connection.query(sql)
20
+ rows = []
21
+ result.each_hash do |hash|
22
+ rows << hash
23
+ end if result
24
+ result.free
25
+ rows
26
+ end
27
+ end
28
+
29
+ ActiveAcl::OPTIONS[:db] = ActiveAcl::DB::MySQLAdapter
data/lib/active_acl.rb ADDED
@@ -0,0 +1,26 @@
1
+ module ActiveAcl
2
+ end
3
+
4
+ # plugin dependency
5
+ require 'has_many_polymorphs'
6
+
7
+ ActiveAcl::CONTROLLERS = {}
8
+
9
+ require 'active_acl/options'
10
+ require 'active_acl/privilege_const_set'
11
+ require 'active_acl/db/active_record_adapter'
12
+ require 'active_acl/cache/no_cache_adapter'
13
+ require 'active_acl/load_controller_actions'
14
+ require 'active_acl/acts_as_access_object'
15
+ require 'active_acl/acts_as_access_group'
16
+
17
+ require 'active_acl/load_files_from'
18
+
19
+ # call class so its loaded and registered as access object
20
+ # wrap in rescue block so migrations don't fail
21
+ begin
22
+ ActiveAcl::ControllerAction
23
+ ActiveAcl::ControllerGroup
24
+ rescue
25
+ nil
26
+ end
@@ -0,0 +1,4 @@
1
+ require 'rake/clean'
2
+
3
+ # coverage output directory - removed with "rake clobber"
4
+ CLOBBER.include("coverage")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeaclplus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Schrammel
@@ -33,8 +33,13 @@ extensions: []
33
33
  extra_rdoc_files: []
34
34
 
35
35
  files:
36
+ - lib/active_acl
36
37
  - lib/active_acl/db
38
+ - lib/active_acl/db/mysql_adapter.rb
39
+ - lib/active_acl/db/active_record_adapter.rb
37
40
  - lib/active_acl/cache
41
+ - lib/active_acl/cache/no_cache_adapter.rb
42
+ - lib/active_acl/cache/memcache_adapter.rb
38
43
  - lib/active_acl/target_group_link.rb
39
44
  - lib/active_acl/controller_action.rb
40
45
  - lib/active_acl/acl_section.rb
@@ -50,8 +55,19 @@ files:
50
55
  - lib/active_acl/privilege_const_set.rb
51
56
  - lib/active_acl/requester_group_link.rb
52
57
  - lib/active_acl/acts_as_access_group.rb
58
+ - lib/active_acl.rb
59
+ - tasks/active_acl_base_tasks.rake
60
+ - generators/active_acl
53
61
  - generators/active_acl/templates
62
+ - generators/active_acl/templates/controllers
63
+ - generators/active_acl/templates/controllers/privileges_controller.rb
64
+ - generators/active_acl/templates/views
65
+ - generators/active_acl/templates/views/privileges
66
+ - generators/active_acl/templates/views/privileges/list.rhtml
67
+ - generators/active_acl/templates/views/privileges/edit.rhtml
68
+ - generators/active_acl/templates/views/privileges/_privilege_form.rhtml
54
69
  - generators/active_acl/active_acl_generator.rb
70
+ - db/migrate
55
71
  - db/migrate/001_base_table_setup.rb
56
72
  - init.rb
57
73
  - install.rb