cancancan 1.17.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/cancancan.gemspec +4 -6
  3. data/lib/cancan.rb +2 -11
  4. data/lib/cancan/ability.rb +1 -1
  5. data/lib/cancan/controller_additions.rb +3 -24
  6. data/lib/cancan/controller_resource.rb +9 -25
  7. data/lib/cancan/matchers.rb +7 -1
  8. data/lib/cancan/model_adapters/active_record_4_adapter.rb +1 -3
  9. data/lib/cancan/model_adapters/active_record_adapter.rb +2 -2
  10. data/lib/cancan/rule.rb +2 -2
  11. data/lib/cancan/version.rb +1 -1
  12. metadata +22 -69
  13. data/.gitignore +0 -15
  14. data/.rspec +0 -1
  15. data/.rubocop.yml +0 -39
  16. data/.rubocop_todo.yml +0 -54
  17. data/.travis.yml +0 -39
  18. data/Appraisals +0 -105
  19. data/CHANGELOG.rdoc +0 -536
  20. data/CONTRIBUTING.md +0 -23
  21. data/Gemfile +0 -3
  22. data/LICENSE +0 -22
  23. data/README.md +0 -234
  24. data/Rakefile +0 -13
  25. data/gemfiles/activerecord_3.2.gemfile +0 -18
  26. data/gemfiles/activerecord_4.0.gemfile +0 -19
  27. data/gemfiles/activerecord_4.1.gemfile +0 -19
  28. data/gemfiles/activerecord_4.2.gemfile +0 -21
  29. data/gemfiles/activerecord_5.0.gemfile +0 -20
  30. data/gemfiles/mongoid_2.x.gemfile +0 -18
  31. data/gemfiles/sequel_3.x.gemfile +0 -18
  32. data/lib/cancan/inherited_resource.rb +0 -20
  33. data/lib/cancan/model_adapters/active_record_3_adapter.rb +0 -16
  34. data/lib/cancan/model_adapters/mongoid_adapter.rb +0 -80
  35. data/lib/cancan/model_adapters/sequel_adapter.rb +0 -87
  36. data/spec/README.rdoc +0 -27
  37. data/spec/cancan/ability_spec.rb +0 -553
  38. data/spec/cancan/controller_additions_spec.rb +0 -164
  39. data/spec/cancan/controller_resource_spec.rb +0 -645
  40. data/spec/cancan/exceptions_spec.rb +0 -58
  41. data/spec/cancan/inherited_resource_spec.rb +0 -71
  42. data/spec/cancan/matchers_spec.rb +0 -29
  43. data/spec/cancan/model_adapters/active_record_4_adapter_spec.rb +0 -160
  44. data/spec/cancan/model_adapters/active_record_adapter_spec.rb +0 -415
  45. data/spec/cancan/model_adapters/default_adapter_spec.rb +0 -7
  46. data/spec/cancan/model_adapters/mongoid_adapter_spec.rb +0 -246
  47. data/spec/cancan/model_adapters/sequel_adapter_spec.rb +0 -129
  48. data/spec/cancan/rule_spec.rb +0 -52
  49. data/spec/matchers.rb +0 -13
  50. data/spec/spec.opts +0 -2
  51. data/spec/spec_helper.rb +0 -27
  52. data/spec/support/ability.rb +0 -6
data/CONTRIBUTING.md DELETED
@@ -1,23 +0,0 @@
1
- ## Contributing to CanCanCan
2
-
3
- ### Reporting an Issue
4
-
5
- 1. If you have any questions about CanCanCan, search the [Wiki](https://github.com/cancancommunity/cancancan/wiki), use [Stack Overflow](http://stackoverflow.com/questions/tagged/cancancan), or [our mailing list](https://groups.google.com/forum/#!forum/cancancan). Do not post questions here.
6
-
7
- 1. If you find a security bug, **DO NOT** submit an issue here. Please send an e-mail to the current maintainer instead.
8
-
9
- 1. Do a small search on the issues tracker before submitting your issue to see if it was already reported / fixed.
10
-
11
- 1. Create your report including Rails and CanCanCan versions. If you are getting exceptions, please include the full backtrace.
12
-
13
- That's it! The more information you give, the more easy it becomes for us to track it down and fix it. Ideal scenario would be adding the issue to CanCanCan test suite or to a sample application.
14
-
15
- ### Adding new Features or Bugfixes
16
-
17
- CanCanCan uses a [git-flow](http://nvie.com/posts/a-successful-git-branching-model/) development model. The latest "released" version of CanCanCan, the latest gem version, can always be found on `master`, while the next version or nightly is on `develop`.
18
-
19
- Please make sure you have test coverage for anything you add or fix!
20
-
21
- Please add a CHANGELOG entry with any relevant tags for issues, pull-requests, and authors.
22
-
23
- Thanks!
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2011 Ryan Bates
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,234 +0,0 @@
1
- # CanCanCan
2
-
3
- [![Gem Version](https://badge.fury.io/rb/cancancan.svg)](http://badge.fury.io/rb/cancancan)
4
- [![Travis badge](https://travis-ci.org/CanCanCommunity/cancancan.svg?branch=develop)](https://travis-ci.org/CanCanCommunity/cancancan)
5
- [![Code Climate Badge](https://codeclimate.com/github/CanCanCommunity/cancancan.svg)](https://codeclimate.com/github/CanCanCommunity/cancancan)
6
- [![Inch CI](http://inch-ci.org/github/CanCanCommunity/cancancan.svg)](http://inch-ci.org/github/CanCanCommunity/cancancan)
7
-
8
- [Wiki](https://github.com/CanCanCommunity/cancancan/wiki) |
9
- [RDocs](http://rdoc.info/projects/CanCanCommunity/cancancan) |
10
- [Screencast](http://railscasts.com/episodes/192-authorization-with-cancan) |
11
- [Gitter](https://gitter.im/CanCanCommunity/cancancan)
12
-
13
- CanCanCan is an authorization library for Ruby 2.0+ and Ruby on Rails 3+ which restricts what resources a given user is allowed to access.
14
-
15
- All permissions are defined in a single location (the `Ability` class) and not duplicated across controllers, views, and database queries.
16
-
17
-
18
- ## Installation
19
-
20
- Add this to your Gemfile:
21
-
22
- gem 'cancancan', '~> 1.10'
23
-
24
- and run the `bundle install` command.
25
-
26
- ## Getting Started
27
-
28
- CanCanCan expects a `current_user` method to exist in the controller.
29
- First, set up some authentication (such as [Devise](https://github.com/plataformatec/devise) or [Authlogic](https://github.com/binarylogic/authlogic)).
30
- See [Changing Defaults](https://github.com/CanCanCommunity/cancancan/wiki/changing-defaults) if you need a different behavior.
31
-
32
- When using [rails-api](https://github.com/rails-api/rails-api), you have to manually include the controller methods for CanCanCan:
33
- ```ruby
34
- class ApplicationController < ActionController::API
35
- include CanCan::ControllerAdditions
36
- end
37
- ```
38
-
39
- ### 1. Define Abilities
40
-
41
- User permissions are defined in an `Ability` class.
42
-
43
- rails g cancan:ability
44
-
45
- See [Defining Abilities](https://github.com/CanCanCommunity/cancancan/wiki/defining-abilities) for details.
46
-
47
-
48
- ### 2. Check Abilities & Authorization
49
-
50
- The current user's permissions can then be checked using the `can?` and `cannot?` methods in views and controllers.
51
-
52
- ```erb
53
- <% if can? :update, @article %>
54
- <%= link_to "Edit", edit_article_path(@article) %>
55
- <% end %>
56
- ```
57
-
58
- See [Checking Abilities](https://github.com/CanCanCommunity/cancancan/wiki/checking-abilities) for more information
59
-
60
- The `authorize!` method in the controller will raise an exception if the user is not able to perform the given action.
61
-
62
- ```ruby
63
- def show
64
- @article = Article.find(params[:id])
65
- authorize! :read, @article
66
- end
67
- ```
68
-
69
- Setting this for every action can be tedious, therefore the `load_and_authorize_resource` method is provided to
70
- automatically authorize all actions in a RESTful style resource controller.
71
- It will use a before action to load the resource into an instance variable and authorize it for every action.
72
-
73
- ```ruby
74
- class ArticlesController < ApplicationController
75
- load_and_authorize_resource
76
-
77
- def show
78
- # @article is already loaded and authorized
79
- end
80
- end
81
- ```
82
-
83
- See [Authorizing Controller Actions](https://github.com/CanCanCommunity/cancancan/wiki/authorizing-controller-actions) for more information.
84
-
85
-
86
- #### Strong Parameters
87
-
88
- When using `strong_parameters` or Rails 4+, you have to sanitize inputs before saving the record, in actions such as `:create` and `:update`.
89
-
90
- For the `:update` action, CanCanCan will load and authorize the resource but *not* change it automatically, so the typical usage would be something like:
91
-
92
- ```ruby
93
- def update
94
- if @article.update_attributes(update_params)
95
- # hurray
96
- else
97
- render :edit
98
- end
99
- end
100
- ...
101
-
102
- def update_params
103
- params.require(:article).permit(:body)
104
- end
105
- ```
106
-
107
- For the `:create` action, CanCanCan will try to initialize a new instance with sanitized input by seeing if your
108
- controller will respond to the following methods (in order):
109
-
110
- 1. `create_params`
111
- 2. `<model_name>_params` such as `article_params` (this is the default convention in rails for naming your param method)
112
- 3. `resource_params` (a generically named method you could specify in each controller)
113
-
114
- Additionally, `load_and_authorize_resource` can now take a `param_method` option to specify a custom method in the controller to run to sanitize input.
115
-
116
- You can associate the `param_method` option with a symbol corresponding to the name of a method that will get called:
117
-
118
- ```ruby
119
- class ArticlesController < ApplicationController
120
- load_and_authorize_resource param_method: :my_sanitizer
121
-
122
- def create
123
- if @article.save
124
- # hurray
125
- else
126
- render :new
127
- end
128
- end
129
-
130
- private
131
-
132
- def my_sanitizer
133
- params.require(:article).permit(:name)
134
- end
135
- end
136
- ```
137
-
138
- You can also use a string that will be evaluated in the context of the controller using `instance_eval` and needs to contain valid Ruby code.
139
-
140
- load_and_authorize_resource param_method: 'permitted_params.article'
141
-
142
- Finally, it's possible to associate `param_method` with a Proc object which will be called with the controller as the only argument:
143
-
144
- load_and_authorize_resource param_method: Proc.new { |c| c.params.require(:article).permit(:name) }
145
-
146
- See [Strong Parameters](https://github.com/CanCanCommunity/cancancan/wiki/Strong-Parameters) for more information.
147
-
148
- ### 3. Handle Unauthorized Access
149
-
150
- If the user authorization fails, a `CanCan::AccessDenied` exception will be raised.
151
- You can catch this and modify its behavior in the `ApplicationController`.
152
-
153
- ```ruby
154
- class ApplicationController < ActionController::Base
155
- rescue_from CanCan::AccessDenied do |exception|
156
- respond_to do |format|
157
- format.json { head :forbidden, content_type: 'text/html' }
158
- format.html { redirect_to main_app.root_url, notice: exception.message }
159
- format.js { head :forbidden, content_type: 'text/html' }
160
- end
161
- end
162
- end
163
- ```
164
-
165
- See [Exception Handling](https://github.com/CanCanCommunity/cancancan/wiki/exception-handling) for more information.
166
-
167
-
168
- ### 4. Lock It Down
169
-
170
- If you want to ensure authorization happens on every action in your application, add `check_authorization` to your `ApplicationController`.
171
-
172
- ```ruby
173
- class ApplicationController < ActionController::Base
174
- check_authorization
175
- end
176
- ```
177
-
178
- This will raise an exception if authorization is not performed in an action.
179
- If you want to skip this, add `skip_authorization_check` to a controller subclass.
180
- See [Ensure Authorization](https://github.com/CanCanCommunity/cancancan/wiki/Ensure-Authorization) for more information.
181
-
182
-
183
- ## Wiki Docs
184
-
185
- * [Upgrading to 1.6](https://github.com/CanCanCommunity/cancancan/wiki/Upgrading-to-1.6)
186
- * [Defining Abilities](https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities)
187
- * [Checking Abilities](https://github.com/CanCanCommunity/cancancan/wiki/Checking-Abilities)
188
- * [Authorizing Controller Actions](https://github.com/CanCanCommunity/cancancan/wiki/Authorizing-Controller-Actions)
189
- * [Exception Handling](https://github.com/CanCanCommunity/cancancan/wiki/Exception-Handling)
190
- * [Changing Defaults](https://github.com/CanCanCommunity/cancancan/wiki/Changing-Defaults)
191
- * [See more](https://github.com/CanCanCommunity/cancancan/wiki)
192
-
193
- ## Mission
194
-
195
- This repo is a continuation of the dead [CanCan](https://github.com/ryanb/cancan) project.
196
- Our mission is to keep CanCan alive and moving forward, with maintenance fixes and new features.
197
- Pull Requests are welcome!
198
-
199
- Any help is greatly appreciated, feel free to submit pull-requests or open issues.
200
-
201
-
202
- ## Questions?
203
-
204
- If you have any question or doubt regarding CanCanCan which you cannot find the solution to in the
205
- [documentation](https://github.com/CanCanCommunity/cancancan/wiki) or our
206
- [mailing list](http://groups.google.com/group/cancancan), please
207
- [open a question on Stackoverflow](http://stackoverflow.com/questions/ask?tags=cancancan) with tag
208
- [cancancan](http://stackoverflow.com/questions/tagged/cancancan)
209
-
210
- ## Bugs?
211
-
212
- If you find a bug please add an [issue on GitHub](https://github.com/CanCanCommunity/cancancan/issues) or fork the project and send a pull request.
213
-
214
-
215
- ## Development
216
-
217
- CanCanCan uses [appraisals](https://github.com/thoughtbot/appraisal) to test the code base against multiple versions
218
- of Rails, as well as the different model adapters.
219
-
220
- When first developing, you may need to run `bundle install` and then `appraisal install`, to install the different sets.
221
-
222
- You can then run all appraisal files (like CI does), with `appraisal rake` or just run a specific set `appraisal activerecord_3.0 rake`.
223
-
224
- See the [CONTRIBUTING](https://github.com/CanCanCommunity/cancancan/blob/develop/CONTRIBUTING.md) and
225
- [spec/README](https://github.com/CanCanCommunity/cancancan/blob/master/spec/README.rdoc) for more information.
226
-
227
-
228
- ## Special Thanks
229
-
230
- CanCanCan was inspired by [declarative_authorization](https://github.com/stffn/declarative_authorization/) and
231
- [aegis](https://github.com/makandra/aegis).
232
-
233
- Also many thanks to the [CanCanCan contributors](https://github.com/CanCanCommunity/cancancan/contributors).
234
- See the [CHANGELOG](https://github.com/CanCanCommunity/cancancan/blob/master/CHANGELOG.rdoc) for the full list.
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
- require 'rubocop/rake_task'
4
-
5
- desc 'Run Rubocop'
6
- RuboCop::RakeTask.new
7
-
8
- desc 'Run RSpec'
9
- RSpec::Core::RakeTask.new do |t|
10
- t.verbose = false
11
- end
12
-
13
- task default: [:rubocop, :spec]
@@ -1,18 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 3.2.0", :require => "active_record"
6
- gem "actionpack", "~> 3.2.0", :require => "action_pack"
7
- gem "rubocop", "0.48.0"
8
-
9
- platforms :jruby do
10
- gem "activerecord-jdbcsqlite3-adapter"
11
- gem "jdbc-sqlite3"
12
- end
13
-
14
- platforms :ruby, :mswin, :mingw do
15
- gem "sqlite3"
16
- end
17
-
18
- gemspec :path => "../"
@@ -1,19 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.0.5", :require => "active_record"
6
- gem "activesupport", "~> 4.0.5", :require => "active_support/all"
7
- gem "actionpack", "~> 4.0.5", :require => "action_pack"
8
- gem "rubocop", "0.48.0"
9
-
10
- platforms :jruby do
11
- gem "activerecord-jdbcsqlite3-adapter"
12
- gem "jdbc-sqlite3"
13
- end
14
-
15
- platforms :ruby, :mswin, :mingw do
16
- gem "sqlite3"
17
- end
18
-
19
- gemspec :path => "../"
@@ -1,19 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.1.1", :require => "active_record"
6
- gem "activesupport", "~> 4.1.1", :require => "active_support/all"
7
- gem "actionpack", "~> 4.1.1", :require => "action_pack"
8
- gem "rubocop", "0.48.0"
9
-
10
- platforms :jruby do
11
- gem "activerecord-jdbcsqlite3-adapter"
12
- gem "jdbc-sqlite3"
13
- end
14
-
15
- platforms :ruby, :mswin, :mingw do
16
- gem "sqlite3"
17
- end
18
-
19
- gemspec :path => "../"
@@ -1,21 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.2.0", :require => "active_record"
6
- gem "activesupport", "~> 4.2.0", :require => "active_support/all"
7
- gem "actionpack", "~> 4.2.0", :require => "action_pack"
8
- gem "nokogiri", "~> 1.6.8", :require => "nokogiri"
9
- gem "rubocop", "0.48.0"
10
-
11
- platforms :jruby do
12
- gem "activerecord-jdbcsqlite3-adapter"
13
- gem "jdbc-sqlite3"
14
- end
15
-
16
- platforms :ruby, :mswin, :mingw do
17
- gem "sqlite3"
18
- gem "pg"
19
- end
20
-
21
- gemspec :path => "../"
@@ -1,20 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.0.0.rc1", :require => "active_record"
6
- gem "activesupport", "~> 5.0.0.rc1", :require => "active_support/all"
7
- gem "actionpack", "~> 5.0.0.rc1", :require => "action_pack"
8
- gem "rubocop", "0.48.0"
9
-
10
- platforms :jruby do
11
- gem "activerecord-jdbcsqlite3-adapter"
12
- gem "jdbc-sqlite3"
13
- end
14
-
15
- platforms :ruby, :mswin, :mingw do
16
- gem "sqlite3"
17
- gem "pg"
18
- end
19
-
20
- gemspec :path => "../"
@@ -1,18 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activesupport", "~> 3.0", :require => "active_support/all"
6
- gem "actionpack", "~> 3.0", :require => "action_pack"
7
- gem "mongoid", "~> 2.0.0"
8
- gem "rubocop", "0.48.0"
9
-
10
- platforms :ruby, :mswin, :mingw do
11
- gem "bson_ext", "~> 1.1"
12
- end
13
-
14
- platforms :jruby do
15
- gem "mongo", "~> 1.9.2"
16
- end
17
-
18
- gemspec :path => "../"
@@ -1,18 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "sequel", "~> 3.48.0"
6
- gem "activesupport", "~> 3.0", :require => "active_support/all"
7
- gem "actionpack", "~> 3.0", :require => "action_pack"
8
- gem "rubocop", "0.48.0"
9
-
10
- platforms :jruby do
11
- gem "jdbc-sqlite3"
12
- end
13
-
14
- platforms :ruby, :mswin, :mingw do
15
- gem "sqlite3"
16
- end
17
-
18
- gemspec :path => "../"