a11n 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +6 -0
- data/README.md +78 -0
- data/Rakefile +2 -0
- data/a11n.gemspec +24 -0
- data/lib/a11n/version.rb +3 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f238ef918fb1d4ed0eef77df95dc30a11c2bd9db
|
4
|
+
data.tar.gz: 9e7d0127729c68a17723f3486c553c8b989abe0b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '0196f3d365a234ea7fd143bee5ea1a4e7ebc2db30aeb38f23b3261e05cd0ec7913aa691428c416a526f536e0a8d05dd2f89388aeb4f18e5ea9427183d8f56d2b'
|
7
|
+
data.tar.gz: 94f5e256b5d31a5a2f5e25c7a1f1abeeffd2bd1e7a97ce4b048139015395c66bb7510086e33e9314a5a5f218b2148bc8e2ff1bc36e69eaf52536e26137a8f7ba
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# A11n
|
2
|
+
|
3
|
+
A11n handles authorization for Rails controllers! It's simple to use and extend.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "a11n"
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install a11n
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class Admin::ProductController < ApplicationController
|
25
|
+
authorization_for :create, [:admin, :support_staff]
|
26
|
+
authorization_for :destroy, [:admin]
|
27
|
+
|
28
|
+
def create
|
29
|
+
product = Production.new(product_params)
|
30
|
+
authorize product
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy
|
34
|
+
product = Production.find(params[:id])
|
35
|
+
authorize product
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class CommentsController < ApplicationController
|
40
|
+
authorization_for :destroy, [:belongs_to_user?, :admin?, :moderator?]
|
41
|
+
|
42
|
+
def destroy
|
43
|
+
comment = Comment.find(params[:id])
|
44
|
+
authorize comment
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class AdminPolicy < A11n::BasePolicy
|
49
|
+
def authorized?
|
50
|
+
user.admin?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class BelongsToUserPolicy < A11n::BasePolicy
|
55
|
+
def authorized?
|
56
|
+
record.user == user
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
### Advanced Usage
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
class CommentUpvotesController < ApplicationController
|
64
|
+
authorization_for :create, [:confirmed_user?]
|
65
|
+
authorization_for :create, -> { !BLACKLISTED_IPS.inclue?(request.ip)}
|
66
|
+
|
67
|
+
def create
|
68
|
+
upvote = CommentUpvote.new(upvote_params)
|
69
|
+
authorize upvote # authorizes the upvote if it
|
70
|
+
return unauthorized_action
|
71
|
+
# do work
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/stevendanils/a11n.
|
data/Rakefile
ADDED
data/a11n.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "a11n/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "a11n"
|
8
|
+
spec.version = A11n::VERSION
|
9
|
+
spec.authors = ["Steven Daniels"]
|
10
|
+
spec.email = ["stevendaniels88@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A11n is an authorization for Rails controllers.}
|
13
|
+
spec.description = %q{A11n handles authorization for Rails controllers! It's simple to use and extend.}
|
14
|
+
spec.homepage = "https://github.com/stevendaniels/a11n"
|
15
|
+
|
16
|
+
spec.files = ["Gemfile", "Rakefile", "README.md", "a11n.gemspec", "lib/a11n/version.rb"]
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activesupport", ">= 3.0.0"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
data/lib/a11n/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: a11n
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steven Daniels
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: A11n handles authorization for Rails controllers! It's simple to use
|
56
|
+
and extend.
|
57
|
+
email:
|
58
|
+
- stevendaniels88@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- a11n.gemspec
|
67
|
+
- lib/a11n/version.rb
|
68
|
+
homepage: https://github.com/stevendaniels/a11n
|
69
|
+
licenses: []
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.6.13
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: A11n is an authorization for Rails controllers.
|
91
|
+
test_files: []
|