authorize_if 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -0
- data/README.md +15 -18
- data/Rakefile +2 -2
- data/lib/authorize_if.rb +7 -8
- data/lib/authorize_if/version.rb +1 -1
- metadata +3 -17
- data/LICENSE +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96b46c082a1f9ef7b714d8e5800205ce7f3a652f
|
4
|
+
data.tar.gz: 02f069b094970c505ef2e633da6bfdeb9bffb175
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb1024b01ca4ad1ef7e4f61bc1673efa0b9a9500b4a0147754cfbc0ee6fe575345ef630ebb00d05493b24005bc1fb98491557c1cbdb602e243db7846622a2456
|
7
|
+
data.tar.gz: 1e1c27faadcb4e876151197f41efb065bde6c7067273e1b6f14178dfa717410d30a874e9e38eceb3bc673d9bd5cdd0475e81e382c40ee5375777ba541d9d7d38
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Vladimir Rybas
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# authorize_if [![Gem Version](https://badge.fury.io/rb/authorize_if.svg)](https://badge.fury.io/rb/authorize_if) [![Build Status](https://travis-ci.org/vrybas/authorize_if.svg?branch=master)](https://travis-ci.org/vrybas/authorize_if) [![Code Climate](https://codeclimate.com/github/vrybas/authorize_if/badges/gpa.svg)](https://codeclimate.com/github/vrybas/authorize_if)
|
2
2
|
|
3
3
|
Minimalistic authorization library for Ruby on Rails applications. It
|
4
|
-
defines controller methods `authorize_if` and `authorize`, which
|
5
|
-
inline or pre-defined authorization rules and raise exception
|
6
|
-
evaluates to `false`.
|
4
|
+
defines controller methods `authorize_if` and `authorize`, which
|
5
|
+
evaluate inline or pre-defined authorization rules and raise exception
|
6
|
+
if rule evaluates to `false`.
|
7
7
|
|
8
8
|
## API documentation
|
9
9
|
|
@@ -16,11 +16,13 @@ evaluates to `false`.
|
|
16
16
|
##### [`authorize`](#authorize) - authorization using pre-defined authorization rules
|
17
17
|
* [Organizing authorization rules](#organizing-authorization-rules)
|
18
18
|
|
19
|
-
##### [`Installation`](#installation)
|
19
|
+
##### [`Installation`](#installation-1)
|
20
20
|
|
21
|
-
##### [`Contributing`](#contributing)
|
21
|
+
##### [`Contributing`](#contributing-1)
|
22
22
|
|
23
|
-
##### [`License`](#license)
|
23
|
+
##### [`License`](#license-1)
|
24
|
+
|
25
|
+
- - -
|
24
26
|
|
25
27
|
## `authorize_if`
|
26
28
|
|
@@ -68,18 +70,19 @@ class ArticlesController < ApplicationController
|
|
68
70
|
# ...
|
69
71
|
|
70
72
|
rescue AuthorizeIf::NotAuthorizedError
|
71
|
-
head
|
73
|
+
head 404
|
72
74
|
|
73
75
|
end
|
74
76
|
end
|
75
77
|
```
|
76
78
|
|
77
|
-
or with `rescue_from` in `
|
79
|
+
or with `rescue_from` in `ApplicationController`:
|
78
80
|
|
79
81
|
```ruby
|
80
82
|
class ApplicationController < ActionController::Base
|
81
83
|
rescue_from AuthorizeIf::NotAuthorizedError do |exception|
|
82
|
-
head
|
84
|
+
head 404
|
85
|
+
|
83
86
|
end
|
84
87
|
end
|
85
88
|
```
|
@@ -100,7 +103,6 @@ class ArticlesController < ApplicationController
|
|
100
103
|
exception.message = "You are not authorized!"
|
101
104
|
|
102
105
|
exception.context[:request_ip] = "192.168.1.1"
|
103
|
-
exception.context[:user_agent] = "Gecko"
|
104
106
|
end
|
105
107
|
# ...
|
106
108
|
end
|
@@ -115,9 +117,6 @@ class ApplicationController < ActionController::Base
|
|
115
117
|
|
116
118
|
exception.context[:request_ip]
|
117
119
|
# => "192.168.1.1"
|
118
|
-
|
119
|
-
exception.context[:user_agent]
|
120
|
-
# => "Gecko"
|
121
120
|
end
|
122
121
|
end
|
123
122
|
```
|
@@ -214,11 +213,9 @@ end
|
|
214
213
|
```
|
215
214
|
|
216
215
|
```ruby
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
current_user.present?
|
221
|
-
end
|
216
|
+
module AuthorizationRules
|
217
|
+
def authorize_index?
|
218
|
+
current_user.present?
|
222
219
|
end
|
223
220
|
end
|
224
221
|
```
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
10
|
rdoc.rdoc_dir = 'rdoc'
|
11
11
|
rdoc.title = 'AuthorizeIf'
|
12
12
|
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
15
|
end
|
16
16
|
|
@@ -19,7 +19,7 @@ end
|
|
19
19
|
|
20
20
|
|
21
21
|
|
22
|
-
|
22
|
+
require 'bundler/gem_tasks'
|
23
23
|
|
24
24
|
require 'rake/testtask'
|
25
25
|
|
data/lib/authorize_if.rb
CHANGED
@@ -138,12 +138,9 @@ module AuthorizeIf
|
|
138
138
|
rule_method_name = "authorize_#{action_name}?"
|
139
139
|
|
140
140
|
unless self.respond_to?(rule_method_name, true)
|
141
|
-
msg =
|
142
|
-
|
143
|
-
|
144
|
-
"Please define method ##{rule_method_name} for",
|
145
|
-
self.class.name
|
146
|
-
].join(' ')
|
141
|
+
msg = "No authorization rule defined for action"\
|
142
|
+
" #{controller_name}##{action_name}."\
|
143
|
+
" Please define method ##{rule_method_name} for #{self.class.name}"
|
147
144
|
|
148
145
|
raise(MissingAuthorizationRuleError, msg)
|
149
146
|
end
|
@@ -152,6 +149,8 @@ module AuthorizeIf
|
|
152
149
|
end
|
153
150
|
end
|
154
151
|
|
155
|
-
ActiveSupport
|
156
|
-
|
152
|
+
if defined?(ActiveSupport)
|
153
|
+
ActiveSupport.on_load :action_controller do
|
154
|
+
include AuthorizeIf
|
155
|
+
end
|
157
156
|
end
|
data/lib/authorize_if/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authorize_if
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Rybas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rails
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 4.2.5
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 4.2.5
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rspec-rails
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,7 +45,7 @@ executables: []
|
|
59
45
|
extensions: []
|
60
46
|
extra_rdoc_files: []
|
61
47
|
files:
|
62
|
-
- LICENSE
|
48
|
+
- MIT-LICENSE
|
63
49
|
- README.md
|
64
50
|
- Rakefile
|
65
51
|
- lib/authorize_if.rb
|
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2016 Vladimir Rybas
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|