cantango 0.9.4.3 → 0.9.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,12 +2,13 @@ h1. CanTango
2
2
 
3
3
  CanTango is an advanced Access Control (permissions) system for Rails 3. It:
4
4
 
5
- * extends "CanCan":http://github.com/ryanb/cancan and offers a more role oriented design
5
+ * extends "CanCan":http://github.com/ryanb/cancan and offers a more granular Object Oriented design
6
6
  * integrates with _role_ and _authentication_ systems in a non-intrusive manner
7
7
  * can _cache_ ability rules between requests for increased performance
8
- * can _store_ abilites in a permission store, including a YAML file, for easy administration
9
- * works well with multiple user accounts and sub applications
10
- * supports multiple "Devise":https://github.com/plataformatec/devise users
8
+ * allows for context specific "Permits":https://github.com/kristianmandrup/cantango/wiki/Permits with rules
9
+ * supports multiple "Devise":https://github.com/plataformatec/devise users/accounts
10
+ * can _store_ static ability rules in a permission store for easy administration
11
+ * manage the permission store from a web UI using the "cantango_editor":https://github.com/stanislaw/cantango_editor, a mountable Rails engine
11
12
 
12
13
  h3. Will CanTango meet my Access Control (permission) requirements?
13
14
 
@@ -35,47 +36,11 @@ Run bundler in a terminal/console from the folder of your Gemfile (root folder o
35
36
 
36
37
  @$ bundle@
37
38
 
38
- h2. Update Nov 4, 2011
39
+ h2. Update Nov 21, 2011
39
40
 
40
- Version 0.9.4.2 has been released with the following features and improvements:
41
+ Version 0.9.4.5 has been released. Fixes bug in configuration/permit_registry.
41
42
 
42
- * Redesign of Cache and Ability execution
43
- * Caching at the individual engine level that can be switched (configured) on/off
44
- * Individual caching for each type of Permit in the Permit engine
45
- * Each engine return a set of rules which are merged into one rule set for that particular execution mode
46
- * Caching for the new User AC engine
47
- * Ability to register your own Permit base classes simply by subclassing CanTango::Permit!
48
- * This is useful if you want to go beyond the built in types, see the @custom_permit_spec.rb@ for an example
49
- * Some bug fixes!
50
-
51
- The :user_ac engine is a port of the Permission system from the _Rails in Action_ book.
52
- With this engine a user can have many permissions defined, where each such permission is a persisted Permission model instance that describes a 'can' action on a specific type of object.
53
-
54
- The new modal Ability model allows you to define rules that are run in Cache mode and others that can be run in no-cache mode. This enables you to circumvent the previos restriction that didn't allow you to use normal conditional ruby logic outside blocks if you enabled caching.
55
-
56
- <pre>
57
- class UserPermit < CanTango::UserPermit
58
- def static_rules
59
- can :access, Article
60
- end
61
-
62
- module Cached
63
- def permit_rules
64
- can :read, Project
65
- end
66
- end
67
-
68
- module NonCached
69
- def permit_rules
70
- can :edit, Article
71
- end
72
- end
73
- end
74
- </pre>
75
-
76
- Any rule method defined directly for the permit is run for any (or both) modes. To define rules specifically for cache or no-cache modes, you should place them in a nested module to signify this as shown in this example.
77
-
78
- You can configure modes with the new config object @CanTango.config.ability.modes@ and set it via @CanTango.config.ability.mode = :no_cache@ . The valid modes are: :cache, :no_cache, and :both. You can similarly configure which modes each engine should participate in, fx via @CanTango.config.permit_engine.mode = :cache@
43
+ The "wiki":https://github.com/kristianmandrup/cantango/wiki has been rewritten and updated to reflect all latest design changes and feature additions.
79
44
 
80
45
  h2. Quickstart
81
46
 
@@ -95,7 +60,7 @@ Simply start with:
95
60
 
96
61
  * cantango:install
97
62
 
98
- To use the Permit generators please see the Generators wiki page ;)
63
+ To use the Permit generators please see the "Generators":https://github.com/kristianmandrup/cantango/wiki/Generators page ;)
99
64
 
100
65
  h3. Rails 3 configuration
101
66
 
@@ -118,19 +83,17 @@ Abilities can be defined for the following conceptual entities:
118
83
  * Role groups
119
84
  * Users
120
85
 
