ibrain-core 0.1.4 → 0.1.8

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: 4037e5cd9ca8b82b658114e6d61cf5376861c2d39dc0ad5b63e1a41a56ef482b
4
- data.tar.gz: a1723cc8a56105297c25e92286d8547d9aead9936b342cf40b1adf19b156398b
3
+ metadata.gz: 48487077f193996a5756c2c1e000b4ff5df6bd8e8364b557edcdfc0958a625aa
4
+ data.tar.gz: ab5e00f8d7c86202c0b13b53d808b26bb9cc60bbd7480e1ee0c012a3e4795df5
5
5
  SHA512:
6
- metadata.gz: 5459ecaf4eb74fe6afa3a482040a3495d189f1a583344527b585be5203b58ba440bfceadcf8b14f5c7530fc3bc74f3d6ba2b093afb28c89a0d93efed8c553ad7
7
- data.tar.gz: 3bdf0366d1c33131c247c767fe9ee8dd3c4637e453124d1ad04c93b8712b62a802276ddab578a372950db3ab5317162ff0868795ec3c9f1bc716f383a0c31ea2
6
+ metadata.gz: 869c5f04e5b7dd23aa84c4159909c63c9913e10dc4c3a1c2832d2a566fd8a2f5dfe52f1a10628695f64b6fdbe8a1d7fec955c38511868c592e6b48c99bb3b682
7
+ data.tar.gz: ccb1c397c1493b1d788af86f3dca9a368150165825e8ed82af04b06b481a96ed66e376ce3c3f53a6ce2a183f2bf80af83446a7b719d7a66b4e5d0a151251a2d5
@@ -18,7 +18,7 @@ module Ibrain
18
18
  end
19
19
 
20
20
  def skip_operations
21
- []
21
+ %w[sign_in].include?(operation_name)
22
22
  end
23
23
 
24
24
  def cryptor
@@ -2,6 +2,15 @@
2
2
 
3
3
  module Ibrain
4
4
  class GraphqlController < Ibrain::BaseController
5
+ include Devise::Controllers::ScopedViews
6
+
7
+ before_action :authenticate_user!, unless: :skip_operations
8
+ before_action :map_user_class_to_request
9
+
10
+ helpers = %w(resource scope_name resource_name signed_in_resource
11
+ resource_class resource_params devise_mapping)
12
+ helper_method(*helpers)
13
+
5
14
  def execute
6
15
  query, variables, operation_name = normalize_entity
7
16
 
@@ -10,7 +19,9 @@ module Ibrain
10
19
  variables: variables,
11
20
  context: {
12
21
  session: session,
13
- current_user: try_ibrain_current_user
22
+ current_user: try_ibrain_current_user,
23
+ controller: self,
24
+ request: request
14
25
  },
15
26
  operation_name: operation_name
16
27
  )
@@ -51,5 +62,11 @@ module Ibrain
51
62
  def schema
52
63
  Ibrain::Config.graphql_schema.safe_constantize
53
64
  end
65
+
66
+ def map_user_class_to_request
67
+ return if request.env['devise.mapping'].present?
68
+
69
+ request.env['devise.mapping'] = Ibrain.user_class
70
+ end
54
71
  end
55
72
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Ibrain
4
4
  module Lazy
5
- class Base < GraphQL::Function
5
+ class Base < GraphQL::Schema::Resolver
6
6
  end
7
7
  end
8
8
  end
@@ -30,6 +30,18 @@ module Ibrain
30
30
  def current_user
31
31
  context[:current_user]
32
32
  end
33
+
34
+ def controller
35
+ context[:controller]
36
+ end
37
+
38
+ def session
39
+ context[:session]
40
+ end
41
+
42
+ def request
43
+ context[:request]
44
+ end
33
45
  end
34
46
  end
35
47
  end
@@ -10,6 +10,10 @@ module Ibrain
10
10
  def current_user
11
11
  context.fetch(:current_user)
12
12
  end
13
+
14
+ def controller
15
+ context[:controller]
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Types
5
+ class AttributeType < BaseScalar
6
+ end
7
+ end
8
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseNode < Types::BaseObject
3
+ class Ibrain::Types::BaseNode < Ibrain::Types::BaseObject
4
4
  include ::GraphQL::Relay::Node
5
5
  implements ::Ibrain::Interfaces::RecordInterface
6
6
 
@@ -5,10 +5,8 @@ module Ibrain
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  include Ibrain::UserApiAuthentication
8
- include Ibrain::UserReporting
9
8
 
10
9
  included do
11
- extend Ibrain::DisplayMoney
12
10
  after_create :auto_generate_ibrain_api_key
13
11
 
