graphql_role_restrict 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/graphql_role_restrict/version.rb +5 -0
- data/lib/graphql_role_restrict.rb +45 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 338e1922413ceb499a26d32e0e3add4db1528dc1a95ad3c27643785184cc0051
|
4
|
+
data.tar.gz: 1623dfa1d4fde932939b551d948102a3f04b68a262ee0a94d047fa0509e07572
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9e72fb169da317e491b7d0c552935c4fdf08bab10f0cf3d0b8d9dcb2630d643028bf30f407acab7ba54c54ca50cf6cc6618365ad626a65adfa2d45a2b354476
|
7
|
+
data.tar.gz: 040b6723013719a68f76bcf02e58fc70950c9158fdf752670258dd592c7a71a17ad094a9340969c759eb5d9f321731bda664864c4359d710533dc14e6dcb271a
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This is based on the #visible? method described in
|
4
|
+
# https://graphql-ruby.org/authorization/visibility.html
|
5
|
+
module GraphqlRoleRestrict
|
6
|
+
# register a new option `role_restrict`
|
7
|
+
def initialize(*args, role_restrict: :logged_in, **kwargs, &block)
|
8
|
+
@role_restrict = role_restrict
|
9
|
+
|
10
|
+
# Pass on the default args:
|
11
|
+
super(*args, **kwargs, &block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_graphql
|
15
|
+
field_defn = super # Returns a GraphQL::Field
|
16
|
+
field_defn.metadata[:role_restrict] = @role_restrict
|
17
|
+
field_defn
|
18
|
+
end
|
19
|
+
|
20
|
+
def visible?(context)
|
21
|
+
super && context_role_valid?(context, @role_restrict)
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# Check the validatity of the the role_restrict value against an object representing
|
26
|
+
# the current_user stored in context[:current_user]
|
27
|
+
# (injection of that value has to be done at the controller level before accessing graphql code)
|
28
|
+
#
|
29
|
+
# Method NEEDS to be Overwritten once the module is included in your Argument/Field class to allow
|
30
|
+
# custom logic
|
31
|
+
#
|
32
|
+
# @param [GraphQL::Query::Context] context Graphql context object
|
33
|
+
# @param [Any] role_restrict Any value passed in to a role_restrict option of a field / argument
|
34
|
+
#
|
35
|
+
# @return [Boolean]
|
36
|
+
#
|
37
|
+
def context_role_valid?(context, role_restrict)
|
38
|
+
case role_restrict
|
39
|
+
when :logged_in
|
40
|
+
!!context[:current_user]
|
41
|
+
else
|
42
|
+
true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: graphql_role_restrict
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- François TCHENG
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-02-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3'
|
55
|
+
description: Simple plugin to allow hiding fields/arguments depending on query context
|
56
|
+
email:
|
57
|
+
- tcheng.f@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- "./lib/graphql_role_restrict.rb"
|
63
|
+
- "./lib/graphql_role_restrict/version.rb"
|
64
|
+
homepage: https://github.com/nekogami/graphql_role_restrict
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubygems_version: 3.3.3
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Simple Field/Argument authorization layer for the gem graphql
|
87
|
+
test_files: []
|