rokku 0.5.1 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +11 -3
- data/bin/rokku +3 -1
- data/lib/rokku/policy_generator/policy_generator.rb +17 -10
- data/lib/rokku/version.rb +1 -1
- data/lib/rokku.rb +9 -4
- data/rokku.gemspec +2 -2
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef755f5416d8d351785de2667a34bde091cf9b35cc2ca20e746e80e62f386c04
|
4
|
+
data.tar.gz: 2b524925c173365bf2f86e35974133d9c962c9ccbe77a644ec737cfdc94c5438
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1da0f987473547a309b413a49f5d46ca052522cfcb7ac7bcd4f0d1da734b2c97b5286eca7a05d22ff458dca7c4ba64df7cdbfed3a4b7bcbf6bd1593e15e923aa
|
7
|
+
data.tar.gz: 3579382deada79aef43b317aa7a4f09a54d9f71ef0cc17f7e40e47f2df2232ed725bc344e459e8d859e99a568af178dda5e008141dfa34e8e45fe0d46fce076a
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Rokku
|
2
2
|
|
3
|
-
[![Join the chat at https://gitter.im/sebastjan-hribar/rokku](https://badges.gitter.im/sebastjan-hribar/rokku.svg)](https://gitter.im/sebastjan-hribar/rokku?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Gem Version](https://badge.fury.io/rb/rokku.svg)](https://badge.fury.io/rb/rokku)
|
3
|
+
[![Join the chat at https://gitter.im/sebastjan-hribar/rokku](https://badges.gitter.im/sebastjan-hribar/rokku.svg)](https://gitter.im/sebastjan-hribar/rokku?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Gem Version](https://badge.fury.io/rb/rokku.svg)](https://badge.fury.io/rb/rokku)
|
4
4
|
|
5
5
|
Rokku (ロック - lock) offers authorization for [Hanami web applications](http://hanamirb.org/).
|
6
6
|
|
@@ -39,7 +39,8 @@ end
|
|
39
39
|
### Role based authorization
|
40
40
|
|
41
41
|
#### Prerequisites
|
42
|
-
The current user must be stored in the `@user` variable
|
42
|
+
The current user must be stored in the `@user` variable and must have the attribute of `roles`. Rokku supports `roles`both as a type of `Array` and `String`.
|
43
|
+
For example, the `@user.roles` could either be a simple string like 'admin' or an array of roles like `['level_1', 'level_2', 'level_3']`.
|
43
44
|
|
44
45
|
```ruby
|
45
46
|
rokku -n mightyPoster -p post
|
@@ -60,7 +61,7 @@ For example:
|
|
60
61
|
@authorized_roles_for_update = ['admin']
|
61
62
|
```
|
62
63
|
|
63
|
-
Then we can check if a user is authorized
|
64
|
+
Then we can check if a user is authorized for the `Post` controller and `Update`action.
|
64
65
|
|
65
66
|
```ruby
|
66
67
|
authorized?("post", "update")
|
@@ -68,6 +69,13 @@ authorized?("post", "update")
|
|
68
69
|
|
69
70
|
### Changelog
|
70
71
|
|
72
|
+
#### 0.6.0
|
73
|
+
|
74
|
+
* Change to accept a string or an array as roles.
|
75
|
+
* Refactored tests.
|
76
|
+
* Added `commands.rb`to `bin/rokku`.
|
77
|
+
* Small style changes.
|
78
|
+
|
71
79
|
#### 0.5.1
|
72
80
|
|
73
81
|
* Readme update
|
data/bin/rokku
CHANGED
@@ -9,15 +9,15 @@ module Hanami
|
|
9
9
|
# The generate_policy method creates the policy file for specified
|
10
10
|
# application and controller. By default all actions to check against
|
11
11
|
# are commented out.
|
12
|
-
# Uncomment the needed actions and define appropriate user
|
12
|
+
# Uncomment the needed actions and define appropriate user roles.
|
13
13
|
|
14
14
|
def generate_policy(app_name, controller_name)
|
15
15
|
app_name = app_name
|
16
16
|
controller = controller_name.downcase.capitalize
|
17
17
|
policy_txt = <<-TXT
|
18
18
|
class #{controller}Policy
|
19
|
-
def initialize(
|
20
|
-
@
|
19
|
+
def initialize(roles)
|
20
|
+
@user_roles = roles
|
21
21
|
# Uncomment the required roles and add the
|
22
22
|
# appropriate user role to the @authorized_roles* array.
|
23
23
|
# @authorized_roles_for_new = []
|
@@ -28,26 +28,33 @@ def generate_policy(app_name, controller_name)
|
|
28
28
|
# @authorized_roles_for_update = []
|
29
29
|
# @authorized_roles_for_destroy = []
|
30
30
|
end
|
31
|
+
|
31
32
|
def new?
|
32
|
-
@authorized_roles_for_new.
|
33
|
+
(@authorized_roles_for_new & @user_roles).any?
|
33
34
|
end
|
35
|
+
|
34
36
|
def create?
|
35
|
-
@authorized_roles_for_create.
|
37
|
+
(@authorized_roles_for_create & @user_roles).any?
|
36
38
|
end
|
39
|
+
|
37
40
|
def show?
|
38
|
-
@authorized_roles_for_show.
|
41
|
+
(@authorized_roles_for_show & @user_roles).any?
|
39
42
|
end
|
43
|
+
|
40
44
|
def index?
|
41
|
-
@authorized_roles_for_index.
|
45
|
+
(@authorized_roles_for_index & @user_roles).any?
|
42
46
|
end
|
47
|
+
|
43
48
|
def edit?
|
44
|
-
@authorized_roles_for_edit.
|
49
|
+
(@authorized_roles_for_edit & @user_roles).any?
|
45
50
|
end
|
51
|
+
|
46
52
|
def update?
|
47
|
-
@authorized_roles_for_update.
|
53
|
+
(@authorized_roles_for_update & @user_roles).any?
|
48
54
|
end
|
55
|
+
|
49
56
|
def destroy?
|
50
|
-
@authorized_roles_for_destroy.
|
57
|
+
(@authorized_roles_for_destroy & @user_roles).any?
|
51
58
|
end
|
52
59
|
end
|
53
60
|
TXT
|
data/lib/rokku/version.rb
CHANGED
data/lib/rokku.rb
CHANGED
@@ -10,13 +10,18 @@ module Hanami
|
|
10
10
|
# and permission to access the action. It returns true or false and
|
11
11
|
# provides the basis for further actions in either case.
|
12
12
|
#
|
13
|
-
# Example: redirect_to "/" unless authorized?("post",
|
13
|
+
# Example: redirect_to "/" unless authorized?("post", create")
|
14
14
|
|
15
15
|
def authorized?(controller, action)
|
16
|
-
|
17
|
-
|
16
|
+
input_roles = @user.roles
|
17
|
+
roles = []
|
18
|
+
if input_roles.class == String
|
19
|
+
roles << input_roles
|
20
|
+
else
|
21
|
+
roles = input_roles
|
22
|
+
end
|
23
|
+
Object.const_get(controller.downcase.capitalize + "Policy").new(roles).send("#{action.downcase}?")
|
18
24
|
end
|
19
|
-
|
20
25
|
end
|
21
26
|
end
|
22
27
|
|
data/rokku.gemspec
CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
21
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
22
|
end
|
23
|
-
spec.bindir = "
|
24
|
-
spec.executables = spec.files.grep(%r{^
|
23
|
+
spec.bindir = "bin"
|
24
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 2.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rokku
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastjan Hribar
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -125,7 +125,10 @@ dependencies:
|
|
125
125
|
description:
|
126
126
|
email:
|
127
127
|
- sebastjan.hribar@gmail.com
|
128
|
-
executables:
|
128
|
+
executables:
|
129
|
+
- console
|
130
|
+
- rokku
|
131
|
+
- setup
|
129
132
|
extensions: []
|
130
133
|
extra_rdoc_files: []
|
131
134
|
files:
|