destiny-role 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 +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +28 -0
- data/destiny.gemspec +23 -0
- data/lib/destiny-role.rb +6 -0
- data/lib/destiny/controller.rb +9 -0
- data/lib/destiny/role.rb +21 -0
- data/lib/destiny/user.rb +36 -0
- data/lib/destiny/version.rb +3 -0
- metadata +69 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 040aaa5de6175f7bdfb615b959f073c2e290e4dc
|
|
4
|
+
data.tar.gz: 8e37419de88c676ce4793831ca0399f76ebb4cf0
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b8bdace9971a17da79588a33e127d36d4d83c0da64f3141a63b56ffa7e3924e7b836c83afd4d95ef769d79701968e6903e68408513744ba06927f89af9d810c2
|
|
7
|
+
data.tar.gz: dfd88d85acc82e1a1ecad3fb427c0ca276544ca750d14bff99f50f9944e81ff24fd840683def71334419bd4866b18602a522cdeccdbcbc8ff7392e4e2785590c
|
data/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.gem
|
data/.ruby-gemset
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
destiny
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.4.0
|
data/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Destiny
|
|
2
|
+
Simple role managment system
|
|
3
|
+
|
|
4
|
+
## Concepts
|
|
5
|
+
|
|
6
|
+
Developer should be able to check permission of a user to perform an action.
|
|
7
|
+
Grant is an opportunity to make a particular action with some class of objects. Role is an aggregation of grants.
|
|
8
|
+
Roles persisted in the database.
|
|
9
|
+
Any number of roles may be assigned to user.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
### Gem
|
|
14
|
+
In the command line
|
|
15
|
+
```
|
|
16
|
+
gem install destiny-role
|
|
17
|
+
```
|
|
18
|
+
or in your Gemfile
|
|
19
|
+
```
|
|
20
|
+
gem 'destiny-role'
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Assumptions
|
|
24
|
+
|
|
25
|
+
1. Your app has a user model called 'User'
|
|
26
|
+
2. App's controller should have (integration purpose only)
|
|
27
|
+
* 'current_user' method returning instance of a user model
|
|
28
|
+
* 'access_denied' method which contains response logic in this case
|
data/destiny.gemspec
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
['../lib'].map{ |dir| File.expand_path(dir, __FILE__) }.each do |path|
|
|
2
|
+
$:.unshift(path) unless $:.include?(path)
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
require 'destiny/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = 'destiny-role'
|
|
9
|
+
spec.version = Destiny::VERSION
|
|
10
|
+
spec.authors = ['Pavel Zhukov']
|
|
11
|
+
spec.email = ['pasha.zhukov@gmail.com']
|
|
12
|
+
|
|
13
|
+
spec.summary = %q{Simple role managment system}
|
|
14
|
+
spec.description = %q{Roles persisted in the database. Role is as a composition of grants. Roles may be assigned to user.}
|
|
15
|
+
# spec.homepage = 'https://github.com/etxzay/destiny'
|
|
16
|
+
spec.license = 'MIT'
|
|
17
|
+
|
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
19
|
+
spec.require_paths = ['lib']
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
|
22
|
+
# spec.add_development_dependency 'rake', '~> 12.0'
|
|
23
|
+
end
|
data/lib/destiny-role.rb
ADDED
data/lib/destiny/role.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Destiny
|
|
2
|
+
module Role
|
|
3
|
+
|
|
4
|
+
def to_hash
|
|
5
|
+
data.to_hash
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def grant(section_name, privilege)
|
|
9
|
+
data[section_name] ||= {}
|
|
10
|
+
data[section_name][privilege] = true
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def revoke(section_name, privilege)
|
|
14
|
+
if data.key? section_name
|
|
15
|
+
data[section_name].delete(privilege) if data[section_name].key? privilege
|
|
16
|
+
data.delete(section_name) if data[section_name].empty?
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/destiny/user.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Destiny
|
|
2
|
+
module User
|
|
3
|
+
|
|
4
|
+
def permitted?(*privileges)
|
|
5
|
+
return true if is_admin?
|
|
6
|
+
|
|
7
|
+
begin
|
|
8
|
+
permitted = role_hash.dig(*privileges)
|
|
9
|
+
permitted = false unless !!permitted == permitted
|
|
10
|
+
rescue Exception => e
|
|
11
|
+
permitted = false
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
permitted
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def owner?(obj)
|
|
18
|
+
return id == obj.user_id if obj.respond_to? :user_id
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def role_hash
|
|
22
|
+
@role_hash = {}
|
|
23
|
+
roles.map(&:to_hash).each_entry { |h| @role_hash.deep_merge!(h) }
|
|
24
|
+
@role_hash.with_indifferent_access
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def admin?
|
|
28
|
+
return true if role_hash.try(:[], 'system').try(:[], 'administrator')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def has_role?(role_name)
|
|
32
|
+
roles.pluck(:name).count(role_name.to_s) > 0
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: destiny-role
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Pavel Zhukov
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-06-18 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.13'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.13'
|
|
27
|
+
description: Roles persisted in the database. Role is as a composition of grants.
|
|
28
|
+
Roles may be assigned to user.
|
|
29
|
+
email:
|
|
30
|
+
- pasha.zhukov@gmail.com
|
|
31
|
+
executables: []
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- ".gitignore"
|
|
36
|
+
- ".ruby-gemset"
|
|
37
|
+
- ".ruby-version"
|
|
38
|
+
- README.md
|
|
39
|
+
- destiny.gemspec
|
|
40
|
+
- lib/destiny-role.rb
|
|
41
|
+
- lib/destiny/controller.rb
|
|
42
|
+
- lib/destiny/role.rb
|
|
43
|
+
- lib/destiny/user.rb
|
|
44
|
+
- lib/destiny/version.rb
|
|
45
|
+
homepage:
|
|
46
|
+
licenses:
|
|
47
|
+
- MIT
|
|
48
|
+
metadata: {}
|
|
49
|
+
post_install_message:
|
|
50
|
+
rdoc_options: []
|
|
51
|
+
require_paths:
|
|
52
|
+
- lib
|
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '0'
|
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
requirements: []
|
|
64
|
+
rubyforge_project:
|
|
65
|
+
rubygems_version: 2.6.14
|
|
66
|
+
signing_key:
|
|
67
|
+
specification_version: 4
|
|
68
|
+
summary: Simple role managment system
|
|
69
|
+
test_files: []
|