rokku 0.6.2 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ab320b2b11ae398d36a715e8895ffc3e471c2c8b2d02ec930ecdb17c96ca91d
4
- data.tar.gz: ff14c12f1609d2d5f9522face2487eb4141547661dc3a068881b21f42827f157
3
+ metadata.gz: de9fd9e92bfea55153e2a5cc08a19f6c9f1e6a6e8955ff5f6949cbe3bf689bb2
4
+ data.tar.gz: be746224f675cdbe8bbc2058ab7d1fcf1c18c9d04a9a5ef2557060ed3fdfcad5
5
5
  SHA512:
6
- metadata.gz: d189c151d7264efc138a39234b06a2bccd34e46d65576b284768f1d3636e69ea43995fb8916ec3a7560cef661d210b5023366452caa361f9895857d9d80c2c2f
7
- data.tar.gz: 15b6d68bae30e7a590aa8db35944e741780f9a47203111a3484a61b405fb8eb925638304d9158c2f6740958a08e57cb4d1baf5ccbdb3eb5e2e6373fc8b77f4a4
6
+ metadata.gz: f1f9f9c33fa1b2c888380a4034eaa3473d25d7b30cbc55c9bbd627bcbcedbdb8af5d7ae63e6fa4e4429f6854cd22315eedff9dce7ff7b5f5caee910c5846ae8f
7
+ data.tar.gz: 0ad532c9440192d8a6a804a6a9d367674a85770cb286a3d343f09fa84f84747396a95c1f92d5cb9a663db3c8d1187cd15b1100ffb85a150340f93ee588a63de3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rokku (0.6.2)
4
+ rokku (0.7.0)
5
5
  hanami-controller (~> 1.0)
6
6
  hanami-router (~> 1.0)
7
7
 
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
- class #{controller}Policy
56
- def initialize(roles)
57
- @user_roles = roles
58
- # Uncomment the required roles and add the
59
- # appropriate user role to the @authorized_roles* array.
60
- # @authorized_roles_for_new = []
61
- # @authorized_roles_for_create = []
62
- # @authorized_roles_for_show = []
63
- # @authorized_roles_for_index = []
64
- # @authorized_roles_for_edit = []
65
- # @authorized_roles_for_update = []
66
- # @authorized_roles_for_destroy = []
67
- end
68
-
69
- def new?
70
- (@authorized_roles_for_new & @user_roles).any?
71
- end
72
-
73
- def create?
74
- (@authorized_roles_for_create & @user_roles).any?
75
- end
76
-
77
- def show?
78
- (@authorized_roles_for_show & @user_roles).any?
79
- end
80
-
81
- def index?
82
- (@authorized_roles_for_index & @user_roles).any?
83
- end
84
-
85
- def edit?
86
- (@authorized_roles_for_edit & @user_roles).any?
87
- end
88
-
89
- def update?
90
- (@authorized_roles_for_update & @user_roles).any?
91
- end
92
-
93
- def destroy?
94
- (@authorized_roles_for_destroy & @user_roles).any?
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
@@ -1,3 +1,3 @@
1
1
  module Rokku
2
- VERSION = "0.6.2"
2
+ VERSION = "0.7.0"
3
3
  end
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 + "Policy").new(roles).send("#{action.downcase}?")
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.6.2
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: 2021-11-14 00:00:00.000000000 Z
11
+ date: 2022-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler