cancannible 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWE0OWZkMjhlMWQ3ODMzNTVmZWNiMTk2ZWM5YmU2YjMyY2I1NTAwMA==
4
+ ZjFkNmJkNGYzODQ2NDRkZDJlODM0M2UyYjY2OTNlODJjMWIzNjU1Yw==
5
5
  data.tar.gz: !binary |-
6
- YjQ0NDZhNzQ5MzdhMDJiMDQ4NzRjMjI1MDE5ZGY1N2ViZjU2NThlMA==
6
+ YzhmMDIxNGY3Y2NkOThiMDEzYzI2ODU5NTA1ZDMyMDA3NWQ1YzdjYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Zjc2OGYzMGI1ODA5ZmY4ZmQ3ZGRhNTU5MDM2MmRiOWJmNDNmNzI4MzZjYTY0
10
- ZDNiNDM3ODVmZTExYzM5NDQ1ZmQyNDZmZjc0NDFiYWIxZTM2YjcwMTdiMGU0
11
- YTliZGI0YjFhNDdjY2RmZWNhZjNhY2YyNDU5YTQ3MDQ3NDRhNjY=
9
+ MTc3ZGNlOTU1NzliNGFlNjBjOTk0ZGVmZDMyNzg4ODBlYTkxNGM4Njg3Mjdi
10
+ NDlkYjc0ZDg3NDRkZDIzMjkzMjRhOGQxZTQ4N2JiZDI1MjAxMWE4NzQ3ZmY5
11
+ NGFjZTYxYWM4Yzg0NGNlMWM3NGMzZTgxNjIxZWE5OThjNTAyMGE=
12
12
  data.tar.gz: !binary |-
13
- MjFhMzBmNzQ5YTcyMzBmOTViMTYwMjEwNDI2YjllNjUxZjEzYjkxNmZjOTVi
14
- YmVkOWZjMWUyODBiMDQ3MmY4YWExMDJiNmUzZTkzZTBlY2MwZWFjMzFmOWM0
15
- MjNiMTBmMGFjNGI3OTllNTkxMjM3NTBmZDViOWYwNmVlZGMwZWE=
13
+ YzQzYzU4ZDEzZmRjZWZmNTZkYmVkNzExNzQxN2UyODNmNjc4ZWUzNTE2ZTZm
14
+ MzhmNDE2NjQwN2YyMzcwMDg5OTg5MGY1OGNiZjQyNDRmM2EyNjJmOGYxZGUw
15
+ ZjY1MjI2NmNhNTBkM2UyNjg4MTA1MGI3ZWIwNWFmYWE5MTY2NGM=
@@ -2,3 +2,13 @@
2
2
  language: ruby
3
3
  rvm:
4
4
  - 1.9.3
5
+ - 2.1.5
6
+ gemfile:
7
+ - gemfiles/rails_3.gemfile
8
+ - gemfiles/rails_4.gemfile
9
+ matrix:
10
+ exclude:
11
+ - rvm: 1.9.3
12
+ gemfile: gemfiles/rails_4.gemfile
13
+ - rvm: 2.1.5
14
+ gemfile: gemfiles/rails_3.gemfile
@@ -0,0 +1,11 @@
1
+ appraise "rails-3" do
2
+ gem "activesupport", '~> 3.2'
3
+ gem "activemodel", '~> 3.2'
4
+ gem "activerecord", '~> 3.2'
5
+ end
6
+
7
+ appraise "rails-4" do
8
+ gem "activesupport", '> 4'
9
+ gem "activemodel", '> 4'
10
+ gem "activerecord", '> 4'
11
+ end
data/Gemfile CHANGED
@@ -1,8 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # currently testing on the 3.2 branch of rails
4
- # gem "activemodel", '~> 3.2'
5
- # gem "activerecord", '~> 3.2'
3
+ gem "appraisal"
6
4
 
7
5
  # Specify your gem's dependencies in cancannible.gemspec
8
6
  gemspec
