access-granted 1.2.0 → 1.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 99c759ed2b314ec49877c1ba6b0673650b9c3fba
4
- data.tar.gz: b77fa0ed9b87a7fd2bb3aa853a767f6e43cfe014
2
+ SHA256:
3
+ metadata.gz: 0ce9cfd4d0c980f5f3ba545fa4f2691897b80698fd6fe665c6b29ff226131774
4
+ data.tar.gz: 82802d1c59a69c201f5f9bfd73de5f17e82e47d8532ca22682a4cef140bada80
5
5
  SHA512:
6
- metadata.gz: 270c16d0e319ac997679178287cbfb323b69c210b6f57ce8dbb1b34b42d566ec1c415936df32004d2a0f65f8622a777cb02c58b8c4514d14563412dd153e35c5
7
- data.tar.gz: 112f93450a81eac894aeb55fb007fc6b1dabec4626e5b561c62a9ceb52e31c29254b0c2a3aae693bb20786e74d77d4376badfaa497e33e0b29a1b3103b1c67d6
6
+ metadata.gz: 7e050411bc42573ce3da74a78672974f4cf589e97c5c320a2774093a4c659bd95302f49796fa1f7ec785a36b93823684c4942b828de675fa24d696bc14a1fb89
7
+ data.tar.gz: '0119c97744988a5c1aea30e5e1e14606cbb53a78c448e2b57d94cc2d7ebcdc0b0ab5220ff7a2672e6c1d56a8ce710f58a20625e288e6d9a4bef069ca1acff56b'
@@ -1,9 +1,11 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - 1.9.3
5
4
  - 2.0
6
5
  - 2.1
7
6
  - 2.2
7
+ - 2.3
8
+ - 2.4
9
+ - 2.5
8
10
  - jruby-1
9
11
  - jruby
@@ -1,9 +1,15 @@
1
+ # 1.3.0
2
+
3
+ - Drop support for Ruby 1.9.3, it might still work but we are no longer testing against it.
4
+ - Start testing against Rubies 2.3-2.5 in CI
5
+ - Move Rails integration into Railties, this fixes some load order issues ([PR #45](https://github.com/chaps-io/access-granted/pull/45)), thanks [jraqula](https://github.com/jraqula)!
6
+
1
7
  # 1.2.0
2
8
 
3
9
  - Cache whole blocks of identical permissions when one of them is checked.
4
10
  For example, assuming we have a given permissions set:
5
11
 
6
- ```
12
+ ```ruby
7
13
  can [:update, :destroy, :archive], Post do |post, user|
8
14
  post.user_id == user.id
9
15
  end
@@ -11,7 +17,7 @@
11
17
 
12
18
  When resolving one of them like this:
13
19
 
14
- ```
20
+ ```ruby
15
21
  can? :update, @post
16
22
  ```
17
23
 
data/README.md CHANGED
@@ -31,26 +31,26 @@ AccessGranted is meant as a replacement for CanCan to solve major problems:
31
31
 
32
32
  1. Performance
33
33
 
34
- On average AccessGranted is **20 times faster** in resolving identical permissions and takes less memory.
35
- See [benchmarks](https://github.com/chaps-io/access-granted/blob/master/benchmarks).
34
+ On average AccessGranted is **20 times faster** in resolving identical permissions and takes less memory.
35
+ See [benchmarks](https://github.com/chaps-io/access-granted/blob/master/benchmarks).
36
36
 
37
37
  2. Roles
38
38
 
39
- Adds support for roles, so no more `if`s and `else`s in your Policy file. This makes it extremely easy to maintain and read the code.
39
+ Adds support for roles, so no more `if`s and `else`s in your Policy file. This makes it extremely easy to maintain and read the code.
40
40
 
41
41
  3. Whitelists
42
42
 
43
- This means that you define what the user can do, which results in clean, readable policies regardless of application complexity.
44
- You don't have to worry about juggling `can`s and `cannot`s in a very convoluted way!
43
+ This means that you define what the user can do, which results in clean, readable policies regardless of application complexity.
44
+ You don't have to worry about juggling `can`s and `cannot`s in a very convoluted way!
45
45
 
46
- _Note_: `cannot` is still available, but has a very specifc use. See [Usage](#usage) below.
46
+ _Note_: `cannot` is still available, but has a very specifc use. See [Usage](#usage) below.
47
47
 
48
48
  4. Framework agnostic
49
49
 
50
- Permissions can work on basically any object and AccessGranted is framework-agnostic,
51
- but it has Rails support out of the box. :)
52
- It does not depend on any libraries, pure and clean Ruby code. Guaranteed to always work,
53
- even when software around changes.
50
+ Permissions can work on basically any object and AccessGranted is framework-agnostic,
51
+ but it has Rails support out of the box. :)
52
+ It does not depend on any libraries, pure and clean Ruby code. Guaranteed to always work,
53
+ even when software around changes.
54
54
 
55
55
  ## Usage
56
56
 
@@ -280,7 +280,7 @@ or with `cannot?`:
280
280
 
281
281
  ```ruby
282
282
  policy.cannot?(:create, Post) #=> false
283
- policy.cannot?(:update, @ost) #=> true
283
+ policy.cannot?(:update, @post) #=> true
284
284
  ```
285
285
 
286
286
  ## Common examples
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "access-granted"
7
- spec.version = "1.2.0"
7
+ spec.version = "1.3.0"
8
8
  spec.authors = ["Piotrek Okoński"]
9
9
  spec.email = ["piotrek@okonski.org"]
10
10
  spec.description = %q{Role based authorization gem}
@@ -1,24 +1,24 @@
1
1
  # Benchmark results
2
2
 
3
- Benchmarks ran on Ubuntu 15.04 64bit, i5 2500k @ 4.4Ghz, 16 GB RAM with Ruby 2.2.
3
+ Benchmarks ran on Ubuntu 17.04 64bit, i7 6700k @ 4.0Ghz, 32 GB RAM with Ruby 2.3.
4
4
 
5
5
  ## permissions.rb
6
6
 
7
7
  This benchmark runs `can?` method for the 3 user roles for 20 seconds each, for both CanCan and AccessGranted.
8
8
 
9
9
  ```
10
+ Warming up --------------------------------------
11
+ ag-admin 158.815k i/100ms
12
+ ag-moderator 161.055k i/100ms
13
+ ag-user 161.670k i/100ms
14
+ cancan-admin 14.865k i/100ms
15
+ cancan-moderator 13.181k i/100ms
16
+ cancan-user 18.907k i/100ms
10
17
  Calculating -------------------------------------
11
- ag-admin 21.361k i/100ms
12
- cancan-admin 13.631k i/100ms
13
- ag-moderator 22.328k i/100ms
14
- cancan-moderator 11.679k i/100ms
15
- ag-user 25.860k i/100ms
16
- cancan-user 16.308k i/100ms
17
- -------------------------------------------------
18
- ag-admin 283.174k (± 1.1%) i/s - 5.682M
19
- cancan-admin 160.450k (± 1.0%) i/s - 3.217M
20
- ag-moderator 301.290k (± 1.1%) i/s - 6.029M
21
- cancan-moderator 134.591k (± 1.3%) i/s - 2.698M
22
- ag-user 353.259k (± 0.9%) i/s - 7.086M
23
- cancan-user 198.579k (± 1.6%) i/s - 3.979M
18
+ ag-admin 2.141M (± 3.9%) i/s - 10.799M in 5.052573s
19
+ ag-moderator 2.180M (± 2.1%) i/s - 10.952M in 5.025727s
20
+ ag-user 2.206M (± 0.4%) i/s - 11.155M in 5.056550s
21
+ cancan-admin 158.288k (± 2.4%) i/s - 802.710k in 5.074299s
22
+ cancan-moderator 142.573k (± 2.1%) i/s - 724.955k in 5.087277s
23
+ cancan-user 204.783k (± 2.2%) i/s - 1.040M in 5.080488s
24
24
  ```
@@ -3,19 +3,9 @@ require "access-granted/policy"
3
3
  require "access-granted/permission"
4
4
  require "access-granted/role"
5
5
  require "access-granted/rails/controller_methods"
6
+ require "access-granted/railtie" if defined?(Rails)
6
7
 
7
8
  module AccessGranted
8
9
 
9
10
  end
10
11
 
11
- if defined? ActionController::Base
12
- ActionController::Base.class_eval do
13
- include AccessGranted::Rails::ControllerMethods
14
- end
15
- end
16
-
17
- if defined? ActionController::API
18
- ActionController::API.class_eval do
19
- include AccessGranted::Rails::ControllerMethods
20
- end
21
- end
@@ -0,0 +1,19 @@
1
+ require 'rails/railtie'
2
+
3
+ module AccessGranted
4
+ class Railtie < ::Rails::Railtie
5
+ initializer :access_granted do
6
+ if defined? ActionController::Base
7
+ ActionController::Base.class_eval do
8
+ include AccessGranted::Rails::ControllerMethods
9
+ end
10
+ end
11
+
12
+ if defined? ActionController::API
13
+ ActionController::API.class_eval do
14
+ include AccessGranted::Rails::ControllerMethods
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -7,13 +7,13 @@ describe AccessGranted::Permission do
7
7
 
8
8
  it "matches proc conditions when true" do
9
9
  sub = double("Element", published?: true)
10
- perm = subject.new(true, :read, sub, nil, {}, proc {true})
10
+ perm = subject.new(true, :read, sub, nil, {}, [], proc {true})
11
11
  expect(perm.matches_conditions?(sub)).to eq(true)
12
12
  end
13
13
 
14
14
  it "does not match proc conditions false" do
15
15
  sub = double("Element", published?: true)
16
- perm = subject.new(true, :read, sub, nil, {}, proc {false})
16
+ perm = subject.new(true, :read, sub, nil, {}, [], proc {false})
17
17
  expect(perm.matches_conditions?(sub)).to eq(false)
18
18
  end
19
19
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: access-granted
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotrek Okoński
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-31 00:00:00.000000000 Z
11
+ date: 2018-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,6 +62,7 @@ files:
62
62
  - lib/access-granted/permission.rb
63
63
  - lib/access-granted/policy.rb
64
64
  - lib/access-granted/rails/controller_methods.rb
65
+ - lib/access-granted/railtie.rb
65
66
  - lib/access-granted/role.rb
66
67
  - lib/generators/access_granted/policy_generator.rb
67
68
  - lib/generators/templates/access_policy.rb
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  version: '0'
91
92
  requirements: []
92
93
  rubyforge_project:
93
- rubygems_version: 2.5.2
94
+ rubygems_version: 2.7.6
94
95
  signing_key:
95
96
  specification_version: 4
96
97
  summary: Elegant whitelist and role based authorization with ability to prioritize