action_policy-graphql 0.5.0 → 0.5.1

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: b5ed86f1884fc8a9468ed78e7476afc81cf68af0f65a549df4e213f5ab50b53f
4
- data.tar.gz: 1991a6c3c2414a85bf3738cbdc600fda90d989a059f613200445d6b1d2c47c9e
3
+ metadata.gz: eb2f4793062ddef25c116e0591d97613174a3c39e18a62e7982f4a41d9f9afc1
4
+ data.tar.gz: 2e776a3a49781309094a4cee8d3824391913b57d5fcdef64edc6425eb476b280
5
5
  SHA512:
6
- metadata.gz: f7a9012c86bcaad3c1220a7f9621655f3ae3ecc7f314672bf58c3f60d09112aa9605f3c361259bc8a7fb39d147ca696409ca20bb6fe92cf88c0cf1bc8c90d5a0
7
- data.tar.gz: 967fa7b9dfc0638469744b810b0329f703eacebd6ba66f960448953b172476c183d1bda2e25841c61e963da6bbf8e091243fce0bb0c0409e3c3b53a38d1bc47b
6
+ metadata.gz: f02980395258ccf616d7508d24615d54162045e2f9abbea4cebcdd5d8976a19213f04ca8b0a7775fe99b03741ea91213dbe27e3e0994ae645e1656abb76212cd
7
+ data.tar.gz: 892b01138e996004cd1a218e06af56435f0f6cd662af14b295fa4162204da350d8a4fb2d192d014b30bd06f9f1e8798f580f272a203fbdbc75813e107463ac14
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.5.1 (2020-10-08)
6
+
7
+ - Fix mutations authorization (clean up around `authorize_mutation_raise_exception` configuration parameter). ([@rzaharenkov][])
8
+
9
+ - Add deprecation for using `authorize` for mutation fields. ([@rzaharenkov][])
10
+
5
11
  ## 0.5.0 (2020-10-07)
6
12
 
7
13
  - Add `preauthorize_mutation_raise_exception` configuration parameter. ([@palkan][])
data/README.md CHANGED
@@ -80,6 +80,8 @@ You can customize the authorization options, e.g. `authorize: {to: :preview?, wi
80
80
 
81
81
  If you don't want to raise an exception but return a null instead, you should set a `raise: false` option.
82
82
 
83
+ Note: it does not make too much sense to use `authorize` in mutations since it's checking authorization rules after mutation is executed. Therefore `authorize` marked as deprecated when used in mutations and will raise error in future releases.
84
+
83
85
  ### `authorized_scope: *`
84
86
 
85
87
  You can add `authorized_scope: true` option to the field (list or _connection_ field) to
@@ -22,17 +22,29 @@ module ActionPolicy
22
22
  end
23
23
 
24
24
  class AuthorizeExtension < Extension
25
- def apply
26
- @to = extract_option(:to) { ::ActionPolicy::GraphQL.default_authorize_rule }
27
- @raise = extract_option(:raise) do
28
- if field.mutation
29
- ::ActionPolicy::GraphQL.authorize_mutation_raise_exception
25
+ DEPRECATION_MESSAGE = "`authorize: *` for mutation fields is deprecated. Please use `preauthorize: *` instead."
26
+
27
+ class << self
28
+ def show_authorize_mutation_deprecation
29
+ return if defined?(@authorize_mutation_deprecation_shown)
30
+
31
+ if defined?(ActiveSupport::Deprecation)
32
+ ActiveSupport::Deprecation.warn(DEPRECATION_MESSAGE)
30
33
  else
31
- ::ActionPolicy::GraphQL.authorize_raise_exception
34
+ warn(DEPRECATION_MESSAGE)
32
35
  end
36
+
37
+ @authorize_mutation_deprecation_shown = true
33
38
  end
34
39
  end
35
40
 
41
+ def apply
42
+ self.class.show_authorize_mutation_deprecation if field.mutation
43
+
44
+ @to = extract_option(:to) { ::ActionPolicy::GraphQL.default_authorize_rule }
45
+ @raise = extract_option(:raise) { ::ActionPolicy::GraphQL.authorize_raise_exception }
46
+ end
47
+
36
48
  def after_resolve(value:, context:, object:, **_rest)
37
49
  return value if value.nil?
38
50
 
@@ -36,7 +36,7 @@ module ActionPolicy
36
36
 
37
37
  base.authorize :user, through: :current_user
38
38
 
39
- if base.respond_to?(:field_class)
39
+ if base.respond_to?(:field_class) && !(base.field_class < ActionPolicy::GraphQL::AuthorizedField)
40
40
  base.field_class.prepend(ActionPolicy::GraphQL::AuthorizedField)
41
41
  base.include ActionPolicy::GraphQL::Fields
42
42
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActionPolicy
4
4
  module GraphQL
5
- VERSION = "0.5.0"
5
+ VERSION = "0.5.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_policy-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-07 00:00:00.000000000 Z
11
+ date: 2020-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: action_policy