data/README.md CHANGED
@@ -7,16 +7,17 @@ Cancannible is a gem that extends CanCan with a range of capabilities:
7
7
  * permissions inheritance (so that, for example, a User can inherit permissions from Roles and/or Groups)
8
8
  * caching of abilities (so that they don't need to be recalculated on each web request)
9
9
  * general-purpose access refinements (so that, for example, CanCan will automatically enforce multi-tenant or other security restrictions)
10
+ * battle-tested with Rails 3.2
11
+ * tested with Rails 4 (but limited experience in the field?)
10
12
 
11
13
  ## Limitations
12
- Cancannible's origin was in a web application that's been in production for over 3 years.
14
+ Cancannible's origin was in a web application that's been in production for over 4 years.
13
15
  This gem is an initial refactoring as a separate component. It continues to be used in production, but
14
16
  there are some limitations and constraints that will ideally be removed or changed over time:
15
17
 
16
18
  * It only supports ActiveRecord for permissions storage (specifically, it has been tested with PostgreSQL and SQLite)
17
19
  * It currently assumes permissions are stored in a Permission model with a specific structure
18
20
  * It works with the [CanCan](https://github.com/ryanb/cancan) gem. It has not yet been tested with the new [CanCanCan](https://github.com/CanCanCommunity/cancancan) gem.
19
- * It assumes and is only tested with Rails 3.2. Not yet with Rails 4.
20
21
  * It assumes your CanCan rules are setup with the default `Ability` class
21
22
 
22
23
 
@@ -120,6 +121,23 @@ For example, this is a simple scheme using Redis:
120
121
  end
121
122
 
122
123
 
124
+ ## Testing the gem
125
+
126
+ The RSpec test suite runs as the default rake task:
127
+
128
+ rake
129
+ # same as:
130
+ rake spec
131
+
132
+ For convenience, guard is included in the development gem environment, so you can start automatic testing-on-change:
133
+
134
+ bundle exec guard
135
+
136
+ [Appraisal](https://github.com/thoughtbot/appraisal) is also included to run tests across Rails 3 and 4 environments:
137
+
138
+ appraisal rake spec
139
+
140
+
123
141
  ## Contributing
124
142
 
125
143
  1. Fork it ( https://github.com/evendis/cancannible/fork )
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "activesupport", "~> 3.2"
22
- spec.add_runtime_dependency "activemodel", "~> 3.2"
21
+ spec.add_runtime_dependency "activesupport", ">= 3.2.1"
22
+ spec.add_runtime_dependency "activemodel", ">= 3.2.1"
23
23
  spec.add_runtime_dependency "cancan", "~> 1.6"
24
24
 
25
- spec.add_development_dependency "activerecord", "~> 3.2"
25
+ spec.add_development_dependency "activerecord", ">= 3.2.1"
26
26
  spec.add_development_dependency "sqlite3", "~> 1.3"
27
27
  spec.add_development_dependency "bundler", "~> 1.6"
28
28
  spec.add_development_dependency "rake", "~> 10.0"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "activesupport", "~> 3.2"
7
+ gem "activemodel", "~> 3.2"
8
+ gem "activerecord", "~> 3.2"
9
+
10
+ gemspec :path => "../"
@@ -0,0 +1,98 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ cancannible (1.0.0)
5
+ activemodel (>= 3.2.1)
6
+ activesupport (>= 3.2.1)
7
+ cancan (~> 1.6)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (3.2.19)
13
+ activesupport (= 3.2.19)
14
+ builder (~> 3.0.0)
15
+ activerecord (3.2.19)
16
+ activemodel (= 3.2.19)
17
+ activesupport (= 3.2.19)
18
+ arel (~> 3.0.2)
19
+ tzinfo (~> 0.3.29)
20
+ activesupport (3.2.19)
21
+ i18n (~> 0.6, >= 0.6.4)
22
+ multi_json (~> 1.0)
23
+ appraisal (1.0.2)
24
+ bundler
25
+ rake
26
+ thor (>= 0.14.0)
27
+ arel (3.0.3)
28
+ builder (3.0.4)
29
+ cancan (1.6.10)
30
+ celluloid (0.16.0)
31
+ timers (~> 4.0.0)
32
+ coderay (1.1.0)
33
+ diff-lcs (1.2.5)
34
+ ffi (1.9.6)
35
+ formatador (0.2.5)
36
+ guard (2.10.5)
37
+ formatador (>= 0.2.4)
38
+ listen (~> 2.7)
39
+ lumberjack (~> 1.0)
40
+ nenv (~> 0.1)
41
+ pry (>= 0.9.12)
42
+ thor (>= 0.18.1)
43
+ guard-compat (1.2.0)
44
+ guard-rspec (4.5.0)
45
+ guard (~> 2.1)
46
+ guard-compat (~> 1.1)
47
+ rspec (>= 2.99.0, < 4.0)
48
+ hitimes (1.2.2)
49
+ i18n (0.7.0)
50
+ listen (2.8.4)
51
+ celluloid (>= 0.15.2)
52
+ rb-fsevent (>= 0.9.3)
53
+ rb-inotify (>= 0.9)
54
+ lumberjack (1.0.9)
55
+ method_source (0.8.2)
56
+ multi_json (1.10.1)
57
+ nenv (0.1.1)
58
+ pry (0.10.1)
59
+ coderay (~> 1.1.0)
60
+ method_source (~> 0.8.1)
61
+ slop (~> 3.4)
62
+ rake (10.4.2)
63
+ rb-fsevent (0.9.4)
64
+ rb-inotify (0.9.5)
65
+ ffi (>= 0.5.0)
66
+ rspec (3.1.0)
67
+ rspec-core (~> 3.1.0)
68
+ rspec-expectations (~> 3.1.0)
69
+ rspec-mocks (~> 3.1.0)
70
+ rspec-core (3.1.7)
71
+ rspec-support (~> 3.1.0)
72
+ rspec-expectations (3.1.2)
73
+ diff-lcs (>= 1.2.0, < 2.0)
74
+ rspec-support (~> 3.1.0)
75
+ rspec-mocks (3.1.3)
76
+ rspec-support (~> 3.1.0)
77
+ rspec-support (3.1.2)
78
+ slop (3.6.0)
79
+ sqlite3 (1.3.10)
80
+ thor (0.19.1)
81
+ timers (4.0.1)
82
+ hitimes
83
+ tzinfo (0.3.40)
84
+
85
+ PLATFORMS
86
+ ruby
87
+
88
+ DEPENDENCIES
89
+ activemodel (~> 3.2)
90
+ activerecord (~> 3.2)
91
+ activesupport (~> 3.2)
92
+ appraisal
93
+ bundler (~> 1.6)
94
+ cancannible!
95
+ guard-rspec (~> 4.0)
96
+ rake (~> 10.0)
97
+ rspec (~> 3.0)
98
+ sqlite3 (~> 1.3)
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "activesupport", "> 4"
7
+ gem "activemodel", "> 4"
8
+ gem "activerecord", "> 4"
9
+
10
+ gemspec :path => "../"
@@ -0,0 +1,103 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ cancannible (1.0.0)
5
+ activemodel (>= 3.2.1)
6
+ activesupport (>= 3.2.1)
7
+ cancan (~> 1.6)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (4.2.0)
13
+ activesupport (= 4.2.0)
14
+ builder (~> 3.1)
15
+ activerecord (4.2.0)
16
+ activemodel (= 4.2.0)
17
+ activesupport (= 4.2.0)
18
+ arel (~> 6.0)
19
+ activesupport (4.2.0)
20
+ i18n (~> 0.7)
21
+ json (~> 1.7, >= 1.7.7)
22
+ minitest (~> 5.1)
23
+ thread_safe (~> 0.3, >= 0.3.4)
24
+ tzinfo (~> 1.1)
25
+ appraisal (1.0.2)
26
+ bundler
27
+ rake
28
+ thor (>= 0.14.0)
29
+ arel (6.0.0)
30
+ builder (3.2.2)
31
+ cancan (1.6.10)
32
+ celluloid (0.16.0)
33
+ timers (~> 4.0.0)
34
+ coderay (1.1.0)
35
+ diff-lcs (1.2.5)
36
+ ffi (1.9.6)
37
+ formatador (0.2.5)
38
+ guard (2.10.5)
39
+ formatador (>= 0.2.4)
40
+ listen (~> 2.7)
41
+ lumberjack (~> 1.0)
42
+ nenv (~> 0.1)
43
+ pry (>= 0.9.12)
44
+ thor (>= 0.18.1)
45
+ guard-compat (1.2.0)
46
+ guard-rspec (4.5.0)
47
+ guard (~> 2.1)
48
+ guard-compat (~> 1.1)
49
+ rspec (>= 2.99.0, < 4.0)
50
+ hitimes (1.2.2)
51
+ i18n (0.7.0)
52
+ json (1.8.1)
53
+ listen (2.8.4)
54
+ celluloid (>= 0.15.2)
55
+ rb-fsevent (>= 0.9.3)
56
+ rb-inotify (>= 0.9)
57
+ lumberjack (1.0.9)
58
+ method_source (0.8.2)
59
+ minitest (5.5.0)
60
+ nenv (0.1.1)
61
+ pry (0.10.1)
62
+ coderay (~> 1.1.0)
63
+ method_source (~> 0.8.1)
64
+ slop (~> 3.4)
65
+ rake (10.4.2)
66
+ rb-fsevent (0.9.4)
67
+ rb-inotify (0.9.5)
68
+ ffi (>= 0.5.0)
69
+ rspec (3.1.0)
70
+ rspec-core (~> 3.1.0)
71
+ rspec-expectations (~> 3.1.0)
72
+ rspec-mocks (~> 3.1.0)
73
+ rspec-core (3.1.7)
74
+ rspec-support (~> 3.1.0)
75
+ rspec-expectations (3.1.2)
76
+ diff-lcs (>= 1.2.0, < 2.0)
77
+ rspec-support (~> 3.1.0)
78
+ rspec-mocks (3.1.3)
79
+ rspec-support (~> 3.1.0)
80
+ rspec-support (3.1.2)
81
+ slop (3.6.0)
82
+ sqlite3 (1.3.10)
83
+ thor (0.19.1)
84
+ thread_safe (0.3.4)
85
+ timers (4.0.1)
86
+ hitimes
87
+ tzinfo (1.2.2)
88
+ thread_safe (~> 0.1)
89
+
90
+ PLATFORMS
91
+ ruby
92
+
93
+ DEPENDENCIES
94
+ activemodel (> 4)
95
+ activerecord (> 4)
96
+ activesupport (> 4)
97
+ appraisal
98
+ bundler (~> 1.6)
99
+ cancannible!
100
+ guard-rspec (~> 4.0)
101
+ rake (~> 10.0)
102
+ rspec (~> 3.0)
103
+ sqlite3 (~> 1.3)
@@ -23,21 +23,15 @@ module Cancannible::Grantee
23
23
  resource_id = resource.try(:id)
24
24
  end
25
25
 
26
- permission = find_by_asserted_and_ability_and_resource_id_and_resource_type(
27
- asserted, ability, resource_id, resource_type)
28
- unless permission
29
- permission = find_or_initialize_by_asserted_and_ability_and_resource_id_and_resource_type(
30
- !asserted, ability, resource_id, resource_type)
31
- permission.asserted = asserted
32
- permission.save!
33
- end
26
+ # This looks ugly, but it avoid version-specific issues with find_by*/find_or_initialize_by* methods
27
+ permission = where(asserted: asserted, ability: ability, resource_id: resource_id, resource_type: resource_type).first
28
+ permission ||= where(asserted: !asserted, ability: ability, resource_id: resource_id, resource_type: resource_type).first
29
+ permission ||= new(asserted: asserted, ability: ability, resource_id: resource_id, resource_type: resource_type)
30
+ permission.asserted = asserted
31
+ permission.save!
32
+
33
+ proxy_association.owner.instance_variable_set :@abilities, nil # invalidate the owner's ability collection
34
34
 
35
- # if Rails.version =~ /3\.0/ # the rails 3.0 way
36
- # proxy_owner.instance_variable_set :@permissions, nil # invalidate the owner's permissions collection
37
- # proxy_owner.instance_variable_set :@abilities, nil # invalidate the owner's ability collection
38
- # else
39
- proxy_association.owner.instance_variable_set :@abilities, nil # invalidate the owner's ability collection
40
- # end
41
35
  permission
42
36
  end
43
37
  end
@@ -1,3 +1,3 @@
1
1
  module Cancannible
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -24,6 +24,7 @@ Cancannible.setup do |config|
24
24
 
25
25
 
26
26
  # ACCESS REFINMENTS
27
+ # =================
27
28
  # Cancannible allows general-purpose access refinements to be declared here. This will be enforced
28
29
  # in addition to any rules defined in you Ability.rb file.
29
30
 
@@ -6,7 +6,7 @@ require 'sqlite3'
6
6
 
7
7
  # Requires supporting files with custom matchers and macros, etc,
8
8
  # in ./support/ and its subdirectories.
9
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each {|f| require f}
10
10
 
11
11
  RSpec.configure do |config|
12
12
  config.before do
@@ -29,7 +29,7 @@ class RolesUsers < ActiveRecord::Base
29
29
  end
30
30
 
31
31
  class Role < ActiveRecord::Base
32
- has_many :roles_users, :class_name => 'RolesUsers'
32
+ has_many :roles_users, class_name: 'RolesUsers'
33
33
  has_many :users, through: :roles_users
34
34
 
35
35
  include Cancannible::Grantee
@@ -43,9 +43,13 @@ describe Cancannible::Grantee do
43
43
  context "when permission is not asserted" do
44
44
  it { should be_truthy }
45
45
  end
46
- context "when permission is not asserted but can is" do
46
+ context "when :can already asserted" do
47
47
  before { grantee.can(:read, resource) }
48
48
  it { should be_falsey }
49
+ context "and then reset as :cannot" do
50
+ before { grantee.cannot(:read, resource) }
51
+ it { should be_truthy }
52
+ end
49
53
  end
50
54
  context "when permission is asserted" do
51
55
  before { grantee.cannot(:read, resource) }
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cancannible
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Gallagher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-31 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
19
+ version: 3.2.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
- version: '3.2'
26
+ version: 3.2.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
- version: '3.2'
33
+ version: 3.2.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
- version: '3.2'
40
+ version: 3.2.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: cancan
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: activerecord
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
- version: '3.2'
61
+ version: 3.2.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
- version: '3.2'
68
+ version: 3.2.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -147,12 +147,17 @@ files:
147
147
  - .gitignore
148
148
  - .rspec
149
149
  - .travis.yml
150
+ - Appraisals
150
151
  - Gemfile
151
152
  - Guardfile
152
153
  - LICENSE.txt
153
154
  - README.md
154
155
  - Rakefile
155
156
  - cancannible.gemspec
157
+ - gemfiles/rails_3.gemfile
158
+ - gemfiles/rails_3.gemfile.lock
159
+ - gemfiles/rails_4.gemfile
160
+ - gemfiles/rails_4.gemfile.lock
156
161
  - lib/cancannible.rb
157
162
  - lib/cancannible/config.rb
158
163
  - lib/cancannible/grantee.rb
@@ -192,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
197
  version: '0'
193
198
  requirements: []
194
199
  rubyforge_project:
195
- rubygems_version: 2.2.2
200
+ rubygems_version: 2.4.5
196
201
  signing_key:
197
202
  specification_version: 4
198
203
  summary: Dynamic, configurable permissions for CanCan