ibrain-core 0.2.2 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0accd0585dbb8b751342cfbeae014e22ef41b75b56bb3aba37f2071813307344
4
- data.tar.gz: b5e922dea8ec2515d5ee390271d04e9ba879d88d0b629f54868420d46771386e
3
+ metadata.gz: 1fe387824c7b0f75b2650403231cc253b761c33fe0867b45af3adbedae3e6e36
4
+ data.tar.gz: 6f018c39da2e0f9acc7f4dc7ca416faca4e5e4c002eab41beab340e4f8e34dce
5
5
  SHA512:
6
- metadata.gz: be6f2b3e72bdba22100743dfa74b99b001ab17f5c4ebf3cc4218ab776667fc3761ad7db01326de8ed4c0d9cf5362f35cf66bbde2260fc943e72327e81a8557b0
7
- data.tar.gz: 47dd41b984584ca4e3bc820e9a07b18eafcbcd8312f5ccad9c03c322ca49ff56cc2bf43ac1d1360db61f87dca904cfb61edac157b6527ae94ce746e1224a2abf
6
+ metadata.gz: d54971c207b5f127f655e9ca11327d713da840853e9b7bbe919db2f608bf120944a791081f14b7b894086890bc46f6fbfcbcf4279fbe3ef7e2c0aad94d78d712
7
+ data.tar.gz: 5e6bd207c6176b067b69cfd56ced53209e69b53acf5b76f0b506ed9dfa32a7211dc6ebff94f05be70891872a08c2f45326cf66cc894fcb4bcc811dedccebf916
@@ -4,10 +4,10 @@ module Ibrain
4
4
  class BaseSchema < ::GraphQL::Schema
5
5
  use GraphQL::Batch
6
6
 
7
- use GraphQL::Guard.new(
8
- policy_object: ::Ibrain::Config.graphql_policy.safe_constantize,
9
- not_authorized: ->(type, field) { raise IbrainErrors::PermissionError.new("You not have permission to access #{type}.#{field}") }
10
- )
7
+ # use GraphQL::Guard.new(
8
+ # policy_object: ::Ibrain::Config.graphql_policy.safe_constantize,
9
+ # not_authorized: ->(type, field) { raise IbrainErrors::PermissionError.new("You not have permission to access #{type}.#{field}") }
10
+ # )
11
11
 
12
12
  # Union and Interface Resolution
13
13
  def self.resolve_type(_abstract_type, _obj, _ctx)
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Extentions
5
+ class Roles < GraphQL::Schema::FieldExtension
6
+ def after_resolve(object:, value:, **_rest)
7
+ raise IbrainErrors::PermissionError.new("You not have permission to access #{field&.name}") if is_invalid_role(object)
8
+
9
+ value
10
+ end
11
+
12
+ private
13
+
14
+ def is_invalid_role(object)
15
+ roles = options.try(:fetch, :roles, [])
16
+ current_user = object.try(:context).try(:fetch, :current_user, nil)
17
+ role = current_user.try(:role) || current_user.try(:graphql_role)
18
+
19
+ return if roles.blank?
20
+ return true if current_user.blank?
21
+ return false if roles.include?(role)
22
+
23
+ true
24
+ end
25
+ end
26
+ end
27
+ end
@@ -13,7 +13,7 @@ module Ibrain
13
13
  private
14
14
 
15
15
  def is_invalid_session(object)
16
- object.try(:contect).try(:fetch, :current_user, nil).blank? && options.try(:fetch, :session_required, false)
16
+ object.try(:context).try(:fetch, :current_user, nil).blank? && options.try(:fetch, :session_required, false)
17
17
  end
18
18
  end
19
19
  end
@@ -5,10 +5,11 @@ module Ibrain
5
5
  class BaseApiField < GraphQL::Schema::Field
6
6
  argument_class ::Ibrain::Types::BaseArgument
7
7
 
8
- def initialize(*args, session_required: true, **kwargs, &block)
8
+ def initialize(*args, session_required: true, roles: nil, **kwargs, &block)
9
9
  super(*args, camelize: false, **kwargs, &block)
10
10
 
11
11
  extension(Ibrain::Extentions::SessionRequired, session_required: session_required) if session_required
12
+ extension(Ibrain::Extentions::Roles, roles: roles) if roles
12
13
  end
13
14
  end
14
15
  end
@@ -5,10 +5,11 @@ module Ibrain
5
5
  class BaseField < GraphQL::Schema::Field
6
6
  argument_class ::Ibrain::Types::BaseArgument
7
7
 
8
- def initialize(*args, default_value: nil, **kwargs, &block)
8
+ def initialize(*args, default_value: nil, roles: nil, **kwargs, &block)
9
9
  super(*args, camelize: false, **kwargs, &block)
10
10
 
11
11
  extension(::Ibrain::Extentions::DefaultValue, default_value: default_value) unless default_value.nil?
12
+ extension(Ibrain::Extentions::Roles, roles: roles) if roles
12
13
  end
13
14
  end
14
15
  end
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ibrain
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.6"
5
5
 
6
6
  def self.ibrain_version
7
7
  VERSION
8
8
  end
9
9
 
10
10
  def self.previous_ibrain_minor_version
11
- '0.2.1'
11
+ '0.2.5'
12
12
  end
13
13
 
14
14
  def self.ibrain_gem_version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibrain-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tai Nguyen Van
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-07 00:00:00.000000000 Z
11
+ date: 2022-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-session_store
@@ -186,6 +186,7 @@ files:
186
186
  - app/controllers/ibrain/core/graphql_controller.rb
187
187
  - app/graphql/ibrain/base_schema.rb
188
188
  - app/graphql/ibrain/extentions/default_value.rb
189
+ - app/graphql/ibrain/extentions/roles.rb
189
190
  - app/graphql/ibrain/extentions/session_required.rb
190
191
  - app/graphql/ibrain/interfaces/base_interface.rb
191
192
  - app/graphql/ibrain/interfaces/person_interface.rb