grant-front 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +3 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +9 -0
- data/grant-front.gemspec +23 -0
- data/lib/grant-front.rb +9 -0
- data/lib/grant-front/grant.rb +26 -0
- data/lib/grant-front/policy.rb +50 -0
- data/lib/grant-front/rails.rb +7 -0
- data/lib/grant-front/version.rb +3 -0
- data/lib/tasks/grant-front.rake +6 -0
- data/spec/grant-front_spec.rb +4 -0
- data/spec/lib/version_spec.rb +9 -0
- data/spec/spec_helper.rb +1 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 975726e6082113ecaa80005e74fd6763b2f8b2e8
|
4
|
+
data.tar.gz: 673d310c584b1105ab3c84b7e9e2ca9ecb583d30
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0aade26dfca87ff36b9f18595e965028994b0e71150a01e428b85b0284edeae412747355d2ccf54d0158ab56893ffca5dce44591c06a007ffbc24e969fa6a6f4
|
7
|
+
data.tar.gz: 097f9ae8ed257a45c278de3563a501cf0d8abab896c6c408e29169c5dded4fa2f6702266f724c1056a052c599f8c2fa908424ac47b0b419a22f33b0dad668663
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 ogom
|
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
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# GrantFront
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/grant-front.png)](https://rubygems.org/gems/grant-front) [![Build Status](https://travis-ci.org/ogom/grant-front.png?branch=master)](https://travis-ci.org/ogom/grant-front)
|
4
|
+
|
5
|
+
Authorization Grant Front on Rails.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```
|
12
|
+
gem 'grant-front'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```
|
24
|
+
$ gem install grant-front
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```
|
30
|
+
class UserPolicy < ApplicationPolicy
|
31
|
+
def create?
|
32
|
+
grant :foo, :bar, :baz
|
33
|
+
end
|
34
|
+
|
35
|
+
def grant(*roles)
|
36
|
+
roles.each do |role|
|
37
|
+
return true if user.roles.include? role
|
38
|
+
end
|
39
|
+
return false, roles
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
```
|
45
|
+
$ rake grant_front:draw
|
46
|
+
```
|
47
|
+
|
48
|
+
||foo|bar|baz|
|
49
|
+
|:-:|:-:|:-:|:-:|
|
50
|
+
|create|o|o|o|
|
51
|
+
|new|o|o|o|
|
52
|
+
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
* MIT
|
data/Rakefile
ADDED
data/grant-front.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'grant-front/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "grant-front"
|
8
|
+
spec.version = GrantFront::VERSION
|
9
|
+
spec.authors = ["ogom"]
|
10
|
+
spec.email = ["ogom@hotmail.co.jp"]
|
11
|
+
spec.summary = %q{Authorization Grant Front.}
|
12
|
+
spec.description = %q{Authorization Grant Front on Rails.}
|
13
|
+
spec.homepage = "http://ogom.github.io/grant-front"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
end
|
data/lib/grant-front.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module GrantFront
|
2
|
+
class Grant
|
3
|
+
class << self
|
4
|
+
def draw
|
5
|
+
policies = {}
|
6
|
+
GrantFront::Policy.all.each do |klass|
|
7
|
+
policies[klass.to_s.to_sym] = GrantFront::Policy.find(klass)
|
8
|
+
end
|
9
|
+
|
10
|
+
policies.keys.each do |policy|
|
11
|
+
puts "\n# #{policy} \n\n"
|
12
|
+
puts "||#{policies[policy][:roles].join('|')}|"
|
13
|
+
puts "|:-:|#{policies[policy][:roles].map{':-:'}.join('|')}|"
|
14
|
+
policies[policy][:methods].keys.each do |method|
|
15
|
+
raw = "|#{method}|"
|
16
|
+
policies[policy][:roles].each do |role|
|
17
|
+
raw += 'o' if policies[policy][:methods][method].include?(role)
|
18
|
+
raw += '|'
|
19
|
+
end
|
20
|
+
puts raw
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module GrantFront
|
2
|
+
class Policy
|
3
|
+
class << self
|
4
|
+
def all
|
5
|
+
requires
|
6
|
+
|
7
|
+
Object.constants.inject([]) do |arr, name|
|
8
|
+
unless name == :Config
|
9
|
+
klass = Object.const_get(name)
|
10
|
+
if klass.class == Class && klass.superclass == ApplicationPolicy
|
11
|
+
arr << klass
|
12
|
+
end
|
13
|
+
end
|
14
|
+
arr
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def find(klass=nil)
|
19
|
+
raw = {methods: {}, roles: []}
|
20
|
+
reg = Regexp.new(/\?$/)
|
21
|
+
user = Struct.new(:id, :roles).new(1, [])
|
22
|
+
|
23
|
+
policy = klass.new(user, user)
|
24
|
+
policy.methods.each do |name|
|
25
|
+
if name =~ reg
|
26
|
+
owner = policy.method(name).owner
|
27
|
+
if owner == klass or owner == ApplicationPolicy
|
28
|
+
allow, roles = policy.send(name)
|
29
|
+
roles ||= []
|
30
|
+
raw[:methods][name.to_s.gsub(reg, '').to_sym] = roles
|
31
|
+
raw[:roles] += roles
|
32
|
+
raw[:roles].uniq!
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
raw
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def requires
|
42
|
+
if defined? Rails
|
43
|
+
Dir.glob(Rails.root.join('app/policies/*.rb').to_s).each do |name|
|
44
|
+
require name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'grant-front'
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grant-front
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ogom
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Authorization Grant Front on Rails.
|
42
|
+
email:
|
43
|
+
- ogom@hotmail.co.jp
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- grant-front.gemspec
|
55
|
+
- lib/grant-front.rb
|
56
|
+
- lib/grant-front/grant.rb
|
57
|
+
- lib/grant-front/policy.rb
|
58
|
+
- lib/grant-front/rails.rb
|
59
|
+
- lib/grant-front/version.rb
|
60
|
+
- lib/tasks/grant-front.rake
|
61
|
+
- spec/grant-front_spec.rb
|
62
|
+
- spec/lib/version_spec.rb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
homepage: http://ogom.github.io/grant-front
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.2.2
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Authorization Grant Front.
|
88
|
+
test_files:
|
89
|
+
- spec/grant-front_spec.rb
|
90
|
+
- spec/lib/version_spec.rb
|
91
|
+
- spec/spec_helper.rb
|