ibrain-core 0.5.6 → 0.5.8

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: '082ccfa655b3f8a6574a155335e68dc25fc9f122d251a86fe899490d4e71cbfd'
4
- data.tar.gz: 2d356e73203f168cdcea21030960389eb6865e2554ccd6b04fce5d8d283beb7e
3
+ metadata.gz: c74180715e26a0b7365da263cc926c968a89176c3b80a7b70233839c8ac971f3
4
+ data.tar.gz: 8f74dd650002174ec4311e83976c98ececf292b2b4e1179fd6c8bc6835ac35f3
5
5
  SHA512:
6
- metadata.gz: 91a864f18e78ff1d4ff9fc5c86cb805291280a40b7239ebc84d3ac7f91fc5dedb6ae8f5a719ea17f1f8c4e9174ba02968771b8539361b27f6b68e376e4199c95
7
- data.tar.gz: 82ae6d5b5e41e27d7b54cde0c46f1ec754a873ee9a7a5f9f2545f45f568062960e63cd2d75e9f4996347ad70ba81ac80e7995515caaf9c95273835a5f76642b8
6
+ metadata.gz: f614df628d2a7ed54a25074acb7c5268d98c26a62b61045b9a6c2f33e0984318e491a5a4228bff5a65403b35e0a8edb571dbf3d1a665a47cb0f2748b17770bac
7
+ data.tar.gz: 37c7d65e40af2ca14a814a9d73e0ac074c78cb6a626ef01e002bb56b34a565802f1cc80d1b6ae23baba67901e2e8e493960877340604b4468fe100db4d171252
@@ -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_require_activated_account && 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_require_activated_account = 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_require_activated_account, :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.8"
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.8
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