cancancan 1.11.0 → 1.12.0

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: 31c960036e585081371697da5c478888f7f5f03d
4
- data.tar.gz: c0ecbe3789eae4ec649037153b750749bc5c6279
3
+ metadata.gz: 55bf93046d99f249ab63118d79f1188ef2383278
4
+ data.tar.gz: 052a7a962e2585ca122723f23a733d882872a660
5
5
  SHA512:
6
- metadata.gz: 3bf8dcc830c31f9b2b0658dd25f3995358d7ef2150a054a85646b766eb1e202c1c949a75ef618bdb0f772a8b5d9a10a3b35c9c392865092e1761f2a1693237cd
7
- data.tar.gz: 7eebcdd0f7a211f958279848dde7a076f2a9c048f110096ecf939bd85731750dda57a5e6b50589fbe1c3708b107117f047049bdce651756955a23fad9a247c58
6
+ metadata.gz: 7b4259d5de95a69c48301338605341a0f86d200ec01e56981a50d08e5367b7513042620fbeaae77d6790299dcae616feb606fa3c1718b20250bf29cd35356519
7
+ data.tar.gz: 1c58fbfde297986492dda47b7f1c03f86da96fb412fe2917bb75bbe8ea5e4e49607189d71c8f19336392d8dd7a7cc30a6b19e8c6e475cc69e38e9ecd533ac135
@@ -1,5 +1,9 @@
1
1
  Develop
2
2
 
3
+ 1.12.0 (June 28th, 2015)
4
+
5
+ * Add a permissions method to Ability (devaroop)
6
+
3
7
  1.11.0 (June 15th, 2015)
4
8
 
5
9
  * Complete cancancan#115 - Specify authorization action for parent resources. (phallguy)
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Code Climate Badge](https://codeclimate.com/github/CanCanCommunity/cancancan.png)](https://codeclimate.com/github/CanCanCommunity/cancancan)
6
6
  [![Inch CI](http://inch-ci.org/github/CanCanCommunity/cancancan.png)](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
 
@@ -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
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module CanCan
2
- VERSION = "1.11.0"
2
+ VERSION = "1.12.0"
3
3
  end
@@ -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)
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
- require 'pry'
4
3
 
5
4
  Bundler.require
6
5
 
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.11.0
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-16 00:00:00.000000000 Z
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.4.5
158
+ rubygems_version: 2.2.3
173
159
  signing_key:
174
160
  specification_version: 4
175
161
  summary: Simple authorization solution for Rails.