access-granted 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed37f3966694f5aa4708f1b12c13b079f769f6b2
4
- data.tar.gz: a287e21f67658f36b532f5fe3e4c6e6ab962dbc5
3
+ metadata.gz: 246a35a6a2cb45ef63cc43536becfb22c88387a5
4
+ data.tar.gz: aae201ebfddf0b130961b0ca675863f32cc276ac
5
5
  SHA512:
6
- metadata.gz: 4b25dc3178876c6134cc10b81396588c0d99cff83e320f82196f653e2db817bca124bf539acab62e8f5b01fa02e0ebb55a1253e1654d0ea55d097a6e24a0ed6e
7
- data.tar.gz: 38e48bf94c3b918421316ea29d3c9b0c5b3072a44192da516a9245f6af713e239b7a656eb7ea3a23aa0048be6a844ec4d4b2be5153dcc1d60c77e554a28e78f7
6
+ metadata.gz: 3b8277e5bf9ad6fdd843d572c0ef707b6e4c28c7bcc4e3dd4178037320ba8bae2b58566865dfff19c4853f01e8034f4512d83321d85ecc087ca79e8d68d4d79b
7
+ data.tar.gz: b477974a51014c347694dd2f4000936faa2ad4f595bcab22e3dbd8e56ab5cc40f08ddeec1978241ccf66e6899680f4948435530fe5daee185a5185b6e8e3f0cd
data/README.md CHANGED
@@ -48,6 +48,8 @@ Roles are defined using blocks (or by passing custom classes to keep things tidy
48
48
  **Order of the roles is VERY important**, because they are being traversed in the top-to-bottom order.
49
49
  At the top you must have an admin or other important role giving the user top permissions, and as you go down you define less-privileged roles.
50
50
 
51
+ **I recommend starting your adventure by reading my [blog post about AccessGranted](http://blog.chaps.io/2015/11/13/role-based-authorization-in-rails.html), where I demonstrate its abilities on a real life example.**
52
+
51
53
  ### 1. Defining access policy
52
54
 
53
55
  Let's start with a complete example of what can be achieved:
@@ -224,7 +226,7 @@ end
224
226
  Usually you don't want to show "Create" buttons for people who can't create something.
225
227
  You can hide any part of the page from users without permissions like this:
226
228
 
227
- ```html
229
+ ```erb
228
230
  # app/views/categories/index.html.erb
229
231
 
230
232
  <% if can? :create, Category %>
@@ -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.0.2"
7
+ spec.version = "1.0.3"
8
8
  spec.authors = ["Piotrek Okoński"]
9
9
  spec.email = ["piotrek@okonski.org"]
10
10
  spec.description = %q{Role based authorization gem}
@@ -20,7 +20,7 @@ module AccessGranted
20
20
  end
21
21
 
22
22
  def matches_conditions?(subject)
23
- if @block
23
+ if @block && !subject.is_a?(Class)
24
24
  @block.call(subject, @user)
25
25
  else
26
26
  matches_hash_conditions?(subject)
@@ -14,6 +14,12 @@ describe AccessGranted::Permission do
14
14
  perm = subject.new(true, :read, sub.class, nil, {}, proc {|el| el.published? })
15
15
  expect(perm.matches_conditions?(sub)).to eq(true)
16
16
  end
17
+
18
+ it "does not match proc conditions when given a class instead of an instance" do
19
+ sub = double("Element", published?: true)
20
+ perm = subject.new(true, :read, sub.class, nil, {}, proc {|el| el.published? })
21
+ expect(perm.matches_conditions?(sub.class)).to eq(true)
22
+ end
17
23
  end
18
24
 
19
25
  describe "#matches_hash_conditions?" do
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.0.2
4
+ version: 1.0.3
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: 2015-11-20 00:00:00.000000000 Z
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler