protector-cancan 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +5 -1
- data/lib/protector/cancan/ability.rb +8 -3
- data/lib/protector/cancan/resource.rb +28 -18
- data/lib/protector/cancan/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b34cee4a1e226310caecd062c57966b2b6885b6a
|
4
|
+
data.tar.gz: 8f487911a2246b9dc4fe62ba06c123e2ab9a9722
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab8ff085f0c0a6a367c8d095b05d2b70dcebb65f8a0f270c2bed5dfd2d4c979d43acebdfac51e45fce11b0970e90b70c74a293d2b9c81f5571540f76fb206245
|
7
|
+
data.tar.gz: d474e2569e79ec413f90d9bbca6649e418d2117deb34ddf1fe36a2eedbcde666c352d5bf2ce84e9ba03005193b74bd8229b0ea03edbfa091ae6ed57edb944549
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Protector::Cancan
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/protector-cancan)
|
4
|
+
[](https://travis-ci.org/inossidabile/protector-cancan)
|
5
|
+
[](https://codeclimate.com/github/inossidabile/protector-cancan)
|
6
|
+
|
3
7
|
Integrates [Protector](https://github.com/inossidabile/protector) and [CanCan](https://github.com/ryanb/cancan).
|
4
8
|
|
5
9
|
Protector and CanCan are all about the same thing: access control. They however act on different fronts: Protector works on a model level and CanCan is all about controllers defense. With this gem you don't have to choose anymore: make them work together for the best result.
|
@@ -44,7 +48,7 @@ class Dummy < ActiveRecord::Base
|
|
44
48
|
end
|
45
49
|
```
|
46
50
|
|
47
|
-
If you call `can? :
|
51
|
+
If you call `can? :view, Dummy`, the gem will evaluate `Dummy` protection block against value passed to `import_protector` (by default it's `current_user`) and expand CanCan rules with resulting meta. Note that gem automatically converts `:read` to `:view` so you should use CanCan naming conventions when working with CanCan.
|
48
52
|
|
49
53
|
So in this particular case we will get `true` if `current_user` is set and `false` otherwise.
|
50
54
|
|
@@ -20,7 +20,13 @@ module Protector
|
|
20
20
|
def self.included(mod)
|
21
21
|
mod.class_eval do
|
22
22
|
|
23
|
-
def can_with_protector?(action,
|
23
|
+
def can_with_protector?(action, entity_set, *extra_args)
|
24
|
+
if entity_set.is_a? Hash
|
25
|
+
entity = entity_set.values.first
|
26
|
+
else
|
27
|
+
entity = entity_set
|
28
|
+
end
|
29
|
+
|
24
30
|
if entity.respond_to?(:restrict!) && @protector_subject_defined
|
25
31
|
@protector_models ||= Set.new
|
26
32
|
|
@@ -42,11 +48,10 @@ module Protector
|
|
42
48
|
end
|
43
49
|
end
|
44
50
|
|
45
|
-
can_without_protector? action,
|
51
|
+
can_without_protector? action, entity_set, *extra_args
|
46
52
|
end
|
47
53
|
|
48
54
|
alias_method_chain :can?, :protector
|
49
|
-
|
50
55
|
end
|
51
56
|
end
|
52
57
|
end
|
@@ -2,34 +2,44 @@ module Protector
|
|
2
2
|
module CanCan
|
3
3
|
module Resource extend ActiveSupport::Concern
|
4
4
|
included do
|
5
|
-
alias_method_chain :
|
5
|
+
alias_method_chain :resource_base, :protector
|
6
6
|
alias_method_chain :load_collection, :protector
|
7
|
+
alias_method_chain :load_collection?, :protector
|
7
8
|
end
|
8
9
|
|
9
|
-
def
|
10
|
-
resource =
|
10
|
+
def resource_base_with_protector
|
11
|
+
resource = resource_base_without_protector
|
11
12
|
|
12
|
-
if
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
resource = resource.restrict!(current_ability.protector_subject)
|
13
|
+
if resource_protectable? resource
|
14
|
+
resource.restrict!(current_ability.protector_subject)
|
15
|
+
else
|
16
|
+
resource
|
17
17
|
end
|
18
|
-
|
19
|
-
resource
|
20
18
|
end
|
21
19
|
|
22
|
-
def load_collection_with_protector
|
23
|
-
|
20
|
+
def load_collection_with_protector
|
21
|
+
resource = resource_base
|
24
22
|
|
25
|
-
if
|
26
|
-
|
27
|
-
|
23
|
+
if resource_protectable? resource
|
24
|
+
resource
|
25
|
+
else
|
26
|
+
load_collection_without_protector
|
27
|
+
end
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
+
def load_collection_with_protector?
|
31
|
+
if resource_protectable? resource_base
|
32
|
+
true
|
33
|
+
else
|
34
|
+
load_collection_without_protector?
|
30
35
|
end
|
31
|
-
|
32
|
-
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def resource_protectable?(resource)
|
41
|
+
resource.respond_to?(:restrict!) &&
|
42
|
+
current_ability.protector_subject?
|
33
43
|
end
|
34
44
|
end
|
35
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protector-cancan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boris Staal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: protector
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.0.
|
104
|
+
rubygems_version: 2.0.3
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Integration layer between Protector and CanCan
|