ibrain-core 0.5.6 → 0.5.7

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: '082ccfa655b3f8a6574a155335e68dc25fc9f122d251a86fe899490d4e71cbfd'
4
- data.tar.gz: 2d356e73203f168cdcea21030960389eb6865e2554ccd6b04fce5d8d283beb7e
3
+ metadata.gz: f191aab54d45f3806d2c2f3cddcc3b31fe5d9e8e4f845ef3761a097ffa588b90
4
+ data.tar.gz: '08030f9583b5d32b5d173e2b5d3a913b665b2637547faf8c90d53e70cd43524c'
5
5
  SHA512:
6
- metadata.gz: 91a864f18e78ff1d4ff9fc5c86cb805291280a40b7239ebc84d3ac7f91fc5dedb6ae8f5a719ea17f1f8c4e9174ba02968771b8539361b27f6b68e376e4199c95
7
- data.tar.gz: 82ae6d5b5e41e27d7b54cde0c46f1ec754a873ee9a7a5f9f2545f45f568062960e63cd2d75e9f4996347ad70ba81ac80e7995515caaf9c95273835a5f76642b8
6
+ metadata.gz: d4f80dcef1a20a8caeec9646d55dc965710b44b64b8ad7d9ba7dd63ca5a3673496dca9b10407ea7d5bc15cdf7f2d636d5bd206807e351208e16b39c9c08ad891
7
+ data.tar.gz: be236a9a75d62f231609bf493447330075a601a2a2495a24f834ca05c5b8565d62347dfaa50776d24fb1f5bc3873cd19c2bb161c631d48dfeca85adc33a0d285
@@ -13,7 +13,8 @@ module Ibrain
13
13
  private
14
14
 
15
15
  def is_activated(object)
16
- object.try(:context).try(:fetch, :current_user, nil).blank? && options.try(:fetch, :session_required, false)
16
+ current_user = object.try(:context).try(:fetch, :current_user, nil)
17
+ current_user.try(:is_activated?) && options.try(:fetch, :active_required, false)
17
18
  end
18
19
  end
19
20
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Loaders
5
+ class AssociationCountLoader < GraphQL::Batch::Loader
6
+ def initialize(model, association_name)
7
+ super()
8
+ @model = model
9
+ @association_name = association_name
10
+ end
11
+
12
+ def perform(records)
13
+ reflection = @model.reflect_on_association(@association_name)
14
+ reflection.check_preloadable!
15
+
16
+ klass = reflection.klass
17
+ field = reflection.join_primary_key
18
+ counts = klass.unscoped.where(field => records).group(field).count
19
+
20
+ records.each do |record|
21
+ record_key = record[reflection.active_record_primary_key]
22
+ fulfill(record, counts[record_key] || 0)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Loaders
5
+ class CountLoader < GraphQL::Batch::Loader
6
+ def initialize(model, field)
7
+ super()
8
+ @model = model
9
+ @field = field
10
+ end
11
+
12
+ def perform(ids)
13
+ counts = @model.unscoped.where(@field => ids).group(@field).count
14
+
15
+ counts.each { |id, count| fulfill(id, count) }
16
+ ids.each { |id| fulfill(id, 0) unless fulfilled?(id) }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -5,11 +5,15 @@ 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, roles: nil, **kwargs, &block)
8
+ def initialize(*args, session_required: true, roles: nil, active_required: true, **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
12
  extension(Ibrain::Extentions::Roles, roles: roles) if roles
13
+
14
+ if ::Ibrain.config.is_activated_account_require && active_required
15
+ extension(Ibrain::Extentions::ActiveRequired)
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -24,6 +24,14 @@ module Ibrain
24
24
  def current_user
25
25
  context.try(:fetch, :current_user)
26
26
  end
27
+
28
+ def association_count_loader
29
+ Ibrain::Loaders::AssociationCountLoader
30
+ end
31
+
32
+ def count_loader
33
+ Ibrain::Loaders::CountLoader
34
+ end
27
35
  end
28
36
  end
29
37
  end
@@ -53,6 +53,9 @@ Ibrain.config do |config|
53
53
 
54
54
  # For auto append mutation to graphql
55
55
  config.is_auto_append_mutation = true
56
+
57
+ # Enable require active
58
+ config.is_activated_account_require = false
56
59
  end
57
60
 
58
61
  <% if defined?(Ibrain::Api::Engine) -%>
@@ -57,6 +57,8 @@ module Ibrain
57
57
 
58
58
  preference :is_auto_append_mutation, :boolean, default: true
59
59
 
60
+ preference :is_activated_account_require, :boolean, default: false
61
+
60
62
  def static_model_preferences
61
63
  @static_model_preferences ||= Ibrain::Preferences::StaticModelPreferences.new
62
64
  end
@@ -1,16 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ibrain
4
- VERSION = "0.5.6"
4
+ VERSION = "0.5.7"
5
5
 
6
6
  def self.ibrain_version
7
7
  VERSION
8
8
  end
9
9
 
10
- def self.previous_ibrain_minor_version
11
- '0.5.5'
12
- end
13
-
14
10
  def self.ibrain_gem_version
15
11
  Gem::Version.new(ibrain_version)
16
12
  end
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.5.6
4
+ version: 0.5.7
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-10-20 00:00:00.000000000 Z
11
+ date: 2022-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-session_store
@@ -173,7 +173,9 @@ files:
173
173
  - app/graphql/ibrain/interfaces/person_interface.rb
174
174
  - app/graphql/ibrain/interfaces/record_interface.rb
175
175
  - app/graphql/ibrain/lazy/base.rb
176
+ - app/graphql/ibrain/loaders/association_count_loader.rb
176
177
  - app/graphql/ibrain/loaders/association_loader.rb
178
+ - app/graphql/ibrain/loaders/count_loader.rb
177
179
  - app/graphql/ibrain/log_query_depth.rb
178
180
  - app/graphql/ibrain/mutations/base_mutation.rb
179
181
  - app/graphql/ibrain/policies/base_policy.rb