121
- h3. Debugging Abilities and Permits
122
-
123
- See "Debugging permits"::https://github.com/kristianmandrup/cantango/wiki/Debugging-permits
86
+ You can even create your own Permit types to suit your own needs! This feature will be further improved in the upcoming 1.0 release.
124
87
 
125
88
  h3. Design overview
126
89
 
127
90
  The default CanTango Ability pattern is simple.
128
91
 
129
- 1. Return cached ability rules for candidate if available
92
+ 1. Return cached ability rules for candidate if available (and cache is on)
130
93
  2. Generate rules for candidate
131
- 3. Cache rules for candidate
94
+ 3. Cache rules for candidate (if cache is on)
132
95
 
133
- A candidate is typically either a user or an account instance.
96
+ An ability candidate is typically either a user or an account instance.
134
97
 
135
98
  Caching can be enabled or disabled. To generate the rules, one or more engines are executed.
136
99
 
@@ -139,7 +102,7 @@ CanTango comes with the following engines:
139
102
  * "Permit engine"::https://github.com/kristianmandrup/cantango/wiki/Permit-engine
140
103
  * "Permission engine":https://github.com/kristianmandrup/cantango/wiki/Permission-engine
141
104
 
142
- You can however freely plugin or unplug engines as you wish as described in "Pluggable engines":https://github.com/kristianmandrup/cantango/wiki/Pluggable-engines
105
+ You can however freely plugin or unplug engines as you wish as described in "Engines":https://github.com/kristianmandrup/cantango/wiki/Engines
143
106
 
144
107
  h3. Dependencies, Adapters and Loading
145
108
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.4.3
1
+ 0.9.4.5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cantango}
8
- s.version = "0.9.4.3"
8
+ s.version = "0.9.4.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Kristian Mandrup}, %q{Stanislaw Pankevich}]
12
- s.date = %q{2011-11-05}
12
+ s.date = %q{2011-11-21}
13
13
  s.description = %q{Define your permission rules as role- or role group specific permits.
14
14
  Integrates well with multiple Devise user acounts.
15
15
  Includes rules caching.
@@ -332,6 +332,7 @@ Store permissions in yaml file or key-value store}
332
332
  "spec/cantango/api/user_account/scope_api_spec.rb",
333
333
  "spec/cantango/api/user_account_api_spec.rb",
334
334
  "spec/cantango/api/user_api_spec.rb",
335
+ "spec/cantango/api_spec.rb",
335
336
  "spec/cantango/cached_ability_spec.rb",
336
337
  "spec/cantango/configuration/ability_spec.rb",
337
338
  "spec/cantango/configuration/adapter_spec.rb",
@@ -1,12 +1,16 @@
1
1
  module CanTango
2
2
  class AbilityExecutor < CanTango::Ability
3
- attr_reader :rules
4
3
 
5
4
  def initialize candidate, options = {}
6
5
  raise "Candidate must be something!" if !candidate
7
6
  @candidate, @options = [candidate, options]
8
7
  @rules = cached_rules + non_cached_rules
9
- @rules.flatten!.compact!
8
+ rules.flatten!
9
+ rules.compact!
10
+ end
11
+
12
+ def rules
13
+ @rules ||= []
10
14
  end
11
15
 
12
16
  def cached_rules
@@ -1,5 +1,14 @@
1
1
  module CanTango
2
2
  module Api
3
3
  autoload_modules :User, :UserAccount, :Options, :Common, :Attributes
4
+
5
+ def self.apis
6
+ [:Can, :Scope, :Ability, :Session]
7
+ end
8
+
9
+ apis.each do |api|
10
+ self.extend "CanTango::Api::User::#{api}".constantize
11
+ self.extend "CanTango::Api::UserAccount::#{api}".constantize
12
+ end
4
13
  end
5
14
  end
@@ -1,9 +1,9 @@
1
1
  module CanTango
2
2
  class Configuration
3
3
  class PermitRegistry
4
- def get permit
5
- raise ArgumentError, "Not an available permit" if !CanTango.config.permits.available_types.include? permit
6
- inst_var_name = "@#{permit}"
4
+ def get_permit label
5
+ raise ArgumentError, "Not an available permit" if !CanTango.config.permits.available_types.include? label
6
+ inst_var_name = "@#{label}"
7
7
  instance_variable_set(inst_var_name, HashRegistry.new) if !instance_variable_get(inst_var_name)
8
8
  instance_variable_get(inst_var_name)
9
9
  end
@@ -17,7 +17,7 @@ module CanTango
17
17
  end
