timcharper-declarative_authorization 0.4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. data/CHANGELOG +135 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +503 -0
  4. data/Rakefile +43 -0
  5. data/app/controllers/authorization_rules_controller.rb +259 -0
  6. data/app/controllers/authorization_usages_controller.rb +23 -0
  7. data/app/helpers/authorization_rules_helper.rb +218 -0
  8. data/app/views/authorization_rules/_change.erb +58 -0
  9. data/app/views/authorization_rules/_show_graph.erb +37 -0
  10. data/app/views/authorization_rules/_suggestions.erb +48 -0
  11. data/app/views/authorization_rules/change.html.erb +169 -0
  12. data/app/views/authorization_rules/graph.dot.erb +68 -0
  13. data/app/views/authorization_rules/graph.html.erb +40 -0
  14. data/app/views/authorization_rules/index.html.erb +17 -0
  15. data/app/views/authorization_usages/index.html.erb +36 -0
  16. data/authorization_rules.dist.rb +20 -0
  17. data/config/routes.rb +7 -0
  18. data/garlic_example.rb +20 -0
  19. data/init.rb +5 -0
  20. data/lib/declarative_authorization.rb +15 -0
  21. data/lib/declarative_authorization/authorization.rb +683 -0
  22. data/lib/declarative_authorization/development_support/analyzer.rb +252 -0
  23. data/lib/declarative_authorization/development_support/change_analyzer.rb +253 -0
  24. data/lib/declarative_authorization/development_support/change_supporter.rb +620 -0
  25. data/lib/declarative_authorization/development_support/development_support.rb +243 -0
  26. data/lib/declarative_authorization/helper.rb +60 -0
  27. data/lib/declarative_authorization/in_controller.rb +623 -0
  28. data/lib/declarative_authorization/in_model.rb +162 -0
  29. data/lib/declarative_authorization/maintenance.rb +198 -0
  30. data/lib/declarative_authorization/obligation_scope.rb +345 -0
  31. data/lib/declarative_authorization/rails_legacy.rb +14 -0
  32. data/lib/declarative_authorization/reader.rb +472 -0
  33. data/test/authorization_test.rb +971 -0
  34. data/test/controller_filter_resource_access_test.rb +511 -0
  35. data/test/controller_test.rb +465 -0
  36. data/test/dsl_reader_test.rb +157 -0
  37. data/test/helper_test.rb +171 -0
  38. data/test/maintenance_test.rb +46 -0
  39. data/test/model_test.rb +1694 -0
  40. data/test/schema.sql +54 -0
  41. data/test/test_helper.rb +134 -0
  42. metadata +119 -0
