grut 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +69 -0
- data/Rakefile +12 -0
- data/grut.gemspec +34 -0
- data/lib/grut.rb +10 -0
- data/lib/grut/asset.rb +24 -0
- data/lib/grut/concerns/db_tables.rb +19 -0
- data/lib/grut/config.rb +17 -0
- data/lib/grut/db.rb +22 -0
- data/lib/grut/guardian.rb +108 -0
- data/lib/grut/statement.rb +33 -0
- data/lib/grut/version.rb +3 -0
- data/lib/tasks/grut.rake +39 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d0a152aead7d0328607420a097d0c2dc43d3bbad
|
4
|
+
data.tar.gz: d9b0a008d5489237a692f31172634f1230d0e42d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b7aef20f767db66ca8a0c2996f9fde8d5ea943509439cbed06912f0522c82d2fdc132320291140c1cb2e1f582b0273a8e6f7c32c28536c1c95a81e8255774eb
|
7
|
+
data.tar.gz: 8ac137414db8a7dea64ede667ecca2492a0faeeb6750c5da58db93d68e8c1a4c8f696906474c1640752d2516721bc05a2df58ca221f7b389c75044cbb4586bae
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at ka8725@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Andrey Koleshko
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Grut
|
2
|
+
|
3
|
+
Define user permissions in a Ruby project dynamically and store them in a database with Grut's help.
|
4
|
+
This allows to manage access to specific entities for concrete users on the fly through a user interface.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Grut requires already installed any of the database adapters supported by [sequel](https://github.com/jeremyevans/sequel). `pg` and `mysql2` are the most popular ones.
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'grut'
|
14
|
+
```
|
15
|
+
|
16
|
+
Configure the database connection after that in some place of the project that have Grut installed. For example, it could be the following line in the `config/application.rb` of a Rails project:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
Grut::Config.instance.db_url = 'postgres://ka8725:@localhost/check_development'
|
20
|
+
```
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
There are two main classes: `Grut::Guardian` and `Grut::Statement`. Use `Grut::Guardian` to manage control
|
25
|
+
access for entries and `Grut::Statement` to get information about defined permissions for a given user.
|
26
|
+
Look into the following code snippet that demonstrates their usage:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
user = Struct.new(:id).new(42)
|
30
|
+
store = Struct.new(:id).new(12)
|
31
|
+
|
32
|
+
guardian = Grut::Guardian.new(user, :admin)
|
33
|
+
statement = Grut::Statement.new(user)
|
34
|
+
|
35
|
+
guardian.permitted?(:manage_store, all: true) # => false
|
36
|
+
guardian.permitted?(:manage_store, id: store.id) # => false
|
37
|
+
statement.all #=> []
|
38
|
+
|
39
|
+
guardian.permit(:manage_store, all: true)
|
40
|
+
guardian.permitted?(:manage_store, all: true) # => true
|
41
|
+
guardian.permitted?(:manage_store, id: store.id) # => true
|
42
|
+
statement.all #=> [#<struct Grut::Statement::Entry role="admin", permission="manage_store", contract_key="all", contract_value="true">]
|
43
|
+
|
44
|
+
guardian.forbid(:manage_store, all: true)
|
45
|
+
guardian.permitted?(:manage_store, all: true) # => false
|
46
|
+
guardian.permitted?(:manage_store, id: store.id) # => false
|
47
|
+
statement.all #=> []
|
48
|
+
|
49
|
+
guardian.permit(:manage_store, id: 1)
|
50
|
+
guardian.permitted?(:manage_store, all: true) # => true
|
51
|
+
guardian.permitted?(:manage_store, id: store.id) # => true
|
52
|
+
statement.all #=> [#<struct Grut::Statement::Entry role="admin", permission="manage_store", contract_key="id", contract_value="1">]
|
53
|
+
```
|
54
|
+
|
55
|
+
## Development
|
56
|
+
|
57
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
58
|
+
|
59
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Andrey Koleshko/grut. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
64
|
+
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
69
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require_relative './lib/grut'
|
4
|
+
|
5
|
+
Rake::TestTask.new(:test) do |t|
|
6
|
+
t.libs << 'test'
|
7
|
+
t.libs << 'lib'
|
8
|
+
t.test_files = FileList['test/**/*_test.rb']
|
9
|
+
end
|
10
|
+
|
11
|
+
task :test_db_setup => ['grut:remove', 'grut:install']
|
12
|
+
task :default => [:test_db_setup, :test]
|
data/grut.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'grut/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'grut'
|
8
|
+
spec.version = Grut::VERSION
|
9
|
+
spec.authors = ['Andrey Koleshko']
|
10
|
+
spec.email = ['ka8725@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Flexible authorization solution.}
|
13
|
+
spec.description = %q{
|
14
|
+
Thi is an authorization system for a Ruby (including Rails) project,
|
15
|
+
that allows to specify dynamic permissions. All data is stored
|
16
|
+
in an SQL database, supported by Sequel.
|
17
|
+
}
|
18
|
+
spec.homepage = ''
|
19
|
+
spec.license = 'MIT'
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
22
|
+
f.match(%r{^(test|spec|features|config|bin)/})
|
23
|
+
end
|
24
|
+
spec.bindir = 'exe'
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
31
|
+
spec.add_development_dependency 'pry-byebug'
|
32
|
+
spec.add_development_dependency 'pg'
|
33
|
+
spec.add_dependency 'sequel'
|
34
|
+
end
|
data/lib/grut.rb
ADDED
data/lib/grut/asset.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Grut
|
2
|
+
module Asset
|
3
|
+
def self.stringify_hash(hash)
|
4
|
+
hash.reduce({}) do |res, (key, val)|
|
5
|
+
res[key.to_s] = val.to_s
|
6
|
+
res
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.sanitize_contract_hash(hash)
|
11
|
+
hash.reduce({}) do |res, (key, val)|
|
12
|
+
res[:"key_#{key}"] = key
|
13
|
+
res[:"val_#{val}"] = val
|
14
|
+
res
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.contract_sql_condition(hash)
|
19
|
+
hash.map do |key, value|
|
20
|
+
"key = :key_#{key} and value = :val_#{value}"
|
21
|
+
end.join(' and ')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Grut
|
2
|
+
module Concerns
|
3
|
+
module DBTables
|
4
|
+
private
|
5
|
+
|
6
|
+
def roles_table
|
7
|
+
@roles_table ||= Grut::Config.instance.db_tables[:roles]
|
8
|
+
end
|
9
|
+
|
10
|
+
def permissions_table
|
11
|
+
@permissions_table ||= Grut::Config.instance.db_tables[:permissions]
|
12
|
+
end
|
13
|
+
|
14
|
+
def permission_params_table
|
15
|
+
@permission_params_table ||= Grut::Config.instance.db_tables[:permission_params]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/grut/config.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Grut
|
4
|
+
class Config
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
attr_accessor :db_url
|
8
|
+
|
9
|
+
def db_tables
|
10
|
+
@tables ||= {
|
11
|
+
roles: :grut_roles,
|
12
|
+
permissions: :grut_permissions,
|
13
|
+
permission_params: :grut_permission_params
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/grut/db.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
class DB
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
def self.conn
|
8
|
+
instance.conn
|
9
|
+
end
|
10
|
+
|
11
|
+
def conn
|
12
|
+
@conn ||= Sequel.connect(db_url)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def db_url
|
18
|
+
url = Grut::Config.instance.db_url
|
19
|
+
fail 'Database connection is not configured' unless url
|
20
|
+
url
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module Grut
|
2
|
+
class Guardian
|
3
|
+
include Concerns::DBTables
|
4
|
+
|
5
|
+
def initialize(user, role)
|
6
|
+
@user = user
|
7
|
+
@role = role.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
def permit(permission, params = {})
|
11
|
+
params = Asset.stringify_hash(params)
|
12
|
+
permission = permission.to_s
|
13
|
+
|
14
|
+
return false if role_exists?(permission, params)
|
15
|
+
permit_role_with_params(permission, params)
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def forbid(permission, params = {})
|
20
|
+
params = Asset.stringify_hash(params)
|
21
|
+
permission = permission.to_s
|
22
|
+
|
23
|
+
forbit_role_with_params(permission, params)
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def permitted?(permission, params = {})
|
28
|
+
params = Asset.stringify_hash(params)
|
29
|
+
permission = permission.to_s
|
30
|
+
|
31
|
+
role_exists?(permission, params)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def role_exists?(permission, params)
|
37
|
+
params_conditions = Asset.contract_sql_condition(params)
|
38
|
+
params = Asset.sanitize_contract_hash(params)
|
39
|
+
select = DB.conn[<<-SQL, params.merge(user_id: @user.id, role: @role, permission: permission)]
|
40
|
+
select 1 from #{roles_table} r
|
41
|
+
join #{permissions_table} p on p.role_id = r.id and (p.name = :permission or p.name = 'manage')
|
42
|
+
join #{permission_params_table} pp on pp.permission_id = p.id and (
|
43
|
+
(#{params_conditions}) or (key = 'all' and value = 'true')
|
44
|
+
)
|
45
|
+
where r.user_id = :user_id and r.name = :role and (
|
46
|
+
p.name = :permission or (p.name = 'manage' and pp.key = 'all' and pp.value = 'true')
|
47
|
+
)
|
48
|
+
SQL
|
49
|
+
select.count > 0
|
50
|
+
end
|
51
|
+
|
52
|
+
def permit_role_with_params(permission_name, params)
|
53
|
+
DB.conn.transaction do
|
54
|
+
role = find_or_create(_Role, user_id: @user.id, name: @role)
|
55
|
+
break if role_manages_all?(role[:id])
|
56
|
+
permission = find_or_create(_Permission, role_id: role[:id], name: permission_name)
|
57
|
+
if params['all'] == 'true'
|
58
|
+
_PermissionParam.where(permission_id: permission[:id]).delete
|
59
|
+
find_or_create(_PermissionParam, permission_id: permission[:id], key: 'all', value: 'true')
|
60
|
+
else
|
61
|
+
params.each do |key, value|
|
62
|
+
find_or_create(_PermissionParam, permission_id: permission[:id], key: key, value: value)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def forbit_role_with_params(permission_name, params)
|
69
|
+
role = _Role[user_id: @user.id] || {}
|
70
|
+
permission = _Permission[role_id: role[:id], name: permission_name] || {}
|
71
|
+
is_all = params['all'] == 'true'
|
72
|
+
permission_params = is_all ? [] : (params.map do |key, val|
|
73
|
+
_PermissionParam[permission_id: permission[:id], key: key, value: val]
|
74
|
+
end.compact)
|
75
|
+
DB.conn.transaction do
|
76
|
+
if is_all
|
77
|
+
_PermissionParam.where(permission_id: permission[:id]).delete
|
78
|
+
else
|
79
|
+
_PermissionParam.where(id: permission_params.map { |pp| pp[:id] }).delete
|
80
|
+
end
|
81
|
+
_Permission.where(id: permission[:id]).delete if _PermissionParam.count(permission_id: permission[:id]) == 0
|
82
|
+
_Role.where(id: role[:id]).delete if _Permission.count(role_id: role[:id]) == 0
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def find_or_create(entity, params)
|
87
|
+
entity[params] || entity[id: entity.insert(params)]
|
88
|
+
end
|
89
|
+
|
90
|
+
def role_manages_all?(role_id)
|
91
|
+
permission = _Permission[name: 'manage', role_id: role_id]
|
92
|
+
return false unless permission
|
93
|
+
_PermissionParam[key: 'all', value: 'true', permission_id: permission[:id]] != nil
|
94
|
+
end
|
95
|
+
|
96
|
+
def _Role
|
97
|
+
@_Role ||= DB.conn[roles_table]
|
98
|
+
end
|
99
|
+
|
100
|
+
def _Permission
|
101
|
+
@_Permission ||= DB.conn[permissions_table]
|
102
|
+
end
|
103
|
+
|
104
|
+
def _PermissionParam
|
105
|
+
@_PermissionParam ||= DB.conn[permission_params_table]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Grut
|
2
|
+
class Statement
|
3
|
+
include Concerns::DBTables
|
4
|
+
|
5
|
+
Entry = Struct.new(:role, :permission, :contract_key, :contract_value) do
|
6
|
+
def self.from_hash(hash)
|
7
|
+
new(*hash.values_at(:role, :permission, :contract_key, :contract_value))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(user)
|
12
|
+
@user = user
|
13
|
+
end
|
14
|
+
|
15
|
+
def all(role: nil, permission: nil, contract: {})
|
16
|
+
permission = permission.to_s if permission
|
17
|
+
role = role.to_s if role
|
18
|
+
contract = Asset.stringify_hash(contract)
|
19
|
+
|
20
|
+
permission_condition = permission ? 'and p.name = :permission' : ''
|
21
|
+
role_condition = role ? 'and r.name = :role' : ''
|
22
|
+
contract_condition = contract.any? ? "and #{Asset.contract_sql_condition(contract)}" : ''
|
23
|
+
|
24
|
+
args = Asset.sanitize_contract_hash(contract).merge(user_id: @user.id, role: role, permission: permission)
|
25
|
+
DB.conn[<<-SQL, args].map { |args| Entry.from_hash(args) }
|
26
|
+
select r.name as role, p.name as permission, pp.key as contract_key, pp.value as contract_value from #{roles_table} r
|
27
|
+
join #{permissions_table} p on p.role_id = r.id #{permission_condition}
|
28
|
+
join #{permission_params_table} pp on pp.permission_id = p.id #{contract_condition}
|
29
|
+
where r.user_id = :user_id #{role_condition}
|
30
|
+
SQL
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/grut/version.rb
ADDED
data/lib/tasks/grut.rake
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
namespace :grut do
|
2
|
+
task :config do
|
3
|
+
require 'yaml'
|
4
|
+
Grut::Config.instance.db_url ||= YAML.load_file('config/grut_database.yml')
|
5
|
+
end
|
6
|
+
|
7
|
+
desc 'Create necessary tables in the DB, specified by a config'
|
8
|
+
task :install => :config do
|
9
|
+
DB.conn.create_table Grut::Config.instance.db_tables[:roles] do
|
10
|
+
primary_key :id
|
11
|
+
Integer :user_id, null: false
|
12
|
+
String :name, null: false
|
13
|
+
index [:user_id, :name], unique: true, name: :grut_uniq_name_on_user_id_index
|
14
|
+
end
|
15
|
+
|
16
|
+
DB.conn.create_table Grut::Config.instance.db_tables[:permissions] do
|
17
|
+
primary_key :id
|
18
|
+
foreign_key :role_id, Grut::Config.instance.db_tables[:roles], null: false
|
19
|
+
String :name, null: false
|
20
|
+
index [:role_id, :name], unique: true, name: :grut_uniq_name_on_role_id_index
|
21
|
+
end
|
22
|
+
|
23
|
+
DB.conn.create_table Grut::Config.instance.db_tables[:permission_params] do
|
24
|
+
primary_key :id
|
25
|
+
foreign_key :permission_id, Grut::Config.instance.db_tables[:permissions], null: false
|
26
|
+
String :key, index: true, null: false
|
27
|
+
String :value, index: true, null: false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Deletes all created tables in the DB'
|
32
|
+
task :remove => :config do
|
33
|
+
DB.conn.run(<<-SQL)
|
34
|
+
drop table if exists #{Grut::Config.instance.db_tables[:permission_params]};
|
35
|
+
drop table if exists #{Grut::Config.instance.db_tables[:permissions]};
|
36
|
+
drop table if exists #{Grut::Config.instance.db_tables[:roles]};
|
37
|
+
SQL
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grut
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrey Koleshko
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-28 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: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pg
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sequel
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: "\n Thi is an authorization system for a Ruby
|
98
|
+
(including Rails) project,\n that allows to specify dynamic
|
99
|
+
permissions. All data is stored\n in an SQL database, supported
|
100
|
+
by Sequel.\n "
|
101
|
+
email:
|
102
|
+
- ka8725@gmail.com
|
103
|
+
executables: []
|
104
|
+
extensions: []
|
105
|
+
extra_rdoc_files: []
|
106
|
+
files:
|
107
|
+
- ".gitignore"
|
108
|
+
- ".rubocop.yml"
|
109
|
+
- ".travis.yml"
|
110
|
+
- CODE_OF_CONDUCT.md
|
111
|
+
- Gemfile
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- grut.gemspec
|
116
|
+
- lib/grut.rb
|
117
|
+
- lib/grut/asset.rb
|
118
|
+
- lib/grut/concerns/db_tables.rb
|
119
|
+
- lib/grut/config.rb
|
120
|
+
- lib/grut/db.rb
|
121
|
+
- lib/grut/guardian.rb
|
122
|
+
- lib/grut/statement.rb
|
123
|
+
- lib/grut/version.rb
|
124
|
+
- lib/tasks/grut.rake
|
125
|
+
homepage: ''
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.5.1
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: Flexible authorization solution.
|
149
|
+
test_files: []
|