rokku 0.6.2 → 0.7.0
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/lib/rokku/commands/commands.rb +47 -45
- data/lib/rokku/version.rb +1 -1
- data/lib/rokku.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de9fd9e92bfea55153e2a5cc08a19f6c9f1e6a6e8955ff5f6949cbe3bf689bb2
|
4
|
+
data.tar.gz: be746224f675cdbe8bbc2058ab7d1fcf1c18c9d04a9a5ef2557060ed3fdfcad5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1f9f9c33fa1b2c888380a4034eaa3473d25d7b30cbc55c9bbd627bcbcedbdb8af5d7ae63e6fa4e4429f6854cd22315eedff9dce7ff7b5f5caee910c5846ae8f
|
7
|
+
data.tar.gz: 0ad532c9440192d8a6a804a6a9d367674a85770cb286a3d343f09fa84f84747396a95c1f92d5cb9a663db3c8d1187cd15b1100ffb85a150340f93ee588a63de3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -39,7 +39,7 @@ end
|
|
39
39
|
### Role based authorization
|
40
40
|
|
41
41
|
#### Prerequisites
|
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`.
|
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
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']`.
|
44
44
|
|
45
45
|
```ruby
|
@@ -61,14 +61,22 @@ For example:
|
|
61
61
|
@authorized_roles_for_update = ['admin']
|
62
62
|
```
|
63
63
|
|
64
|
-
Then we can check if a user is authorized for the `Post` controller and `Update`action.
|
64
|
+
Then we can check if a user is authorized for the `mightyPoster` application, `Post` controller and `Update`action.
|
65
65
|
|
66
66
|
```ruby
|
67
|
-
authorized?("post", "update")
|
67
|
+
authorized?("mightyposter", "post", "update")
|
68
68
|
```
|
69
69
|
|
70
|
+
A complete example of using Rokku in a Hanami 1.3 applications is available [here](https://sebastjan-hribar.github.io/programming/2022/01/08/rokku-with-hanami.html).
|
71
|
+
|
72
|
+
|
70
73
|
### Changelog
|
71
74
|
|
75
|
+
#### 0.7.0
|
76
|
+
|
77
|
+
* Policies are now scoped under application module so it is possible to have two `Dashboard` policies for two different applications.
|
78
|
+
* Readme update.
|
79
|
+
|
72
80
|
#### 0.6.0
|
73
81
|
|
74
82
|
* Change to accept a string or an array as roles.
|
@@ -49,57 +49,59 @@ module Commands
|
|
49
49
|
# Uncomment the needed actions and define appropriate user roles.
|
50
50
|
|
51
51
|
def self.generate_policy(app_name, controller_name)
|
52
|
-
app_name = app_name
|
52
|
+
app_name = app_name.downcase.capitalize
|
53
53
|
controller = controller_name.downcase.capitalize
|
54
54
|
policy_txt = <<-TXT
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
55
|
+
module #{app_name}
|
56
|
+
class #{controller}Policy
|
57
|
+
def initialize(roles)
|
58
|
+
@user_roles = roles
|
59
|
+
# Uncomment the required roles and add the
|
60
|
+
# appropriate user role to the @authorized_roles* array.
|
61
|
+
# @authorized_roles_for_new = []
|
62
|
+
# @authorized_roles_for_create = []
|
63
|
+
# @authorized_roles_for_show = []
|
64
|
+
# @authorized_roles_for_index = []
|
65
|
+
# @authorized_roles_for_edit = []
|
66
|
+
# @authorized_roles_for_update = []
|
67
|
+
# @authorized_roles_for_destroy = []
|
68
|
+
end
|
69
|
+
|
70
|
+
def new?
|
71
|
+
(@authorized_roles_for_new & @user_roles).any?
|
72
|
+
end
|
73
|
+
|
74
|
+
def create?
|
75
|
+
(@authorized_roles_for_create & @user_roles).any?
|
76
|
+
end
|
77
|
+
|
78
|
+
def show?
|
79
|
+
(@authorized_roles_for_show & @user_roles).any?
|
80
|
+
end
|
81
|
+
|
82
|
+
def index?
|
83
|
+
(@authorized_roles_for_index & @user_roles).any?
|
84
|
+
end
|
85
|
+
|
86
|
+
def edit?
|
87
|
+
(@authorized_roles_for_edit & @user_roles).any?
|
88
|
+
end
|
89
|
+
|
90
|
+
def update?
|
91
|
+
(@authorized_roles_for_update & @user_roles).any?
|
92
|
+
end
|
93
|
+
|
94
|
+
def destroy?
|
95
|
+
(@authorized_roles_for_destroy & @user_roles).any?
|
96
|
+
end
|
95
97
|
end
|
96
98
|
end
|
97
99
|
TXT
|
98
100
|
|
99
|
-
FileUtils.mkdir_p "lib/#{app_name}/policies" unless File.directory?("lib/#{app_name}/policies")
|
100
|
-
unless File.file?("lib/#{app_name}/policies/#{controller}Policy.rb")
|
101
|
-
File.open("lib/#{app_name}/policies/#{controller}Policy.rb", 'w') { |file| file.write(policy_txt) }
|
101
|
+
FileUtils.mkdir_p "lib/#{app_name.downcase}/policies" unless File.directory?("lib/#{app_name.downcase}/policies")
|
102
|
+
unless File.file?("lib/#{app_name.downcase}/policies/#{controller}Policy.rb")
|
103
|
+
File.open("lib/#{app_name.downcase}/policies/#{controller}Policy.rb", 'w') { |file| file.write(policy_txt) }
|
102
104
|
end
|
103
|
-
puts("Generated policy: lib/#{app_name}/policies/#{controller}Policy.rb") if File.file?("lib/#{app_name}/policies/#{controller}Policy.rb")
|
105
|
+
puts("Generated policy: lib/#{app_name.downcase}/policies/#{controller}Policy.rb") if File.file?("lib/#{app_name.downcase}/policies/#{controller}Policy.rb")
|
104
106
|
end
|
105
107
|
end
|
data/lib/rokku/version.rb
CHANGED
data/lib/rokku.rb
CHANGED
@@ -12,7 +12,7 @@ module Hanami
|
|
12
12
|
#
|
13
13
|
# Example: redirect_to "/" unless authorized?("post", create")
|
14
14
|
|
15
|
-
def authorized?(controller, action)
|
15
|
+
def authorized?(application, controller, action)
|
16
16
|
input_roles = @user.roles
|
17
17
|
roles = []
|
18
18
|
if input_roles.class == String
|
@@ -20,7 +20,7 @@ module Hanami
|
|
20
20
|
else
|
21
21
|
roles = input_roles
|
22
22
|
end
|
23
|
-
Object.const_get(controller.downcase.capitalize
|
23
|
+
Object.const_get("#{application}::#{controller.downcase.capitalize}Policy").new(roles).send("#{action.downcase}?")
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
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.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastjan Hribar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|