cancancan 1.11.0 → 1.12.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 +4 -4
- data/CHANGELOG.rdoc +4 -0
- data/README.md +1 -1
- data/cancancan.gemspec +0 -1
- data/lib/cancan/ability.rb +29 -0
- data/lib/cancan/version.rb +1 -1
- data/spec/cancan/ability_spec.rb +20 -0
- data/spec/spec_helper.rb +0 -1
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55bf93046d99f249ab63118d79f1188ef2383278
|
4
|
+
data.tar.gz: 052a7a962e2585ca122723f23a733d882872a660
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b4259d5de95a69c48301338605341a0f86d200ec01e56981a50d08e5367b7513042620fbeaae77d6790299dcae616feb606fa3c1718b20250bf29cd35356519
|
7
|
+
data.tar.gz: 1c58fbfde297986492dda47b7f1c03f86da96fb412fe2917bb75bbe8ea5e4e49607189d71c8f19336392d8dd7a7cc30a6b19e8c6e475cc69e38e9ecd533ac135
|
data/CHANGELOG.rdoc
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
[](https://codeclimate.com/github/CanCanCommunity/cancancan)
|
6
6
|
[](http://inch-ci.org/github/CanCanCommunity/cancancan)
|
7
7
|
|
8
|
-
[Wiki](https://github.com/CanCanCommunity/cancancan/wiki) | [RDocs](http://rdoc.info/projects/CanCanCommunity/cancancan) | [Screencast](http://railscasts.com/episodes/192-authorization-with-cancan)
|
8
|
+
[Wiki](https://github.com/CanCanCommunity/cancancan/wiki) | [RDocs](http://rdoc.info/projects/CanCanCommunity/cancancan) | [Screencast](http://railscasts.com/episodes/192-authorization-with-cancan) | [IRC: #cancancan (freenode)](http://webchat.freenode.net/?channels=cancancan)
|
9
9
|
|
10
10
|
CanCan is an authorization library for Ruby on Rails which restricts what resources a given user is allowed to access. All permissions are defined in a single location (the `Ability` class) and not duplicated across controllers, views, and database queries.
|
11
11
|
|
data/cancancan.gemspec
CHANGED
@@ -26,7 +26,6 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_development_dependency 'rake', '~> 10.1.1'
|
27
27
|
s.add_development_dependency 'rspec', '~> 3.0.0'
|
28
28
|
s.add_development_dependency 'appraisal', '>= 1.0.0'
|
29
|
-
s.add_development_dependency 'pry', '~> 0.10.0'
|
30
29
|
|
31
30
|
s.rubyforge_project = s.name
|
32
31
|
end
|
data/lib/cancan/ability.rb
CHANGED
@@ -252,6 +252,35 @@ module CanCan
|
|
252
252
|
self
|
253
253
|
end
|
254
254
|
|
255
|
+
# Return a hash of permissions for the user in the format of:
|
256
|
+
# {
|
257
|
+
# can: can_hash,
|
258
|
+
# cannot: cannot_hash
|
259
|
+
# }
|
260
|
+
#
|
261
|
+
# Where can_hash and cannot_hash are formatted thusly:
|
262
|
+
# {
|
263
|
+
# action: array_of_objects
|
264
|
+
# }
|
265
|
+
def permissions
|
266
|
+
permissions_list = {:can => {}, :cannot => {}}
|
267
|
+
|
268
|
+
rules.each do |rule|
|
269
|
+
subjects = rule.subjects
|
270
|
+
expand_actions(rule.actions).each do |action|
|
271
|
+
if(rule.base_behavior)
|
272
|
+
permissions_list[:can][action] ||= []
|
273
|
+
permissions_list[:can][action] += subjects.map(&:to_s)
|
274
|
+
else
|
275
|
+
permissions_list[:cannot][action] ||= []
|
276
|
+
permissions_list[:cannot][action] += subjects.map(&:to_s)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
permissions_list
|
282
|
+
end
|
283
|
+
|
255
284
|
private
|
256
285
|
|
257
286
|
def unauthorized_message_keys(action, subject)
|
data/lib/cancan/version.rb
CHANGED
data/spec/cancan/ability_spec.rb
CHANGED
@@ -155,6 +155,26 @@ describe CanCan::Ability do
|
|
155
155
|
expect(@ability.can?(:update, {:any => [123, 1.0]})).to be(false)
|
156
156
|
end
|
157
157
|
|
158
|
+
it "lists all permissions" do
|
159
|
+
@ability.can :manage, :all
|
160
|
+
@ability.can :learn, Range
|
161
|
+
@ability.cannot :read, String
|
162
|
+
@ability.cannot :read, Hash
|
163
|
+
@ability.cannot :preview, Array
|
164
|
+
|
165
|
+
expected_list = {:can => {:manage => ["all"],
|
166
|
+
:learn => ["Range"]
|
167
|
+
},
|
168
|
+
:cannot => {:read => ["String", "Hash"],
|
169
|
+
:index => ["String", "Hash"],
|
170
|
+
:show => ["String", "Hash"],
|
171
|
+
:preview => ["Array"]
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
expect(@ability.permissions).to eq(expected_list)
|
176
|
+
end
|
177
|
+
|
158
178
|
it "supports custom objects in the rule" do
|
159
179
|
@ability.can :read, :stats
|
160
180
|
expect(@ability.can?(:read, :stats)).to be(true)
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cancancan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Rite
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-06-
|
12
|
+
date: 2015-06-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -67,20 +67,6 @@ dependencies:
|
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: 1.0.0
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: pry
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - "~>"
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 0.10.0
|
77
|
-
type: :development
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - "~>"
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: 0.10.0
|
84
70
|
description: Continuation of the simple authorization solution for Rails which is
|
85
71
|
decoupled from user roles. All permissions are stored in a single location.
|
86
72
|
email: bryan@bryanrite.com
|
@@ -169,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
155
|
version: 1.3.4
|
170
156
|
requirements: []
|
171
157
|
rubyforge_project: cancancan
|
172
|
-
rubygems_version: 2.
|
158
|
+
rubygems_version: 2.2.3
|
173
159
|
signing_key:
|
174
160
|
specification_version: 4
|
175
161
|
summary: Simple authorization solution for Rails.
|