aserto-rails 0.20.2 → 0.30.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: c73023472e4a2c16c1d7f2d54302cfd533a63f592f2ca039c26ecdbc00945adc
4
- data.tar.gz: 5ba34c354dd5e34970da2e76114055eaf14b58a7e72507a6df63966fac7fcecd
3
+ metadata.gz: db5e72e6292b71ced35b0f37998cc46901356c44dfce224981a1196a0d978f0f
4
+ data.tar.gz: 72a97cb5107d799c1087636838d283b60ddd1092fcff6c9c06c5fe4cca9fe3ed
5
5
  SHA512:
6
- metadata.gz: b5883461dedf1448f933c1dbdc02d66d526e437c16e8696f70e5d7023cf03efe537674bbb32ce6a66420f26ee2609d7e100d0dc9a974909c56d6164ab47196b7
7
- data.tar.gz: 133daa61ff2ee17d32746948b14974f9bbb81a5119399fa8826a31034fdb8785fc5ec495dabbd904cce923d767db80f45465ec66f2ad509f851c7511008c3dba
6
+ metadata.gz: 30f24678897474717e27bc9120ce84a5535472efede444fa0054c48b403fd3ba3a4501f60824da2a126e560f94c245bbbda0b8a47bd34184f8d8cfa9358d9905
7
+ data.tar.gz: abd7814fc2cb926ed1e0f1e99b57f550e91c3cdc54f1b8b6ac0629cc67529d5c223e7647a432614ca82590bedf1550c91c313650e3c55fdee3587910b010ac18
data/README.md CHANGED
@@ -138,6 +138,8 @@ end
138
138
 
139
139
  ## Controller helpers
140
140
 
141
+ ### aserto_authorize!
142
+
141
143
  The `aserto_authorize!` method in the controller will raise an exception if the user is not able to perform the given action.
142
144
 
143
145
  ```ruby
@@ -167,6 +169,38 @@ class PostsController < ApplicationController
167
169
  end
168
170
  ```
169
171
 
172
+ ### check!
173
+
174
+ The `check!` method in the controller will raise an exception if the user is not able to perform the given action.
175
+
176
+ ```ruby
177
+ def show
178
+ # only users in the "evil_genius" group are allowed to get this resource
179
+ check!(object_id: "evil_genius", object_type: "group", relation: "member")
180
+ @post = Post.find(params[:id])
181
+ end
182
+ ```
183
+
184
+ Setting this for every action can be tedious, therefore the `aserto_check_resource` method is provided to
185
+ automatically authorize all actions in a RESTful style resource controller.
186
+ It will use a before action to load the resource into an instance variable and authorize it for every action.
187
+
188
+ ```ruby
189
+ class PostsController < ApplicationController
190
+ aserto_authorize_resource
191
+ # aserto_check_resource only: %i[show], params: { object_id: "evil_genius", object_type: "group", relation: "member" }
192
+ # aserto_check_resource except: %i[index], params: { object_id: "evil_genius", object_type: "group", relation: "member" }
193
+
194
+ def show
195
+ # getting a single post authorized
196
+ end
197
+
198
+ def index
199
+ # getting all posts is authorized
200
+ end
201
+ end
202
+ ```
203
+
170
204
  ## Check Permissions
171
205
 
172
206
  The current user's permissions can then be checked using the `allowed?`, `visible?` and `enabled?` methods in views and controllers.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.20.2
1
+ 0.30.0
@@ -8,6 +8,10 @@ module Aserto
8
8
  aserto_resource_class.add_before_action(self, :authorize_resource, *args)
9
9
  end
10
10
 
11
+ def aserto_check_resource(*args)
12
+ aserto_resource_class.add_before_action(self, :check_resource, *args)
13
+ end
14
+
11
15
  def aserto_resource_class
12
16
  ControllerResource
13
17
  end
@@ -38,6 +42,23 @@ module Aserto
38
42
  raise Aserto::AccessDenied unless Aserto::AuthClient.new(request).is
39
43
  end
40
44
 
45
+ #
46
+ # Authorization call based on check relation
47
+ #
48
+ # @param [String] object_id
49
+ # @param [String] object_type
50
+ # @param [String] relation
51
+ #
52
+ # @return [nil]
53
+ #
54
+ # @raise Aserto::AccessDenied
55
+ #
56
+ def check!(object_id:, object_type:, relation:)
57
+ raise Aserto::AccessDenied unless Aserto::AuthClient.new(request).check(
58
+ object_id: object_id, object_type: object_type, relation: relation
59
+ )
60
+ end
61
+
41
62
  private
42
63
 
43
64
  def augment_request!(action, path, resource)
@@ -10,6 +10,22 @@ module Aserto
10
10
  @name = args.first
11
11
  end
12
12
 
13
+ #
14
+ # Authorization call based on check relation
15
+ #
16
+ # @param [String] object_id
17
+ # @param [String] object_type
18
+ # @param [String] relation
19
+ #
20
+ # @return [nil]
21
+ #
22
+ # @raise Aserto::AccessDenied
23
+ #
24
+ def check_resource
25
+ client = Aserto::AuthClient.new(@controller.request)
26
+ raise Aserto::AccessDenied unless client.check(**(@options[:params] || {}))
27
+ end
28
+
13
29
  def authorize_resource
14
30
  raise Aserto::AccessDenied unless Aserto::AuthClient.new(@controller.request).is
15
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aserto-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.2
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aserto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-23 00:00:00.000000000 Z
11
+ date: 2023-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aserto
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.20.5
19
+ version: 0.30.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.20.5
26
+ version: 0.30.1
27
27
  description: Aserto authorization library for Ruby and Ruby on Rails
28
28
  email:
29
29
  - aserto@aserto.com