ibrain-core 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/ibrain/base_controller.rb +12 -14
- data/app/controllers/ibrain/core/graphql_controller.rb +79 -83
- data/app/graphql/ibrain/base_schema.rb +50 -52
- data/app/graphql/ibrain/extentions/default_value.rb +7 -11
- data/app/graphql/ibrain/extentions/roles.rb +15 -20
- data/app/graphql/ibrain/extentions/session_required.rb +10 -14
- data/app/graphql/ibrain/lazy/base.rb +2 -6
- data/app/graphql/ibrain/loaders/association_loader.rb +51 -55
- data/app/graphql/ibrain/mutations/base_mutation.rb +52 -56
- data/app/graphql/ibrain/policies/base_policy.rb +43 -47
- data/app/graphql/ibrain/policies/graphql_policy.rb +2 -6
- data/app/graphql/ibrain/resolvers/base_aggregate.rb +6 -10
- data/app/graphql/ibrain/resolvers/base_resolver.rb +8 -12
- data/app/graphql/ibrain/types/aggregate_type.rb +4 -8
- data/app/graphql/ibrain/types/attribute_type.rb +2 -5
- data/app/graphql/ibrain/types/base_api_connection.rb +6 -10
- data/app/graphql/ibrain/types/base_api_edge.rb +4 -8
- data/app/graphql/ibrain/types/base_api_field.rb +7 -11
- data/app/graphql/ibrain/types/base_api_object.rb +6 -10
- data/app/graphql/ibrain/types/base_argument.rb +3 -7
- data/app/graphql/ibrain/types/base_connection.rb +7 -11
- data/app/graphql/ibrain/types/base_edge.rb +3 -7
- data/app/graphql/ibrain/types/base_enum.rb +1 -5
- data/app/graphql/ibrain/types/base_field.rb +6 -10
- data/app/graphql/ibrain/types/base_input_object.rb +6 -10
- data/app/graphql/ibrain/types/base_interface.rb +5 -9
- data/app/graphql/ibrain/types/base_object.rb +12 -16
- data/app/graphql/ibrain/types/base_scalar.rb +1 -5
- data/app/graphql/ibrain/types/base_type.rb +4 -10
- data/app/graphql/ibrain/types/base_union.rb +3 -7
- data/app/graphql/ibrain/types/filter_type.rb +1 -5
- data/app/graphql/ibrain/types/node_type.rb +4 -8
- data/app/graphql/ibrain/util/field_combiner.rb +5 -9
- data/app/graphql/ibrain/util/query_combiner.rb +4 -8
- data/app/models/concerns/ibrain/soft_deletable.rb +6 -8
- data/app/models/concerns/ibrain/user_api_authentication.rb +14 -16
- data/app/models/concerns/ibrain/user_methods.rb +11 -13
- data/app/models/ibrain/ability.rb +31 -32
- data/app/models/ibrain/aggregate.rb +5 -7
- data/app/models/ibrain/application_record.rb +2 -4
- data/app/models/ibrain/legacy_user.rb +7 -13
- data/app/models/ibrain/role.rb +6 -8
- data/app/models/ibrain/role_user.rb +8 -10
- data/app/repositories/ibrain/base_repository.rb +9 -11
- data/lib/generators/ibrain/core/model_generator.rb +17 -21
- data/lib/generators/ibrain/graphql/core.rb +55 -59
- data/lib/generators/ibrain/graphql/mutation_generator.rb +58 -66
- data/lib/generators/ibrain/graphql/object_generator.rb +58 -70
- data/lib/generators/ibrain/graphql/resolver_generator.rb +17 -25
- data/lib/generators/ibrain/graphql/resolvers_generator.rb +59 -67
- data/lib/generators/ibrain/graphql/templates/aggregate.erb +5 -7
- data/lib/generators/ibrain/graphql/templates/input.erb +5 -9
- data/lib/generators/ibrain/graphql/templates/mutation.erb +24 -26
- data/lib/generators/ibrain/graphql/templates/object.erb +6 -10
- data/lib/generators/ibrain/graphql/templates/resolver.erb +9 -11
- data/lib/generators/ibrain/graphql/templates/resolvers.erb +8 -10
- data/lib/generators/ibrain/graphql/type_generator.rb +84 -88
- data/lib/generators/ibrain/install/install_generator.rb +137 -140
- data/lib/generators/ibrain/install/templates/graphql/types/mutation_type.rb.tt +13 -15
- data/lib/generators/ibrain/install/templates/graphql/types/query_type.rb.tt +11 -13
- data/lib/generators/ibrain/install/templates/rubocop.yml.tt +83 -30
- data/lib/ibrain/app_configuration.rb +34 -36
- data/lib/ibrain/core/class_constantizer.rb +30 -33
- data/lib/ibrain/core/controller_helpers/auth.rb +53 -59
- data/lib/ibrain/core/controller_helpers/current_host.rb +5 -11
- data/lib/ibrain/core/controller_helpers/response.rb +43 -49
- data/lib/ibrain/core/controller_helpers/strong_parameters.rb +9 -15
- data/lib/ibrain/core/engine.rb +5 -9
- data/lib/ibrain/core/environment.rb +5 -9
- data/lib/ibrain/core/environment_extension.rb +13 -17
- data/lib/ibrain/core/role_configuration.rb +52 -54
- data/lib/ibrain/core/validators/email.rb +15 -17
- data/lib/ibrain/core/version.rb +2 -2
- data/lib/ibrain/core/versioned_value.rb +61 -65
- data/lib/ibrain/encryptor.rb +18 -20
- data/lib/ibrain/logger.rb +13 -15
- data/lib/ibrain/permission_sets/base.rb +22 -26
- data/lib/ibrain/permission_sets/super_user.rb +3 -7
- data/lib/ibrain/permitted_attributes.rb +18 -20
- data/lib/ibrain/preferences/configuration.rb +135 -137
- data/lib/ibrain/preferences/preferable.rb +158 -162
- data/lib/ibrain/preferences/preferable_class_methods.rb +112 -114
- data/lib/ibrain/user_class_handle.rb +22 -24
- metadata +2 -2
@@ -3,138 +3,136 @@
|
|
3
3
|
require 'logger'
|
4
4
|
require 'ibrain/encryptor'
|
5
5
|
|
6
|
-
module Ibrain::Preferences
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def preference(name, type, options = {})
|
23
|
-
options.assert_valid_keys(:default, :encryption_key)
|
24
|
-
|
25
|
-
if type == :encrypted_string
|
26
|
-
preference_encryptor = preference_encryptor(options)
|
27
|
-
options[:default] = preference_encryptor.encrypt(options[:default])
|
28
|
-
end
|
29
|
-
|
30
|
-
default = begin
|
31
|
-
given = options[:default]
|
32
|
-
if self <= Ibrain::Preferences::Configuration &&
|
33
|
-
given.is_a?(Proc) &&
|
34
|
-
given.lambda? &&
|
35
|
-
given.arity.zero?
|
36
|
-
Ibrain::Logger.warn <<~MSG
|
37
|
-
The arity of a proc given as the default for a preference
|
38
|
-
has changed from 0 to 1 on Ibrain 3.1. The Ibrain
|
39
|
-
version for the loaded preference defaults is given as the
|
40
|
-
proc's argument from this point on.
|
41
|
-
|
42
|
-
If you don't need to return a different default value
|
43
|
-
depending on the loaded Ibrain version, you can change
|
44
|
-
the proc so that it doesn't have lambda semantics (lambdas
|
45
|
-
raise when extra arguments are supplied, while raw procs
|
46
|
-
don't). E.g.:
|
47
|
-
|
48
|
-
preference :foo, :string, default: proc { true }
|
49
|
-
|
50
|
-
If you want to branch on the provided Ibrain version, you can do like the following:
|
51
|
-
|
52
|
-
preference :foo, :string, default: by_version(true, "3.2.0" => false)
|
53
|
-
|
54
|
-
MSG
|
55
|
-
->(_default_context) { given.call }
|
56
|
-
elsif given.is_a?(Proc)
|
57
|
-
given
|
58
|
-
else
|
59
|
-
proc { given }
|
60
|
-
end
|
61
|
-
end
|
6
|
+
module Ibrain::Preferences::PreferableClassMethods
|
7
|
+
DEFAULT_ADMIN_FORM_PREFERENCE_TYPES = %i(
|
8
|
+
boolean
|
9
|
+
decimal
|
10
|
+
integer
|
11
|
+
password
|
12
|
+
string
|
13
|
+
text
|
14
|
+
encrypted_string
|
15
|
+
)
|
16
|
+
|
17
|
+
def defined_preferences
|
18
|
+
[]
|
19
|
+
end
|
62
20
|
|
63
|
-
|
64
|
-
|
65
|
-
# We store these as a class instance variable on each class which has a
|
66
|
-
# preference. super() collects preferences defined on ancestors.
|
67
|
-
singleton_preferences = (@defined_singleton_preferences ||= [])
|
68
|
-
singleton_preferences << name.to_sym
|
21
|
+
def preference(name, type, options = {})
|
22
|
+
options.assert_valid_keys(:default, :encryption_key)
|
69
23
|
|
70
|
-
|
71
|
-
|
72
|
-
|
24
|
+
if type == :encrypted_string
|
25
|
+
preference_encryptor = preference_encryptor(options)
|
26
|
+
options[:default] = preference_encryptor.encrypt(options[:default])
|
27
|
+
end
|
73
28
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
29
|
+
default = begin
|
30
|
+
given = options[:default]
|
31
|
+
if self <= Ibrain::Preferences::Configuration &&
|
32
|
+
given.is_a?(Proc) &&
|
33
|
+
given.lambda? &&
|
34
|
+
given.arity.zero?
|
35
|
+
Ibrain::Logger.warn <<~MSG
|
36
|
+
The arity of a proc given as the default for a preference
|
37
|
+
has changed from 0 to 1 on Ibrain 3.1. The Ibrain
|
38
|
+
version for the loaded preference defaults is given as the
|
39
|
+
proc's argument from this point on.
|
40
|
+
|
41
|
+
If you don't need to return a different default value
|
42
|
+
depending on the loaded Ibrain version, you can change
|
43
|
+
the proc so that it doesn't have lambda semantics (lambdas
|
44
|
+
raise when extra arguments are supplied, while raw procs
|
45
|
+
don't). E.g.:
|
46
|
+
|
47
|
+
preference :foo, :string, default: proc { true }
|
48
|
+
|
49
|
+
If you want to branch on the provided Ibrain version, you can do like the following:
|
50
|
+
|
51
|
+
preference :foo, :string, default: by_version(true, "3.2.0" => false)
|
52
|
+
|
53
|
+
MSG
|
54
|
+
->(_default_context) { given.call }
|
55
|
+
elsif given.is_a?(Proc)
|
56
|
+
given
|
57
|
+
else
|
58
|
+
proc { given }
|
59
|
+
end
|
60
|
+
end
|
83
61
|
|
84
|
-
|
85
|
-
|
86
|
-
|
62
|
+
# The defined preferences on a class are all those defined directly on
|
63
|
+
# that class as well as those defined on ancestors.
|
64
|
+
# We store these as a class instance variable on each class which has a
|
65
|
+
# preference. super() collects preferences defined on ancestors.
|
66
|
+
singleton_preferences = (@defined_singleton_preferences ||= [])
|
67
|
+
singleton_preferences << name.to_sym
|
87
68
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
preferences_will_change! if respond_to?(:preferences_will_change!)
|
92
|
-
end
|
69
|
+
define_singleton_method :defined_preferences do
|
70
|
+
super() + singleton_preferences
|
71
|
+
end
|
93
72
|
|
94
|
-
|
73
|
+
# cache_key will be nil for new objects, then if we check if there
|
74
|
+
# is a pending preference before going to default
|
75
|
+
define_method preference_getter_method(name) do
|
76
|
+
value = preferences.fetch(name) do
|
95
77
|
default.call(*context_for_default)
|
96
78
|
end
|
97
|
-
|
98
|
-
|
99
|
-
type
|
100
|
-
end
|
79
|
+
value = preference_encryptor.decrypt(value) if preference_encryptor.present?
|
80
|
+
value
|
101
81
|
end
|
102
82
|
|
103
|
-
|
104
|
-
|
105
|
-
|
83
|
+
define_method preference_setter_method(name) do |value|
|
84
|
+
value = convert_preference_value(value, type, preference_encryptor)
|
85
|
+
preferences[name] = value
|
106
86
|
|
107
|
-
|
108
|
-
|
87
|
+
# If this is an activerecord object, we need to inform
|
88
|
+
# ActiveRecord::Dirty that this value has changed, since this is an
|
89
|
+
# in-place update to the preferences hash.
|
90
|
+
preferences_will_change! if respond_to?(:preferences_will_change!)
|
109
91
|
end
|
110
92
|
|
111
|
-
|
112
|
-
|
93
|
+
define_method preference_default_getter_method(name) do
|
94
|
+
default.call(*context_for_default)
|
113
95
|
end
|
114
96
|
|
115
|
-
|
116
|
-
|
97
|
+
define_method preference_type_getter_method(name) do
|
98
|
+
type
|
117
99
|
end
|
100
|
+
end
|
118
101
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
Rails.application.credentials.secret_key_base
|
102
|
+
def preference_getter_method(name)
|
103
|
+
"preferred_#{name}".to_sym
|
104
|
+
end
|
123
105
|
|
124
|
-
|
125
|
-
|
106
|
+
def preference_setter_method(name)
|
107
|
+
"preferred_#{name}=".to_sym
|
108
|
+
end
|
126
109
|
|
127
|
-
|
128
|
-
#
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
#
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
110
|
+
def preference_default_getter_method(name)
|
111
|
+
"preferred_#{name}_default".to_sym
|
112
|
+
end
|
113
|
+
|
114
|
+
def preference_type_getter_method(name)
|
115
|
+
"preferred_#{name}_type".to_sym
|
116
|
+
end
|
117
|
+
|
118
|
+
def preference_encryptor(options)
|
119
|
+
key = options[:encryption_key] ||
|
120
|
+
ENV['IBRAIN_PREFERENCES_MASTER_KEY'] ||
|
121
|
+
Rails.application.credentials.secret_key_base
|
122
|
+
|
123
|
+
Ibrain::Encryptor.new(key)
|
124
|
+
end
|
125
|
+
|
126
|
+
# List of preference types allowed as form fields in the Ibrain admin
|
127
|
+
#
|
128
|
+
# Overwrite this method in your class that includes +Ibrain::Preferable+
|
129
|
+
# if you want to provide more fields. If you do so, you also need to provide
|
130
|
+
# a preference field partial that lives in:
|
131
|
+
#
|
132
|
+
# +app/views/Ibrain/admin/shared/preference_fields/+
|
133
|
+
#
|
134
|
+
# @return [Array]
|
135
|
+
def allowed_admin_form_preference_types
|
136
|
+
DEFAULT_ADMIN_FORM_PREFERENCE_TYPES
|
139
137
|
end
|
140
138
|
end
|
@@ -1,29 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
class
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
fail "'Ibrain.user_class' has not been set yet." unless Ibrain.user_class
|
3
|
+
# Configuration point for User model implementation.
|
4
|
+
#
|
5
|
+
# `Ibrain::UserClassHandle` allows you to configure your own implementation of a
|
6
|
+
# User class or use an extension like `ibrain-auth`.
|
7
|
+
#
|
8
|
+
# @note Placeholder for name of Ibrain.user_class to ensure later evaluation at
|
9
|
+
# runtime.
|
10
|
+
#
|
11
|
+
# Unfortunately, it is possible for classes to get loaded before
|
12
|
+
# Ibrain.user_class has been set in the initializer. As a result, they end up
|
13
|
+
# with class_name: "" in their association definitions. For obvious reasons,
|
14
|
+
# that doesn't work.
|
15
|
+
#
|
16
|
+
# For now, Rails does not call to_s on the instance passed in until runtime.
|
17
|
+
# So this little hack provides a wrapper around Ibrain.user_class so that we
|
18
|
+
# can basically lazy-evaluate it. Yay! Problem solved forever.
|
19
|
+
class Ibrain::UserClassHandle
|
20
|
+
# @return [String] the name of the user class as a string.
|
21
|
+
# @raise [RuntimeError] if Ibrain.user_class is nil
|
22
|
+
def to_s
|
23
|
+
fail "'Ibrain.user_class' has not been set yet." unless Ibrain.user_class
|
25
24
|
|
26
|
-
|
27
|
-
end
|
25
|
+
"::#{Ibrain.user_class}"
|
28
26
|
end
|
29
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibrain-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tai Nguyen Van
|
@@ -293,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
293
293
|
- !ruby/object:Gem::Version
|
294
294
|
version: '0'
|
295
295
|
requirements: []
|
296
|
-
rubygems_version: 3.
|
296
|
+
rubygems_version: 3.2.22
|
297
297
|
signing_key:
|
298
298
|
specification_version: 4
|
299
299
|
summary: Its Core is an sso authen gem for Ruby on Rails.
|