aserto-rails 0.20.1 → 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: dbb7151353f86f941690b382de5e1d5f81076db081262abeb7dbc55c45745c66
4
- data.tar.gz: a7aa53b6275c4613aa367b77c568c8641d9e55b5c1a5c0a2205a91eb72e29f71
3
+ metadata.gz: db5e72e6292b71ced35b0f37998cc46901356c44dfce224981a1196a0d978f0f
4
+ data.tar.gz: 72a97cb5107d799c1087636838d283b60ddd1092fcff6c9c06c5fe4cca9fe3ed
5
5
  SHA512:
6
- metadata.gz: 853876ec44491170671af35673e1b32b26f02c79ca6d8dfdc9c5ec4eac0074d7c7d62cfb99193583f5ca96790d1805fbe2a5e2873d043d571f8490a0117c7055
7
- data.tar.gz: fd7ca8c2b5250bddcc7314da3b114c35cb13166af2b73899c81174a748b1dad6c416a158f6ece38268ca7610702450a700c9e7dba1d170db80842e62c190e251
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.1
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.1
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: 2022-11-28 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,124 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.20.2
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.2
27
- - !ruby/object:Gem::Dependency
28
- name: appraisal
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.0'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 2.0.0
37
- type: :development
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '2.0'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 2.0.0
47
- - !ruby/object:Gem::Dependency
48
- name: bundler
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: 1.15.0
54
- - - "<"
55
- - !ruby/object:Gem::Version
56
- version: '3.0'
57
- type: :development
58
- prerelease: false
59
- version_requirements: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: 1.15.0
64
- - - "<"
65
- - !ruby/object:Gem::Version
66
- version: '3.0'
67
- - !ruby/object:Gem::Dependency
68
- name: codecov
69
- requirement: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - "~>"
72
- - !ruby/object:Gem::Version
73
- version: '0.6'
74
- type: :development
75
- prerelease: false
76
- version_requirements: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - "~>"
79
- - !ruby/object:Gem::Version
80
- version: '0.6'
81
- - !ruby/object:Gem::Dependency
82
- name: grpc_mock
83
- requirement: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - "~>"
86
- - !ruby/object:Gem::Version
87
- version: '0.4'
88
- type: :development
89
- prerelease: false
90
- version_requirements: !ruby/object:Gem::Requirement
91
- requirements:
92
- - - "~>"
93
- - !ruby/object:Gem::Version
94
- version: '0.4'
95
- - !ruby/object:Gem::Dependency
96
- name: rspec
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - "~>"
100
- - !ruby/object:Gem::Version
101
- version: '3.0'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - "~>"
107
- - !ruby/object:Gem::Version
108
- version: '3.0'
109
- - !ruby/object:Gem::Dependency
110
- name: rubocop-performance
111
- requirement: !ruby/object:Gem::Requirement
112
- requirements:
113
- - - "~>"
114
- - !ruby/object:Gem::Version
115
- version: '1.14'
116
- type: :development
117
- prerelease: false
118
- version_requirements: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - "~>"
121
- - !ruby/object:Gem::Version
122
- version: '1.14'
123
- - !ruby/object:Gem::Dependency
124
- name: rubocop-rspec
125
- requirement: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - "~>"
128
- - !ruby/object:Gem::Version
129
- version: '2.11'
130
- type: :development
131
- prerelease: false
132
- version_requirements: !ruby/object:Gem::Requirement
133
- requirements:
134
- - - "~>"
135
- - !ruby/object:Gem::Version
136
- version: '2.11'
26
+ version: 0.30.1
137
27
  description: Aserto authorization library for Ruby and Ruby on Rails
138
28
  email:
139
29
  - aserto@aserto.com
@@ -166,7 +56,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
56
  requirements:
167
57
  - - ">="
168
58
  - !ruby/object:Gem::Version
169
- version: 2.7.0
59
+ version: 3.0.0
170
60
  required_rubygems_version: !ruby/object:Gem::Requirement
171
61
  requirements:
172
62
  - - ">="