ez-permissions 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e66c7c3aaf11e53f4f1049546d344eef5ef7ef0c4ab2af0ffb8940d11a64afa1
4
- data.tar.gz: 6833c0293e997dd7d6f9f82d1c7794f1197f5167012254260b1d0f763e0bc32c
3
+ metadata.gz: 4b1bba0ec695b54e27b18035b6ca073f1a66810df48707479431fb3f31f0ff8c
4
+ data.tar.gz: 49278569109b575599eda90fc1afeb57490e368c8ece5442e0fc90a8eb02703b
5
5
  SHA512:
6
- metadata.gz: d99a291847509881c4d11c804fd1b92a9bfc62da9f28d4f802bfcc0d3b61fcd15dc6da4ad980ef6b2ee861b9c28806b09e194b7160b4e74a65a5d54716758977
7
- data.tar.gz: c20c12f67b68b8bac4f88402eeff521d06eb6e731c2811385ab20d64d9dc2f334003acc03ab512daf61cce6adcaef37ef8e58678747aff3e449e1518c3559e30
6
+ metadata.gz: d80747eeffaac6088373fa9fa56e78ae9351b4b9f2f708a5426344f64067bd4b4c717635482260051fb0d5004725fa535ed98074ee3e934217d9080a5d591c82
7
+ data.tar.gz: da7e1ced8d532ff27689e6b309858ad501ba3aee88edb35ec76e2af1ee72104b38b33240a6d2d47e93e8fed458434dbeac496ee9773f2601bf478595ffc2b6bd
data/README.md CHANGED
@@ -7,9 +7,9 @@
7
7
  **Ez Permissions** (read as "easy permissions") - one of the [ez-engines](https://github.com/ez-engines) collection that helps easily add permissions interface to your [Rails](http://rubyonrails.org/) application.
8
8
 
9
9
  - Most advanced RBAC model:
10
- - Flexible tool with simple DSL and confguration
10
+ - Flexible tool with simple DSL and configuration
11
11
  - All in one solution
12
- - Convetion over configuration principles.
12
+ - Convention over configuration principles.
13
13
  - Depends on [ez-core](https://github.com/ez-engines/ez-core)
14
14
 
15
15
  ## Installation
@@ -36,7 +36,7 @@ Ez::Permissions.configure do |config|
36
36
  config.models_roles_table_name = 'my_model_roles'
37
37
  config.permissions_roles_table_name = 'my_permissions_roles'
38
38
 
39
- # Suppress stdoud messages for test environment
39
+ # Suppress STDOUT messages for test environment
40
40
  config.mute_stdout = true if Rails.env.test?
41
41
 
42
42
  # Define your custom callbacks
@@ -61,7 +61,7 @@ rails generate ez:permissions:migrations
61
61
 
62
62
  ## DSL
63
63
 
64
- Simple DSL for difinition of permission relationships
64
+ Simple DSL for definition of permission relationships
65
65
  ```ruby
66
66
  Ez::Permissions::DSL.define do |setup|
67
67
  # You need add all resources of your application and possible actions
@@ -72,8 +72,8 @@ Ez::Permissions::DSL.define do |setup|
72
72
  setup.add :permissions, actions: %i[crud my_custom_action]
73
73
 
74
74
  # Actions option are not required. In such case you add all crud actions by default
75
- setup.add :users
76
- setup.add :projects
75
+ setup.add :users, group: :accounts # You can group resources
76
+ setup.add :projects # Resource without a group will get "others" group
77
77
  end
78
78
  ```
79
79
 
@@ -89,7 +89,7 @@ user = User.first
89
89
 
90
90
  # User model become permission model
91
91
  user.roles #=> [application level roles]
92
- user.assigned_roles #=> [user owned roles, gloabal and scoped]
92
+ user.assigned_roles #=> [user owned roles, global and scoped]
93
93
  user.permissions #=> [user available permissions through assigned_roles]
94
94
  ```
95
95
 
@@ -146,6 +146,10 @@ Permissions.includes_role?(user, :admin)
146
146
  # Check if user includes scoped role
147
147
  project = Project.first
148
148
  Permissions.includes_role?(user, :manager, scoped: project)
149
+
150
+ # List users with particular role in particular scope
151
+ project = Project.first
152
+ Permissions.list_by_role(:manager, scoped: project)
149
153
  ```
150
154
 
151
155
  ### Permissions
@@ -180,7 +184,7 @@ end
180
184
  # otherwise you will get an exception
181
185
  Ez::Permissions::NotAuthorized
182
186
 
183
- # Both .authrorize and .authorize! methods can be used without blocks.
187
+ # Both .authorize and .authorize! methods can be used without blocks.
184
188
 
185
189
  # if you don't want raise exception, just use
186
190
  Permissions.authorize(user, :create, :users) { puts 'Yeahh!' } #=> false
@@ -204,7 +208,7 @@ user_permissions.permissions_map # => { :read_users => true}
204
208
 
205
209
  # and the in your code just fetch by the key:
206
210
  if user_permissions.permissions_map[:read_users]
207
- # execute authrorized code
211
+ # execute authorized code
208
212
  end
209
213
 
210
214
  # or user #can? and #authorize! helper methods
@@ -217,7 +221,7 @@ user_permissions.authorize!(:create, :users) # => raise Ez::Permissions::NotAuth
217
221
  EzPermissions ships with bunch of RSpec helper methods that helps mock permission.
218
222
  For large test suite (more than 5000 specs) it saves up to 30% of test runs time.
219
223
 
220
- Add test helpers tou your rspec config
224
+ Add test helpers to your rspec config
221
225
  ```ruby
222
226
  require 'ez/permissions/rspec_helpers'
223
227
 
@@ -248,7 +252,7 @@ mock_model_role(:worker, user)
248
252
  mock_permission(:users, :create)
249
253
  ```
250
254
 
251
- ### Cleaup redundant permissions
255
+ ### Cleanup redundant permissions
252
256
  If you changed your permissions DSL and removed redundant resources and actions
253
257
 
254
258
  ```sh
@@ -256,7 +260,7 @@ rake ez:permissions:outdated # display list of outdated permissions
256
260
  rake ez:permissions:cleanup # remove outdated permissions from the DB
257
261
  ```
258
262
 
259
- ### Kepp it excplicit!
263
+ ### Keep it explicit!
260
264
  You can wonder, why we just not add authorization methods to user instance, like:
261
265
  ```ruby
262
266
  user.can?(:something)
@@ -270,7 +274,7 @@ Of course, you can use them as mixins, but it's up to you.
270
274
  - User can has role in scope of some resource (Project, Company, Business, etc.)
271
275
  - User can has role in global scope (without scope)
272
276
  - If user want access data in scope of resource - user must has assigned role scoped for this resource
273
- - If user want access data in global scope - user must has assigned role wihtout any scoped resorce (global role)
277
+ - If user want access data in global scope - user must has assigned role without any scoped resource (global role)
274
278
  - User with global role - can't access scoped resources.
275
279
  - User with scoped role - can't access global resources.
276
280
 
@@ -17,7 +17,7 @@ module Ez
17
17
 
18
18
  def authorize!(action_name, resource_name)
19
19
  permissions_map.fetch(to_key(action_name, resource_name))
20
- rescue KeyError => ex
20
+ rescue KeyError
21
21
  raise Ez::Permissions::NotAuthorizedError
22
22
  end
23
23
 
@@ -26,6 +26,15 @@ module Ez
26
26
  model_role(role, model, scoped) ? true : false
27
27
  end
28
28
 
29
+ def list_by_role(role_name, scoped: nil)
30
+ role = Ez::Permissions::API.get_role!(role_name)
31
+
32
+ Ez::Permissions::ModelRole.where(
33
+ role: role,
34
+ scoped: scoped
35
+ ).map(&:model)
36
+ end
37
+
29
38
  private
30
39
 
31
40
  def model_role(role, model, scoped)
@@ -42,7 +42,7 @@ module Ez
42
42
  return unless seed_to_db(resource)
43
43
 
44
44
  message(
45
- "Resource [#{name}] has been successfully registred with actions: [#{resource.actions.join(', ')}]",
45
+ "Resource [#{name}] has been successfully registered with actions: [#{resource.actions.join(', ')}]",
46
46
  'SUCCESS'
47
47
  )
48
48
  end
@@ -5,12 +5,14 @@ module Ez
5
5
  class Resource
6
6
  ACTIONS = %i[create read update delete].freeze
7
7
 
8
- attr_reader :name, :model, :actions
8
+ attr_reader :name, :model, :actions, :group, :label
9
9
 
10
10
  def initialize(name, options = {})
11
11
  @name = name
12
12
  @model = options.fetch(:model, nil)
13
13
  @actions = process_actions(options.fetch(:actions, []))
14
+ @group = options.fetch(:group, :others)
15
+ @label = options.fetch(:label, name.to_s.humanize)
14
16
  end
15
17
 
16
18
  def <=>(other)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ez
4
4
  module Permissions
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
@@ -7,8 +7,8 @@ namespace :ez do
7
7
  Ez::Permissions::Permission.find_each do |permission|
8
8
  next if Ez::Permissions::DSL.resource_action?(permission.resource, permission.action)
9
9
 
10
- STDOUT.puts "[WARNING] Ez::Permissions: \n"
11
- "Permission##{permission.id} [#{permission.resource} -> #{permission.action}] is redundant"
10
+ STDOUT.puts '[WARNING] Ez::Permissions:'\
11
+ "Permission##{permission.id} [#{permission.resource} -> #{permission.action}] is redundant"
12
12
  end
13
13
  end
14
14
 
@@ -17,8 +17,8 @@ namespace :ez do
17
17
  next if Ez::Permissions::DSL.resource_action?(permission.resource, permission.action)
18
18
 
19
19
  permission.destroy
20
- STDOUT.puts "[WARNING] Ez::Permissions: \n"
21
- "Permission##{permission.id} [#{permission.resource} -> #{permission.action}] is removed"
20
+ STDOUT.puts '[WARNING] Ez::Permissions:'\
21
+ "Permission##{permission.id} [#{permission.resource} -> #{permission.action}] is removed"
22
22
  end
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ez-permissions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volodya Sveredyuk
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-08 00:00:00.000000000 Z
11
+ date: 2020-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ez-core
@@ -193,7 +193,7 @@ licenses:
193
193
  - MIT
194
194
  metadata:
195
195
  allowed_push_host: https://rubygems.org
196
- post_install_message:
196
+ post_install_message:
197
197
  rdoc_options: []
198
198
  require_paths:
199
199
  - lib
@@ -201,15 +201,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
201
201
  requirements:
202
202
  - - ">="
203
203
  - !ruby/object:Gem::Version
204
- version: '0'
204
+ version: 2.4.0
205
205
  required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  requirements:
207
207
  - - ">="
208
208
  - !ruby/object:Gem::Version
209
209
  version: '0'
210
210
  requirements: []
211
- rubygems_version: 3.0.6
212
- signing_key:
211
+ rubygems_version: 3.1.2
212
+ signing_key:
213
213
  specification_version: 4
214
214
  summary: Easy permissions engine for Rails app.
215
215
  test_files: []