14
12
  include Ibrain::RansackableAttributes unless included_modules.include?(Ibrain::RansackableAttributes)
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ IGNORE_ATTRIBUTES = %w(id created_at updated_at)
4
+
3
5
  class Ibrain::Base < Ibrain::ApplicationRecord
4
6
  include ActionView::Helpers::DateHelper
5
7
 
@@ -49,5 +51,9 @@ class Ibrain::Base < Ibrain::ApplicationRecord
49
51
  def adjust_date_for_cdt(datetime)
50
52
  datetime.in_time_zone('UTC')
51
53
  end
54
+
55
+ def permitted_attributes
56
+ column_names.reject { |k| IGNORE_ATTRIBUTES.include?(k) }
57
+ end
52
58
  end
53
59
  end
@@ -6,7 +6,7 @@ module Ibrain
6
6
  # @note This class is intended to be modified by extensions (ex.
7
7
  # ibrain-auth)
8
8
  class LegacyUser < Ibrain::Base
9
- include UserMethods
9
+ include Ibrain::UserMethods
10
10
 
11
11
  self.table_name = 'ibrain_users'
12
12
 
@@ -55,7 +55,7 @@ module Ibrain
55
55
  Would you like to install it? (Y/n)"))
56
56
 
57
57
  @plugins_to_be_installed << 'ibrain-auth' unless system('gem list | grep ibrain-auth')
58
- @plugin_generators_to_run << 'ibrain:auth:install'
58
+ @plugin_generators_to_run << "ibrain:auth:install --with-ridgpole=#{options[:with_ridgepole]}"
59
59
  end
60
60
  end
61
61
 
@@ -7,7 +7,7 @@
7
7
 
8
8
  Rails.application.config.middleware.insert_before 0, Rack::Cors do
9
9
  allow do
10
- origins '*'
10
+ origins ['localhost']
11
11
 
12
12
  resource '*',
13
13
  headers: :any,
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ibrain
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.8"
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.1.3'
11
+ '0.1.7'
12
12
  end
13
13
 
14
14
  def self.ibrain_gem_version
data/lib/ibrain/core.rb CHANGED
@@ -14,6 +14,7 @@ require 'friendly_id'
14
14
  require 'kaminari/activerecord'
15
15
  require 'rack/cors'
16
16
  require 'ransack'
17
+ require 'discard'
17
18
 
18
19
  module Ibrain
19
20
  mattr_accessor :user_class
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.1.4
4
+ version: 0.1.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: 2021-12-20 00:00:00.000000000 Z
11
+ date: 2022-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-session_store
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.15.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: discard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: friendly_id
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -183,6 +197,7 @@ files:
183
197
  - app/graphql/ibrain/resolvers/base_aggregate.rb
184
198
  - app/graphql/ibrain/resolvers/base_resolver.rb
185
199
  - app/graphql/ibrain/types/aggregate_type.rb
200
+ - app/graphql/ibrain/types/attribute_type.rb
186
201
  - app/graphql/ibrain/types/base_argument.rb
187
202
  - app/graphql/ibrain/types/base_connection.rb
188
203
  - app/graphql/ibrain/types/base_edge.rb
@@ -199,14 +214,13 @@ files:
199
214
  - app/graphql/ibrain/types/node_type.rb
200
215
  - app/graphql/ibrain/util/field_combiner.rb
201
216
  - app/graphql/ibrain/util/query_combiner.rb
202
- - app/graphql/mutations/insert_user.rb
217
+ - app/models/concerns/ibrain/ransackable_attributes.rb
218
+ - app/models/concerns/ibrain/soft_deletable.rb
219
+ - app/models/concerns/ibrain/user_api_authentication.rb
220
+ - app/models/concerns/ibrain/user_methods.rb
203
221
  - app/models/ibrain/ability.rb
204
222
  - app/models/ibrain/application_record.rb
205
223
  - app/models/ibrain/base.rb
206
- - app/models/ibrain/concerns/ransackable_attributes.rb
207
- - app/models/ibrain/concerns/soft_deletable.rb
208
- - app/models/ibrain/concerns/user_api_authentication.rb
209
- - app/models/ibrain/concerns/user_methods.rb
210
224
  - app/models/ibrain/legacy_user.rb
211
225
  - app/models/ibrain/role.rb
212
226
  - app/models/ibrain/role_user.rb
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ibrain
4
- module Mutations
5
- class InsertUser < Ibrain::Mutations::BaseMutation
6
- # TODO: define return fields
7
- # field :post, Types::PostType, null: false
8
-
9
- # TODO: define arguments
10
- # argument :name, String, required: true
11
-
12
- # TODO: define resolve method
13
- # def resolve(name:)
14
- # { post: ... }
15
- # end
16
- end
17
- end
18
- end