18
18
 
19
19
  def all
20
- (CanTango.config.permits.available_types - [:special]).map{|p| send(p) if respond_to?(p)}
20
+ (CanTango.config.permits.available_types - [:special]).map{|label| get_permit(label) }
21
21
  end
22
22
 
23
23
  def show_all
@@ -78,11 +78,11 @@ module CanTango
78
78
  end
79
79
 
80
80
  def register_permit_class(permit_name, permit_clazz, permit_type, account_name)
81
- registry = account_name ? self.send(account_name.to_sym) : self
81
+ registry = account_name ? get_permit(account_name.to_sym) : self
82
82
  debug "Registering #{permit_type} permit: #{permit_name} of class #{permit_clazz}"
83
83
 
84
84
  registry.get(permit_type)[permit_name] = permit_clazz
85
- debug registry.get(permit_type).inspect
85
+ debug registry.get_permit(permit_type).inspect
86
86
  end
87
87
 
88
88
  def allowed candidate, actions, subjects, *extra_args
@@ -12,13 +12,14 @@ module CanTango
12
12
  def include_apis(clazz)
13
13
  return if !respond_to?(:apis) || !apis
14
14
  apis.each do |api|
15
+ # puts "include API: #{api}"
15
16
  clazz.send :include, "CanTango::Api::User::#{api}".constantize
16
17
  clazz.send :include, "CanTango::Api::UserAccount::#{api}".constantize
17
18
  end
18
19
  end
19
20
 
20
21
  def apis
21
- [:Can, :Scope]
22
+ [:Can, :Scope, :Ability, :Session]
22
23
  end
23
24
  end
24
25
  extend ClassMethods
@@ -0,0 +1,14 @@
1
+ require 'rspec'
2
+ require 'cantango'
3
+ require 'fixtures/models'
4
+ require 'cantango/rspec'
5
+
6
+ def config_folder
7
+ File.dirname(__FILE__)+ "/../fixtures/config/"
8
+ end
9
+
10
+ describe CanTango::Api do
11
+ subject { CanTango::Api }
12
+
13
+ specify { subject.methods.should include(:current_user_ability) }
14
+ end
@@ -5,9 +5,9 @@ describe CanTango::Configuration::PermitRegistry do
5
5
  @permit_registry = CanTango::Configuration::PermitRegistry.new
6
6
  end
7
7
 
8
- it "should respond to permits groups methods" do
9
- [:user, :account, :role, :role_group].each do |permit_group|
10
- @permit_registry.should respond_to(permit_group)
8
+ it '#get_permit should respond to default permit types' do
9
+ [:user, :account, :role, :role_group].each do |type|
10
+ @permit_registry.get_permit(type).should_not be_nil
11
11
  end
12
12
  end
13
13
 
@@ -38,24 +38,10 @@ describe CanTango::Configuration::Permits do
38
38
  @permit_registry = CanTango::Configuration::Permits.instance
39
39
  end
40
40
 
41
- it "should respond to permits groups methods" do
42
- [:user, :account, :role, :role_group].each do |permit_group|
43
- @permit_registry.should respond_to(permit_group)
44
- end
45
- end
46
-
47
41
  it "should treat missing methods as account keys" do
48
42
  @permit_registry.any_method.should be_kind_of(CanTango::Configuration::PermitRegistry)
49
43
  end
50
44
 
51
- context "account keys" do
52
- it "should behave like PermitRegistry" do
53
- [:user, :account, :role, :role_group].each do |permit_group|
54
- @permit_registry.admin_account.should respond_to(permit_group)
55
- end
56
- end
57
- end
58
-
59
45
  describe 'debugging permits' do
60
46
  let(:context) { Context.new }
61
47
  let (:user) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cantango
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4.3
4
+ version: 0.9.4.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-11-05 00:00:00.000000000Z
13
+ date: 2011-11-21 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &70093336203760 !ruby/object:Gem::Requirement
17
+ requirement: &70220124631000 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.0.1
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70093336203760
25
+ version_requirements: *70220124631000
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: cancan
28
- requirement: &70093336203220 !ruby/object:Gem::Requirement
28
+ requirement: &70220124630520 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '1.4'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70093336203220
36
+ version_requirements: *70220124630520
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: sugar-high
39
- requirement: &70093336202700 !ruby/object:Gem::Requirement
39
+ requirement: &70220124630020 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 0.6.0
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70093336202700
47
+ version_requirements: *70220124630020
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: sweetloader
50
- requirement: &70093336202180 !ruby/object:Gem::Requirement
50
+ requirement: &70220124629400 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 0.1.0
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70093336202180
58
+ version_requirements: *70220124629400
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: hashie
61
- requirement: &70093336201600 !ruby/object:Gem::Requirement
61
+ requirement: &70220124628760 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0.4'
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *70093336201600
69
+ version_requirements: *70220124628760
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rspec-rails
72
- requirement: &70093336201060 !ruby/object:Gem::Requirement
72
+ requirement: &70220124628100 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 2.6.1
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70093336201060
80
+ version_requirements: *70220124628100
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: forgery
83
- requirement: &70093336200540 !ruby/object:Gem::Requirement
83
+ requirement: &70220124627420 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0.3'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70093336200540
91
+ version_requirements: *70220124627420
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: factory_girl
94
- requirement: &70093336200000 !ruby/object:Gem::Requirement
94
+ requirement: &70220124626940 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *70093336200000
102
+ version_requirements: *70220124626940
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: sqlite3
105
- requirement: &70093336199500 !ruby/object:Gem::Requirement
105
+ requirement: &70220124620920 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: '0'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *70093336199500
113
+ version_requirements: *70220124620920
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: sourcify
116
- requirement: &70093336198960 !ruby/object:Gem::Requirement
116
+ requirement: &70220124620260 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: '0'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *70093336198960
124
+ version_requirements: *70220124620260
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: dkastner-moneta
127
- requirement: &70093336198420 !ruby/object:Gem::Requirement
127
+ requirement: &70220124619620 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ! '>='
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: '1.0'
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *70093336198420
135
+ version_requirements: *70220124619620
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: rspec
138
- requirement: &70093336197860 !ruby/object:Gem::Requirement
138
+ requirement: &70220124618860 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ! '>='
@@ -143,10 +143,10 @@ dependencies:
143
143
  version: 2.4.0
144
144
  type: :development
145
145
  prerelease: false
146
- version_requirements: *70093336197860
146
+ version_requirements: *70220124618860
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: jeweler
149
- requirement: &70093336197320 !ruby/object:Gem::Requirement
149
+ requirement: &70220124618380 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
152
152
  - - ! '>='
@@ -154,10 +154,10 @@ dependencies:
154
154
  version: 1.6.4
155
155
  type: :development
156
156
  prerelease: false
157
- version_requirements: *70093336197320
157
+ version_requirements: *70220124618380
158
158
  - !ruby/object:Gem::Dependency
159
159
  name: bundler
160
- requirement: &70093336196800 !ruby/object:Gem::Requirement
160
+ requirement: &70220124617720 !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
163
163
  - - ! '>='
@@ -165,10 +165,10 @@ dependencies:
165
165
  version: 1.0.1
166
166
  type: :development
167
167
  prerelease: false
168
- version_requirements: *70093336196800
168
+ version_requirements: *70220124617720
169
169
  - !ruby/object:Gem::Dependency
170
170
  name: rdoc
171
- requirement: &70093336196280 !ruby/object:Gem::Requirement
171
+ requirement: &70220124617020 !ruby/object:Gem::Requirement
172
172
  none: false
173
173
  requirements:
174
174
  - - ! '>='
@@ -176,7 +176,7 @@ dependencies:
176
176
  version: '0'
177
177
  type: :development
178
178
  prerelease: false
179
- version_requirements: *70093336196280
179
+ version_requirements: *70220124617020
180
180
  description: ! 'Define your permission rules as role- or role group specific permits.
181
181
 
182
182
  Integrates well with multiple Devise user acounts.
@@ -503,6 +503,7 @@ files:
503
503
  - spec/cantango/api/user_account/scope_api_spec.rb
504
504
  - spec/cantango/api/user_account_api_spec.rb
505
505
  - spec/cantango/api/user_api_spec.rb
506
+ - spec/cantango/api_spec.rb
506
507
  - spec/cantango/cached_ability_spec.rb
507
508
  - spec/cantango/configuration/ability_spec.rb
508
509
  - spec/cantango/configuration/adapter_spec.rb
@@ -872,7 +873,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
872
873
  version: '0'
873
874
  segments:
874
875
  - 0
875
- hash: -442753695255517293
876
+ hash: -477019430598223523
876
877
  required_rubygems_version: !ruby/object:Gem::Requirement
877
878
  none: false
878
879
  requirements: