graphql-pundit 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/lib/graphql-pundit/instrumenter.rb +0 -10
- data/lib/graphql-pundit/instrumenters/scope.rb +5 -1
- data/lib/graphql-pundit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d29e967add746973f9b8b17927d9cb4929e01a3
|
4
|
+
data.tar.gz: 345db8210f01ccde612dab0e6d46138e6320e2ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 421f7515bad6de63018207fc5a8c0efc0b8e1450f2aef126ee4103d9fcba00a936183a2c6d89091349c57953b4b83da254e7a8596dbfd4a65b6187c100dc177c
|
7
|
+
data.tar.gz: f79f667733fb0c4515ac9917dee32220a8df70cc0c52c38911525face5421e39c17edd3f6aa6e48cfd80bd759f1b1db952996a837182ea980dd5e6b24338387f
|
data/README.md
CHANGED
@@ -112,6 +112,15 @@ field :posts
|
|
112
112
|
end
|
113
113
|
```
|
114
114
|
|
115
|
+
In case you only want to specify the Policy class containing the Scope explicitly, you can pass the Policy class explicitly:
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
field :posts
|
119
|
+
scope PostablePolicy
|
120
|
+
resolve ...
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
115
124
|
## Development
|
116
125
|
|
117
126
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -23,16 +23,6 @@ module GraphQL
|
|
23
23
|
scoped_field = scope_instrumenter.instrument(type, field)
|
24
24
|
authorization_instrumenter.instrument(type, scoped_field)
|
25
25
|
end
|
26
|
-
|
27
|
-
def authorize(current_user, obj, args, ctx, options)
|
28
|
-
if options[:proc]
|
29
|
-
options[:proc].call(obj, args, ctx)
|
30
|
-
else
|
31
|
-
::Pundit.authorize(ctx[current_user],
|
32
|
-
options[:record] || obj,
|
33
|
-
options[:query].to_s + '?')
|
34
|
-
end
|
35
|
-
end
|
36
26
|
end
|
37
27
|
end
|
38
28
|
end
|
@@ -25,6 +25,10 @@ module GraphQL
|
|
25
25
|
old_resolve = field.resolve_proc
|
26
26
|
|
27
27
|
scope_proc = lambda do |obj, _args, ctx|
|
28
|
+
unless inferred?(scope)
|
29
|
+
obj.define_singleton_method(:policy_class) { scope }
|
30
|
+
end
|
31
|
+
|
28
32
|
::Pundit.policy_scope!(ctx[current_user], obj)
|
29
33
|
end
|
30
34
|
scope_proc = scope if proc?(scope)
|
@@ -40,7 +44,7 @@ module GraphQL
|
|
40
44
|
private
|
41
45
|
|
42
46
|
def valid_value?(value)
|
43
|
-
inferred?(value) || proc?(value)
|
47
|
+
value.is_a?(Class) || inferred?(value) || proc?(value)
|
44
48
|
end
|
45
49
|
|
46
50
|
def proc?(value)
|