data/test/schema.sql ADDED
@@ -0,0 +1,54 @@
1
+ CREATE TABLE 'test_models' (
2
+ 'id' INTEGER PRIMARY KEY NOT NULL,
3
+ 'test_attr_through_id' INTEGER,
4
+ 'content' text,
5
+ 'country_id' integer,
6
+ 'created_at' datetime,
7
+ 'updated_at' datetime
8
+ );
9
+
10
+ CREATE TABLE 'test_attrs' (
11
+ 'id' INTEGER PRIMARY KEY NOT NULL,
12
+ 'test_model_id' integer,
13
+ 'test_another_model_id' integer,
14
+ 'test_a_third_model_id' integer,
15
+ 'branch_id' integer,
16
+ 'company_id' integer,
17
+ 'test_attr_through_id' INTEGER,
18
+ 'n_way_join_item_id' INTEGER,
19
+ 'test_model_security_model_id' integer,
20
+ 'attr' integer default 1
21
+ );
22
+
23
+ CREATE TABLE 'test_attr_throughs' (
24
+ 'id' INTEGER PRIMARY KEY NOT NULL,
25
+ 'test_attr_id' integer
26
+ );
27
+
28
+ CREATE TABLE 'test_model_security_models' (
29
+ 'id' INTEGER PRIMARY KEY NOT NULL,
30
+ 'attr' integer default 1,
31
+ 'attr_2' integer default 1
32
+ );
33
+
34
+ CREATE TABLE 'n_way_join_items' (
35
+ 'id' INTEGER PRIMARY KEY NOT NULL
36
+ );
37
+
38
+ CREATE TABLE 'branches' (
39
+ 'id' INTEGER PRIMARY KEY NOT NULL,
40
+ 'company_id' integer,
41
+ 'name' text
42
+ );
43
+
44
+ CREATE TABLE 'companies' (
45
+ 'id' INTEGER PRIMARY KEY NOT NULL,
46
+ 'country_id' integer,
47
+ 'type' text,
48
+ 'name' text
49
+ );
50
+
51
+ CREATE TABLE 'countries' (
52
+ 'id' INTEGER PRIMARY KEY NOT NULL,
53
+ 'name' text
54
+ );
@@ -0,0 +1,134 @@
1
+ require 'test/unit'
2
+
3
+ unless defined?(RAILS_ROOT)
4
+ RAILS_ROOT = ENV['RAILS_ROOT'] ?
5
+ ENV['RAILS_ROOT'] + "" :
6
+ File.join(File.dirname(__FILE__), %w{.. .. .. ..})
7
+ end
8
+
9
+ require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization rails_legacy})
10
+ require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization authorization})
11
+ require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization in_controller})
12
+ require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization maintenance})
13
+
14
+ unless defined?(ActiveRecord)
15
+ if File.directory? RAILS_ROOT + '/config'
16
+ puts 'Using config/boot.rb'
17
+ ENV['RAILS_ENV'] = 'test'
18
+ require File.join(RAILS_ROOT, 'config', 'environment.rb')
19
+ else
20
+ # simply use installed gems if available
21
+ version_requirement = ENV['RAILS_VERSION'] ? "= #{ENV['RAILS_VERSION']}" : nil
22
+ puts "Using Rails from RubyGems (#{version_requirement || "default"})"
23
+ require 'rubygems'
24
+ %w{actionpack activerecord activesupport rails}.each do |gem_name|
25
+ gem gem_name, version_requirement || "> 2.1.0"
26
+ end
27
+ end
28
+
29
+ unless defined?(Rails) # needs to be explicit in Rails < 3
30
+ %w(action_pack action_controller active_record active_support initializer).each {|f| require f}
31
+ end
32
+ end
33
+
34
+ begin
35
+ require 'ruby-debug'
36
+ rescue MissingSourceFile; end
37
+
38
+
39
+ class MockDataObject
40
+ def initialize (attrs = {})
41
+ attrs.each do |key, value|
42
+ instance_variable_set(:"@#{key}", value)
43
+ self.class.class_eval do
44
+ attr_reader key
45
+ end
46
+ end
47
+ end
48
+
49
+ def self.descends_from_active_record?
50
+ true
51
+ end
52
+
53
+ def self.table_name
54
+ name.tableize
55
+ end
56
+
57
+ def self.name
58
+ "Mock"
59
+ end
60
+
61
+ def self.find(*args)
62
+ raise "Couldn't find #{self.name} with id #{args[0].inspect}" unless args[0]
63
+ new :id => args[0]
64
+ end
65
+ end
66
+
67
+ class MockUser < MockDataObject
68
+ def initialize (*roles)
69
+ options = roles.last.is_a?(::Hash) ? roles.pop : {}
70
+ super(options.merge(:role_symbols => roles, :login => hash))
71
+ end
72
+
73
+ def initialize_copy (other)
74
+ @role_symbols = @role_symbols.clone
75
+ end
76
+ end
77
+
78
+ class MocksController < ActionController::Base
79
+ attr_accessor :current_user
80
+ attr_writer :authorization_engine
81
+
82
+ def authorized?
83
+ !!@authorized
84
+ end
85
+
86
+ def self.define_action_methods (*methods)
87
+ methods.each do |method|
88
+ define_method method do
89
+ @authorized = true
90
+ render :text => 'nothing'
91
+ end
92
+ end
93
+ end
94
+
95
+ def self.define_resource_actions
96
+ define_action_methods :index, :show, :edit, :update, :new, :create, :destroy
97
+ end
98
+
99
+ def logger (*args)
100
+ Class.new do
101
+ def warn(*args)
102
+ #p args
103
+ end
104
+ alias_method :info, :warn
105
+ alias_method :debug, :warn
106
+ def warn?; end
107
+ alias_method :info?, :warn?
108
+ alias_method :debug?, :warn?
109
+ end.new
110
+ end
111
+ end
112
+
113
+ ActionController::Routing::Routes.draw do |map|
114
+ map.connect ':controller/:action/:id'
115
+ end
116
+ ActionController::Base.send :include, Authorization::AuthorizationInController
117
+ if Rails.version < "3"
118
+ require "action_controller/test_process"
119
+ end
120
+
121
+ class Test::Unit::TestCase
122
+ include Authorization::TestHelper
123
+
124
+ def request! (user, action, reader, params = {})
125
+ action = action.to_sym if action.is_a?(String)
126
+ @controller.current_user = user
127
+ @controller.authorization_engine = Authorization::Engine.new(reader)
128
+
129
+ ((params.delete(:clear) || []) + [:@authorized]).each do |var|
130
+ @controller.instance_variable_set(var, nil)
131
+ end
132
+ get action, params
133
+ end
134
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timcharper-declarative_authorization
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 1
9
+ - 2
10
+ version: 0.4.1.2
11
+ platform: ruby
12
+ authors:
13
+ - Steffen Bartsch
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-03-24 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 1
31
+ - 0
32
+ version: 2.1.0
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description:
36
+ email: sbartsch@tzi.org
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
+ - CHANGELOG
44
+ files:
45
+ - CHANGELOG
46
+ - MIT-LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - authorization_rules.dist.rb
50
+ - garlic_example.rb
51
+ - init.rb
52
+ - app/controllers/authorization_rules_controller.rb
53
+ - app/controllers/authorization_usages_controller.rb
54
+ - app/helpers/authorization_rules_helper.rb
55
+ - app/views/authorization_usages/index.html.erb
56
+ - app/views/authorization_rules/index.html.erb
57
+ - app/views/authorization_rules/_show_graph.erb
58
+ - app/views/authorization_rules/_change.erb
59
+ - app/views/authorization_rules/_suggestions.erb
60
+ - app/views/authorization_rules/graph.dot.erb
61
+ - app/views/authorization_rules/change.html.erb
62
+ - app/views/authorization_rules/graph.html.erb
63
+ - config/routes.rb
64
+ - lib/declarative_authorization.rb
65
+ - lib/declarative_authorization/in_controller.rb
66
+ - lib/declarative_authorization/reader.rb
67
+ - lib/declarative_authorization/rails_legacy.rb
68
+ - lib/declarative_authorization/obligation_scope.rb
69
+ - lib/declarative_authorization/in_model.rb
70
+ - lib/declarative_authorization/helper.rb
71
+ - lib/declarative_authorization/development_support/analyzer.rb
72
+ - lib/declarative_authorization/development_support/change_analyzer.rb
73
+ - lib/declarative_authorization/development_support/change_supporter.rb
74
+ - lib/declarative_authorization/development_support/development_support.rb
75
+ - lib/declarative_authorization/authorization.rb
76
+ - lib/declarative_authorization/maintenance.rb
77
+ - test/authorization_test.rb
78
+ - test/schema.sql
79
+ - test/maintenance_test.rb
80
+ - test/model_test.rb
81
+ - test/controller_test.rb
82
+ - test/helper_test.rb
83
+ - test/dsl_reader_test.rb
84
+ - test/controller_filter_resource_access_test.rb
85
+ - test/test_helper.rb
86
+ has_rdoc: true
87
+ homepage: http://github.com/stffn/declarative_authorization
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options: []
92
+
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ segments:
100
+ - 1
101
+ - 8
102
+ - 6
103
+ version: 1.8.6
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ requirements: []
112
+
113
+ rubyforge_project:
114
+ rubygems_version: 1.3.6
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: declarative_authorization is a Rails plugin for authorization based on readable authorization rules.
118
+ test_files: []
119
+