graphql-permissions 0.1.0 → 0.1.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: b19b42395768459f48d770eeca3d951f5322f7340dbe1bdd2229ba209ddac71a
4
- data.tar.gz: 00d83aeec4b6ac80570c260e4175ff1933d11e0ecef922e0ee2474e12f8acdc6
3
+ metadata.gz: acad633b6804921ff87dd79146fc94ca570025f8193befafa6cfa72d7d96da17
4
+ data.tar.gz: 5e4271b38e08dd0d90ae6e577e378cbb804170ee2fecad4e38f08ac27c249497
5
5
  SHA512:
6
- metadata.gz: e6ee32bb1a6624c5859a938c40cb19e2b529e91abb7df079d553fb972e64a94ac02f671934dfca232d4d2275ad7b0646b6c697fee96a4ae5dfc849107befdb1a
7
- data.tar.gz: 9ee5d6ec4658bbf1b7ea5eb39308a4e9ad8bed8bf0e0bee03352a2a924e92f679bbbc9c1ea4a45ac60bf8e7f4d18233a6784a83a34ededf291887fbd8f299d91
6
+ metadata.gz: e75e87548d22f8f1d4c89e3b6019022fe93b0dc9bcc86c91bf7ceb43289467f64904dd9eaf57241d718717db2e54344d61e4dafb7c90fa38d4e760218d0e0bc8
7
+ data.tar.gz: 51bd2550553f9412c30a8509f332c3000f0f2acfb047e298777cf6aec2944ecf82959d834a55dbc82b5081b7db9a63379b76893c8bd1fe94b6e7e367e17aee51
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql-permissions (0.1.0)
5
- graphql
4
+ graphql-permissions (0.1.1)
5
+ graphql (~> 2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  ast (2.4.2)
11
- graphql (2.0.7)
11
+ graphql (2.0.15)
12
12
  parallel (1.22.1)
13
13
  parser (3.1.2.0)
14
14
  ast (~> 2.4.1)
data/README.md CHANGED
@@ -1,8 +1,24 @@
1
1
  # GraphQL::Permissions
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/graphql/permissions`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ GraphQL Permissions allows you to model permissions directly in your GraphQL schema. It works together with your authorization library to communicate which actions are and are not allowed to your client.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ At the highest level, it lets you write queries like this:
6
+ ```graphql
7
+ query PostById($id: ID!) {
8
+ post(id: $id) {
9
+ id
10
+ body
11
+ permissions {
12
+ canEdit
13
+ canDelete
14
+ }
15
+ }
16
+ }
17
+ ```
18
+
19
+ This helps keep all of your authorization logic in one place, and prevent disagreements between the server and client about whether a user can perform an action.
20
+
21
+ GraphQL Permissions was designed with the [Pundit](https://github.com/varvet/pundit) gem in mind, but should work with most authorization libraries.
6
22
 
7
23
  ## Installation
8
24
 
@@ -24,7 +40,21 @@ Then run the Rails generator:
24
40
 
25
41
  $ bin/rails generate graphql:permissions:install
26
42
 
27
- This will create the base permissions object and interface types, as well as an initializer under `config/initializers/graphql_permissions.rb`
43
+ This will create the base permissions object and interface types, as well as an initializer in `config/initializers/graphql_permissions.rb`
44
+
45
+ ### Configuring a Permission Handler
46
+
47
+ GraphQL Permissions requires a default permission handler callback to be defined by your application. This callback receives the action performed, the object being authorized, and your GraphQL context, and must return a Boolean value to indicate whether the action is or is not allowed.
48
+
49
+ For example, integration for the Pundit gem might look like so:
50
+
51
+ ```ruby
52
+ GraphQL::Permissions.default_permission_handler = lambda do |action, object, context|
53
+ Pundit.policy(context[:current_user], object).send(:"#{action}?")
54
+ end
55
+ ```
56
+
57
+ A stub permissions handler callback is defined under `config/initializers/graphql_permissions.rb` by the Rails generator.
28
58
 
29
59
  ## Usage
30
60
 
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ['lib']
32
32
 
33
- spec.add_dependency 'graphql'
33
+ spec.add_dependency 'graphql', '~> 2'
34
34
  end
@@ -18,7 +18,7 @@ module GraphQL
18
18
 
19
19
  # @return [Array<Module>]
20
20
  def interfaces_with_permissions
21
- own_interfaces.select { |interface| interface.respond_to?(:permissions_type) && interface.permissions_type }
21
+ interfaces.select { |interface| interface.respond_to?(:permissions_type) && interface.permissions_type }
22
22
  end
23
23
 
24
24
  def permissions(&block)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module Permissions
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-permissions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minty Fresh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-10 00:00:00.000000000 Z
11
+ date: 2022-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '2'
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'
26
+ version: '2'
27
27
  description: Expose user permissions in your GraphQL schema
28
28
  email:
29
29
  - 7896757+mintyfresh@users.noreply.github.com
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  requirements: []
76
- rubygems_version: 3.2.15
76
+ rubygems_version: 3.3.7
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: Permissions DSL for GraphQL Ruby