rokku 0.5.1 → 0.6.1

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: fa884cd59034be5f8dfdd5bb0edcb17855b8bc895db41904ace461e56516d762
4
- data.tar.gz: 1f45e1c95f9400de4667113b2069c2a42f453bf620ef089684fdeef4ff7ea5ec
3
+ metadata.gz: ef755f5416d8d351785de2667a34bde091cf9b35cc2ca20e746e80e62f386c04
4
+ data.tar.gz: 2b524925c173365bf2f86e35974133d9c962c9ccbe77a644ec737cfdc94c5438
5
5
  SHA512:
6
- metadata.gz: 01b0f07606231dc015998b92c5b44b9f4a64b7e8d676e8e9e41c2511701cd0168078912729118ca1d0af83897f1f053e311919cec39894f29280ace71277121a
7
- data.tar.gz: 7425475d5a25bc25a9ea05187e3d5dc32e19b601e25d91ce235aeb26ed4d7344331fa14847d2a29f98b0041eeb817e15eac89831ec3ae3f2d828bb99a8356289
6
+ metadata.gz: 1da0f987473547a309b413a49f5d46ca052522cfcb7ac7bcd4f0d1da734b2c97b5286eca7a05d22ff458dca7c4ba64df7cdbfed3a4b7bcbf6bd1593e15e923aa
7
+ data.tar.gz: 3579382deada79aef43b317aa7a4f09a54d9f71ef0cc17f7e40e47f2df2232ed725bc344e459e8d859e99a568af178dda5e008141dfa34e8e45fe0d46fce076a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rokku (0.5.1)
4
+ rokku (0.6.1)
5
5
  hanami-controller (~> 1.0)
6
6
  hanami-router (~> 1.0)
7
7
 
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) [![Build Status](https://travis-ci.org/sebastjan-hribar/rokku.svg?branch=master)](https://travis-ci.org/sebastjan-hribar/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
@@ -1,2 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require_relative "../lib/rokku/commands/commands.rb"
2
+ require_relative "../lib/rokku/commands/commands.rb"
3
+
4
+ commands.rb
@@ -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 role.
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(role)
20
- @user_role = role
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.include? @user_role
33
+ (@authorized_roles_for_new & @user_roles).any?
33
34
  end
35
+
34
36
  def create?
35
- @authorized_roles_for_create.include? @user_role
37
+ (@authorized_roles_for_create & @user_roles).any?
36
38
  end
39
+
37
40
  def show?
38
- @authorized_roles_for_show.include? @user_role
41
+ (@authorized_roles_for_show & @user_roles).any?
39
42
  end
43
+
40
44
  def index?
41
- @authorized_roles_for_index.include? @user_role
45
+ (@authorized_roles_for_index & @user_roles).any?
42
46
  end
47
+
43
48
  def edit?
44
- @authorized_roles_for_edit.include? @user_role
49
+ (@authorized_roles_for_edit & @user_roles).any?
45
50
  end
51
+
46
52
  def update?
47
- @authorized_roles_for_update.include? @user_role
53
+ (@authorized_roles_for_update & @user_roles).any?
48
54
  end
55
+
49
56
  def destroy?
50
- @authorized_roles_for_destroy.include? @user_role
57
+ (@authorized_roles_for_destroy & @user_roles).any?
51
58
  end
52
59
  end
53
60
  TXT
data/lib/rokku/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rokku
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.1"
3
3
  end
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", "admin", "create")
13
+ # Example: redirect_to "/" unless authorized?("post", create")
14
14
 
15
15
  def authorized?(controller, action)
16
- role = @user.role
17
- Object.const_get(controller.downcase.capitalize + "Policy").new(role).send("#{action.downcase}?")
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 = "exe"
24
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
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.5.1
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastjan Hribar
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-30 00:00:00.000000000 Z
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: