action_policy-graphql 0.3.1 → 0.3.2

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: a36627f17b3f0ed75370d60052cfc7f62fff25520c9bb58ba98289c1f3480903
4
- data.tar.gz: 45f7c8b1e3a2401113f90fa3b5cf002f6efba4647a9df98209b77c4123691100
3
+ metadata.gz: 4af0cfd306d4128f52758c4336988f29bfa8628f5839aa18e1a54b366c07a9b9
4
+ data.tar.gz: 69098890e8c59b44dd2af5a902639dbc407ce190a73e55c1d84b6c9ce464bad0
5
5
  SHA512:
6
- metadata.gz: 800c62024be3fb01378ebe900e62bd5fbc9343f27857dfa4c20125dd007ce6260e037599880df2e3d97cdab136466c272f6d3756f994595d46b4dbd3514ed330
7
- data.tar.gz: 37287ca3abcf008b787f8b9e504db6f4f396f22e4aab5c628524b8d2f543f99e043730ff2ec7455dbce106c7820578040576275e85f546d80f2ea0671d1fd642
6
+ metadata.gz: 2ee55992d03aa2cd350c2c29e9c632c84dff85288a55ef3608e5f277d407f182a98a1bafd820e18caffe4571b1f896cc5608f72979958da0336e6afef0d7f7ef
7
+ data.tar.gz: a99cac79463311fecb84d459b537555b9cefe88e0b268b07412d5a0b053ce603c8cea3a426e92cd58033b789d474f008bd3f22b7296270f66e0409f37c0ac6bf
@@ -15,9 +15,13 @@ matrix:
15
15
  fast_finish: true
16
16
  include:
17
17
  - rvm: ruby-head
18
- gemfile: gemfiles/graphqlmaster.gemfile
18
+ gemfile: gemfiles/graphql/master.gemfile
19
19
  - rvm: 2.6
20
- gemfile: gemfiles/graphqlmaster.gemfile
20
+ gemfile: gemfiles/graphql/master.gemfile
21
+ - rvm: 2.6
22
+ gemfile: gemfiles/action_policy/master.gemfile
23
+ - rvm: 2.6
24
+ gemfile: gemfiles/action_policy/0.3.gemfile
21
25
  - rvm: jruby-9.2.5.0
22
26
  gemfile: gemfiles/jruby.gemfile
23
27
  - rvm: 2.6
@@ -28,6 +32,8 @@ matrix:
28
32
  gemfile: Gemfile
29
33
  allow_failures:
30
34
  - rvm: ruby-head
31
- gemfile: gemfiles/graphqlmaster.gemfile
35
+ gemfile: gemfiles/graphql/master.gemfile
36
+ - rvm: 2.6
37
+ gemfile: gemfiles/graphql/master.gemfile
32
38
  - rvm: 2.6
33
- gemfile: gemfiles/graphqlmaster.gemfile
39
+ gemfile: gemfiles/action_policy/master.gemfile
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.3.2 (2019-12-12)
6
+
7
+ - Fix compatibility with Action Policy 0.4.0 ([@haines][])
8
+
5
9
  ## 0.3.1 (2019-10-23)
6
10
 
7
11
  - Add support for using Action Policy methods in `self.authorized?`. ([@palkan][])
@@ -30,3 +34,4 @@ Action Policy helpers there.
30
34
  - Initial version. ([@palkan][])
31
35
 
32
36
  [@palkan]: https://github.com/palkan
37
+ [@haines]: https://github.com/haines
data/Gemfile CHANGED
@@ -11,6 +11,6 @@ if File.exist?(local_gemfile)
11
11
  # Specify custom action_policy/graphql-ruby version in Gemfile.local
12
12
  eval(File.read(local_gemfile)) # rubocop:disable Security/Eval
13
13
  else
14
- gem "action_policy", "~> 0.3.0"
14
+ gem "action_policy", "~> 0.4.0"
15
15
  gem "graphql", "~> 1.9.3"
16
16
  end
data/README.md CHANGED
@@ -80,6 +80,8 @@ end
80
80
 
81
81
  You can customize the authorization options, e.g. `authorize: {to: :preview?, with: CustomPolicy}`.
82
82
 
83
+ If you don't want to raise an exception but return a null instead, you should set a `raise: false` option.
84
+
83
85
  ### `authorized_scope: *`
84
86
 
85
87
  You can add `authorized_scope: true` option to the field (list or _connection_ field) to
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "action_policy", "~> 0.3.0"
4
+
5
+ gemspec path: "../.."
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "action_policy", github: "palkan/action_policy"
4
+
5
+ gemspec path: "../.."
@@ -2,4 +2,4 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "graphql", github: "rmosolgo/graphql-ruby"
4
4
 
5
- gemspec path: ".."
5
+ gemspec path: "../.."
@@ -13,52 +13,61 @@ module ActionPolicy
13
13
  # field :comments, null: false, authorized: { type: :relation, with: MyPostPolicy }
14
14
  # end
15
15
  module AuthorizedField
16
- class AuthorizeExtension < ::GraphQL::Schema::FieldExtension
17
- def initialize(*)
18
- super
19
- options[:to] ||= ::ActionPolicy::GraphQL.default_authorize_rule
20
- options[:raise] = ::ActionPolicy::GraphQL.authorize_raise_exception unless options.key?(:raise)
16
+ class Extension < ::GraphQL::Schema::FieldExtension
17
+ def extract_option(key, &default)
18
+ value = options.fetch(key, &default)
19
+ options.delete key
20
+ value
21
+ end
22
+ end
23
+
24
+ class AuthorizeExtension < Extension
25
+ def apply
26
+ @to = extract_option(:to) { ::ActionPolicy::GraphQL.default_authorize_rule }
27
+ @raise = extract_option(:raise) { ::ActionPolicy::GraphQL.authorize_raise_exception }
21
28
  end
22
29
 
23
30
  def after_resolve(value:, context:, object:, **_rest)
24
31
  return value if value.nil?
25
32
 
26
- if options[:raise]
27
- object.authorize! value, **options
33
+ if @raise
34
+ object.authorize! value, to: @to, **options
28
35
  value
29
36
  else
30
- object.allowed_to?(options[:to], value, options) ? value : nil
37
+ object.allowed_to?(@to, value, **options) ? value : nil
31
38
  end
32
39
  end
33
40
  end
34
41
 
35
- class PreauthorizeExtension < ::GraphQL::Schema::FieldExtension
36
- def initialize(*)
37
- super
42
+ class PreauthorizeExtension < Extension
43
+ def apply
38
44
  if options[:with].nil?
39
45
  raise ArgumentError, "You must specify the policy for preauthorization: " \
40
46
  "`field :#{field.name}, preauthorize: {with: SomePolicy}`"
41
47
  end
42
- options[:to] ||=
48
+
49
+ @to = extract_option(:to) do
43
50
  if field.type.list?
44
51
  ::ActionPolicy::GraphQL.default_preauthorize_list_rule
45
52
  else
46
53
  ::ActionPolicy::GraphQL.default_preauthorize_node_rule
47
54
  end
48
- options[:raise] = ::ActionPolicy::GraphQL.authorize_raise_exception unless options.key?(:raise)
55
+ end
56
+
57
+ @raise = extract_option(:raise) { ::ActionPolicy::GraphQL.authorize_raise_exception }
49
58
  end
50
59
 
51
60
  def resolve(context:, object:, arguments:, **_rest)
52
- if options[:raise]
53
- object.authorize! field.name, **options
61
+ if @raise
62
+ object.authorize! field.name, to: @to, **options
54
63
  yield object, arguments
55
- elsif object.allowed_to?(options[:to], field.name, options)
64
+ elsif object.allowed_to?(@to, field.name, **options)
56
65
  yield object, arguments
57
66
  end
58
67
  end
59
68
  end
60
69
 
61
- class ScopeExtension < ::GraphQL::Schema::FieldExtension
70
+ class ScopeExtension < Extension
62
71
  def after_resolve(value:, context:, object:, **_rest)
63
72
  return value if value.nil?
64
73
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActionPolicy
4
4
  module GraphQL
5
- VERSION = "0.3.1"
5
+ VERSION = "0.3.2"
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.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-23 00:00:00.000000000 Z
11
+ date: 2019-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: action_policy
@@ -154,7 +154,9 @@ files:
154
154
  - action_policy-graphql.gemspec
155
155
  - bin/console
156
156
  - bin/setup
157
- - gemfiles/graphqlmaster.gemfile
157
+ - gemfiles/action_policy/0.3.gemfile
158
+ - gemfiles/action_policy/master.gemfile
159
+ - gemfiles/graphql/master.gemfile
158
160
  - gemfiles/jruby.gemfile
159
161
  - lib/action_policy-graphql.rb
160
162
  - lib/action_policy/graphql.rb
@@ -188,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
190
  - !ruby/object:Gem::Version
189
191
  version: '0'
190
192
  requirements: []
191
- rubygems_version: 3.0.4
193
+ rubygems_version: 3.0.6
192
194
  signing_key:
193
195
  specification_version: 4
194
196
  summary: Action Policy integration for GraphQL-Ruby