ibrain-core 0.4.5 → 0.4.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 +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
|
@@ -6,7 +6,12 @@ require:
|
|
|
6
6
|
- rubocop-graphql
|
|
7
7
|
|
|
8
8
|
AllCops:
|
|
9
|
-
|
|
9
|
+
Exclude:
|
|
10
|
+
- db/migrate/*.rb
|
|
11
|
+
- bin/*
|
|
12
|
+
- config/application.rb
|
|
13
|
+
- "**/vendor/**/*"
|
|
14
|
+
- vendor/eco-api-ruby
|
|
10
15
|
|
|
11
16
|
# We use class vars and will have to continue doing so for compatability
|
|
12
17
|
Style/ClassVars:
|
|
@@ -27,9 +32,6 @@ Naming/AccessorMethodName:
|
|
|
27
32
|
Style/MutableConstant:
|
|
28
33
|
Enabled: false
|
|
29
34
|
|
|
30
|
-
Style/ClassAndModuleChildren:
|
|
31
|
-
Enabled: false
|
|
32
|
-
|
|
33
35
|
Style/EmptyElse:
|
|
34
36
|
Enabled: false
|
|
35
37
|
|
|
@@ -49,7 +51,7 @@ Style/ConditionalAssignment:
|
|
|
49
51
|
Enabled: false
|
|
50
52
|
|
|
51
53
|
Performance/Count:
|
|
52
|
-
Enabled:
|
|
54
|
+
Enabled: true
|
|
53
55
|
|
|
54
56
|
Style/RaiseArgs:
|
|
55
57
|
Enabled: false
|
|
@@ -66,44 +68,44 @@ Style/AsciiComments:
|
|
|
66
68
|
Enabled: false
|
|
67
69
|
|
|
68
70
|
Layout/EndAlignment:
|
|
69
|
-
Enabled:
|
|
71
|
+
Enabled: true
|
|
70
72
|
|
|
71
73
|
Layout/ElseAlignment:
|
|
72
|
-
Enabled:
|
|
74
|
+
Enabled: true
|
|
73
75
|
|
|
74
76
|
Layout/IndentationWidth:
|
|
75
|
-
Enabled:
|
|
77
|
+
Enabled: true
|
|
76
78
|
|
|
77
79
|
Layout/ParameterAlignment:
|
|
78
|
-
Enabled:
|
|
80
|
+
Enabled: true
|
|
79
81
|
|
|
80
82
|
Layout/ClosingParenthesisIndentation:
|
|
81
|
-
Enabled:
|
|
83
|
+
Enabled: true
|
|
82
84
|
|
|
83
85
|
Layout/MultilineMethodCallIndentation:
|
|
84
|
-
Enabled:
|
|
86
|
+
Enabled: true
|
|
85
87
|
|
|
86
88
|
Layout/FirstArrayElementIndentation:
|
|
87
|
-
Enabled:
|
|
89
|
+
Enabled: true
|
|
88
90
|
|
|
89
91
|
Layout/FirstHashElementIndentation:
|
|
90
|
-
Enabled:
|
|
92
|
+
Enabled: true
|
|
91
93
|
|
|
92
94
|
Layout/HashAlignment:
|
|
93
|
-
Enabled:
|
|
95
|
+
Enabled: true
|
|
94
96
|
|
|
95
97
|
Style/TrailingCommaInArguments:
|
|
96
|
-
Enabled:
|
|
98
|
+
Enabled: true
|
|
97
99
|
|
|
98
100
|
Style/TrailingCommaInArrayLiteral:
|
|
99
|
-
Enabled:
|
|
101
|
+
Enabled: true
|
|
100
102
|
|
|
101
103
|
Style/TrailingCommaInHashLiteral:
|
|
102
|
-
Enabled:
|
|
104
|
+
Enabled: true
|
|
103
105
|
|
|
104
106
|
# Symbol Arrays are ok and the %i syntax widely unknown
|
|
105
107
|
Style/SymbolArray:
|
|
106
|
-
Enabled:
|
|
108
|
+
Enabled: true
|
|
107
109
|
|
|
108
110
|
Rails/DynamicFindBy:
|
|
109
111
|
Whitelist:
|
|
@@ -114,7 +116,7 @@ Rails/DynamicFindBy:
|
|
|
114
116
|
Rails/SkipsModelValidations:
|
|
115
117
|
Exclude:
|
|
116
118
|
- db/seeds/**/*.rb
|
|
117
|
-
-
|
|
119
|
+
- "*/spec/**/*"
|
|
118
120
|
|
|
119
121
|
# We use a lot of
|
|
120
122
|
#
|
|
@@ -125,13 +127,13 @@ Rails/SkipsModelValidations:
|
|
|
125
127
|
# syntax in the specs files.
|
|
126
128
|
Lint/AmbiguousBlockAssociation:
|
|
127
129
|
Exclude:
|
|
128
|
-
-
|
|
129
|
-
-
|
|
130
|
+
- "*/spec/**/*"
|
|
131
|
+
- "spec/**/*" # For the benefit of apps that inherit from this config
|
|
130
132
|
|
|
131
133
|
Security/Eval:
|
|
132
134
|
Exclude:
|
|
133
|
-
-
|
|
134
|
-
-
|
|
135
|
+
- "Gemfile"
|
|
136
|
+
- "*/Gemfile"
|
|
135
137
|
|
|
136
138
|
Naming/VariableNumber:
|
|
137
139
|
Enabled: false
|
|
@@ -235,7 +237,7 @@ Layout/SpaceInsideParens:
|
|
|
235
237
|
StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens
|
|
236
238
|
|
|
237
239
|
Style/SpecialGlobalVars:
|
|
238
|
-
Enabled:
|
|
240
|
+
Enabled: true
|
|
239
241
|
StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
|
|
240
242
|
|
|
241
243
|
Style/StringLiterals:
|
|
@@ -300,6 +302,9 @@ Style/FrozenStringLiteralComment:
|
|
|
300
302
|
Enabled: true
|
|
301
303
|
EnforcedStyle: always
|
|
302
304
|
|
|
305
|
+
Style/FetchEnvVar:
|
|
306
|
+
Enabled: true
|
|
307
|
+
|
|
303
308
|
# json.() is idiomatic in jbuilder files
|
|
304
309
|
Style/LambdaCall:
|
|
305
310
|
Enabled: false
|
|
@@ -315,7 +320,7 @@ Style/IdenticalConditionalBranches:
|
|
|
315
320
|
Enabled: false
|
|
316
321
|
|
|
317
322
|
Naming/MemoizedInstanceVariableName:
|
|
318
|
-
Enabled:
|
|
323
|
+
Enabled: true
|
|
319
324
|
|
|
320
325
|
Lint/BinaryOperatorWithIdenticalOperands:
|
|
321
326
|
Enabled: false
|
|
@@ -599,10 +604,7 @@ GraphQL/FieldDescription:
|
|
|
599
604
|
Enabled: false
|
|
600
605
|
|
|
601
606
|
GraphQL/ObjectDescription:
|
|
602
|
-
Enabled:
|
|
603
|
-
Exclude:
|
|
604
|
-
- app/graphql/policies/*.rb
|
|
605
|
-
- app/graphql/*.rb
|
|
607
|
+
Enabled: false
|
|
606
608
|
|
|
607
609
|
GraphQL/ExtractType:
|
|
608
610
|
Enabled: false
|
|
@@ -612,4 +614,55 @@ Rails/UnknownEnv:
|
|
|
612
614
|
- production
|
|
613
615
|
- development
|
|
614
616
|
- test
|
|
615
|
-
- staging
|
|
617
|
+
- staging
|
|
618
|
+
|
|
619
|
+
Style/MixinUsage:
|
|
620
|
+
Enabled: true
|
|
621
|
+
Exclude:
|
|
622
|
+
- db/seeds/*.rb
|
|
623
|
+
|
|
624
|
+
GraphQL/ExtractInputType:
|
|
625
|
+
Enabled: false
|
|
626
|
+
GraphQL/ArgumentDescription:
|
|
627
|
+
Enabled: false
|
|
628
|
+
|
|
629
|
+
Style/AccessorGrouping:
|
|
630
|
+
Enabled: true
|
|
631
|
+
|
|
632
|
+
Layout/AccessModifierIndentation:
|
|
633
|
+
Enabled: true
|
|
634
|
+
EnforcedStyle: indent
|
|
635
|
+
|
|
636
|
+
Layout/ArrayAlignment:
|
|
637
|
+
Enabled: true
|
|
638
|
+
|
|
639
|
+
Layout/ArgumentAlignment:
|
|
640
|
+
Enabled: true
|
|
641
|
+
|
|
642
|
+
Layout/ClassStructure:
|
|
643
|
+
Categories:
|
|
644
|
+
association:
|
|
645
|
+
- has_many
|
|
646
|
+
- has_one
|
|
647
|
+
attribute_macros:
|
|
648
|
+
- attr_accessor
|
|
649
|
+
- attr_reader
|
|
650
|
+
- attr_writer
|
|
651
|
+
macros:
|
|
652
|
+
- validates
|
|
653
|
+
- validate
|
|
654
|
+
module_inclusion:
|
|
655
|
+
- include
|
|
656
|
+
- prepend
|
|
657
|
+
- extend
|
|
658
|
+
Layout/IndentationConsistency:
|
|
659
|
+
EnforcedStyle: indented_internal_methods
|
|
660
|
+
|
|
661
|
+
Layout/InitialIndentation:
|
|
662
|
+
Enabled: true
|
|
663
|
+
|
|
664
|
+
Layout/IndentationStyle:
|
|
665
|
+
EnforcedStyle: spaces
|
|
666
|
+
|
|
667
|
+
Style/ClassAndModuleChildren:
|
|
668
|
+
EnforcedStyle: compact
|
|
@@ -20,56 +20,54 @@
|
|
|
20
20
|
require 'ibrain/preferences/configuration'
|
|
21
21
|
require 'ibrain/core/environment'
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
# Preferences (alphabetized to more easily lookup particular preferences)
|
|
23
|
+
class Ibrain::AppConfiguration < Ibrain::Preferences::Configuration
|
|
24
|
+
# Preferences (alphabetized to more easily lookup particular preferences)
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
# @!attribute [rw] guest_token_cookie_options
|
|
27
|
+
# @return [Hash] Add additional guest_token cookie options here (ie. domain or path)
|
|
28
|
+
preference :guest_token_cookie_options, :hash, default: {}
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
# @!attribute [rw] generate_api_key_for_all_roles
|
|
31
|
+
# @return [Boolean] Allow generating api key automatically for user
|
|
32
|
+
# at role_user creation for all roles. (default: +false+)
|
|
33
|
+
preference :generate_api_key_for_all_roles, :boolean, default: false
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
# @!attribute [rw] mails_from
|
|
36
|
+
# @return [String] Email address used as +From:+ field in transactional emails.
|
|
37
|
+
preference :mails_from, :string, default: 'ibrain@example.com'
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
preference :graphql_policy, :string, default: 'Ibrain::Policies::GraphqlPolicy'
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
# Api version for route config
|
|
42
|
+
preference :api_version, :string, default: 'v1'
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
# Graphql Schema name
|
|
45
|
+
preference :graphql_schema, :string, default: 'Ibrain::BaseSchema'
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
# Graphql Encryptor key
|
|
48
|
+
preference :ibrain_encryptor_key, :string, default: nil
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
# Parent controller
|
|
51
|
+
preference :parent_controller, :string, default: 'ActionController::API'
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
preference :master_database, :string, default: 'primary'
|
|
55
54
|
|
|
56
|
-
|
|
55
|
+
preference :graphql_max_depth, :integer, default: 3
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
preference :is_auto_append_mutation, :boolean, default: true
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
def static_model_preferences
|
|
60
|
+
@static_model_preferences ||= Ibrain::Preferences::StaticModelPreferences.new
|
|
61
|
+
end
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
end
|
|
63
|
+
def roles
|
|
64
|
+
@roles ||= Ibrain::RoleConfiguration.new.tap do |roles|
|
|
65
|
+
roles.assign_permissions :default, ['Ibrain::PermissionSets::DefaultCustomer']
|
|
66
|
+
roles.assign_permissions :admin, ['Ibrain::PermissionSets::SuperUser']
|
|
69
67
|
end
|
|
68
|
+
end
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
end
|
|
70
|
+
def environment
|
|
71
|
+
@environment ||= Ibrain::Core::Environment.new(self)
|
|
74
72
|
end
|
|
75
73
|
end
|
|
@@ -2,40 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
require 'active_support/core_ext/module'
|
|
4
4
|
|
|
5
|
-
module Ibrain
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@collection.each do |klass|
|
|
35
|
-
yield klass.constantize
|
|
36
|
-
end
|
|
37
|
-
end
|
|
5
|
+
module Ibrain::Core::ClassConstantizer
|
|
6
|
+
class Set
|
|
7
|
+
include Enumerable
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@collection = ::Set.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def <<(klass)
|
|
14
|
+
@collection << klass.to_s
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def concat(klasses)
|
|
18
|
+
klasses.each do |klass|
|
|
19
|
+
self << klass
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
self
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
delegate :clear, :empty?, to: :@collection
|
|
26
|
+
|
|
27
|
+
def delete(object)
|
|
28
|
+
@collection.delete(object.to_s)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def each
|
|
32
|
+
@collection.each do |klass|
|
|
33
|
+
yield klass.constantize
|
|
38
34
|
end
|
|
39
35
|
end
|
|
40
36
|
end
|
|
41
37
|
end
|
|
38
|
+
|
|
@@ -1,68 +1,62 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Ibrain
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
render_json_error(error, :unauthorized)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
rescue_from CanCan::AccessDenied do
|
|
31
|
-
instance_exec(&fallback_on_unauthorized)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
3
|
+
module Ibrain::Core::ControllerHelpers::Auth
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
include Response
|
|
6
|
+
|
|
7
|
+
# @!attribute [rw] fallback_on_unauthorized
|
|
8
|
+
# @!scope class
|
|
9
|
+
# Extension point for overriding behaviour of access denied errors.
|
|
10
|
+
# Default behaviour is to redirect back or to "/unauthorized" with a flash
|
|
11
|
+
# message.
|
|
12
|
+
# @return [Proc] action to take when access denied error is raised.
|
|
13
|
+
|
|
14
|
+
included do
|
|
15
|
+
before_action :set_guest_token
|
|
16
|
+
helper_method :try_ibrain_current_user
|
|
17
|
+
|
|
18
|
+
class_attribute :fallback_on_unauthorized
|
|
19
|
+
self.fallback_on_unauthorized = -> do
|
|
20
|
+
error = ::Struct.new(
|
|
21
|
+
message: I18n.t('ibrain.authorization_failure')
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
render_json_error(error, :unauthorized)
|
|
25
|
+
end
|
|
34
26
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
rescue_from CanCan::AccessDenied do
|
|
28
|
+
instance_exec(&fallback_on_unauthorized)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
39
31
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
# httponly: true
|
|
45
|
-
# )
|
|
46
|
-
# end
|
|
47
|
-
end
|
|
32
|
+
# Needs to be overriden so that we use Brain's Ability rather than anyone else's.
|
|
33
|
+
def current_ability
|
|
34
|
+
@current_ability ||= Ibrain::Ability.new(try_ibrain_current_user)
|
|
35
|
+
end
|
|
48
36
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
elsif respond_to?(:current_ibrain_user, true)
|
|
58
|
-
try(:current_ibrain_user)
|
|
59
|
-
end
|
|
60
|
-
rescue StandardError => e
|
|
61
|
-
Ibrain::Logger.warn e.message.to_s
|
|
37
|
+
def set_guest_token
|
|
38
|
+
# if cookies.signed[:guest_token].blank?
|
|
39
|
+
# cookies.permanent.signed[:guest_token] = Ibrain::Config[:guest_token_cookie_options].merge(
|
|
40
|
+
# value: SecureRandom.urlsafe_base64(nil, false),
|
|
41
|
+
# httponly: true
|
|
42
|
+
# )
|
|
43
|
+
# end
|
|
44
|
+
end
|
|
62
45
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
46
|
+
# proxy method to *possible* ibrain_current_user method
|
|
47
|
+
# Authentication extensions (such as ibrain-auth) are meant to provide ibrain_current_user
|
|
48
|
+
def try_ibrain_current_user
|
|
49
|
+
# This one will be defined by apps looking to hook into Ibrain
|
|
50
|
+
# As per authentication_helpers.rb
|
|
51
|
+
if respond_to?(:ibrain_current_user, true)
|
|
52
|
+
try(:ibrain_current_user)
|
|
53
|
+
# This one will be defined by Devise
|
|
54
|
+
elsif respond_to?(:current_ibrain_user, true)
|
|
55
|
+
try(:current_ibrain_user)
|
|
66
56
|
end
|
|
57
|
+
rescue StandardError => e
|
|
58
|
+
Ibrain::Logger.warn e.message.to_s
|
|
59
|
+
|
|
60
|
+
nil
|
|
67
61
|
end
|
|
68
62
|
end
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Ibrain
|
|
4
|
-
|
|
5
|
-
module ControllerHelpers
|
|
6
|
-
module CurrentHost
|
|
7
|
-
extend ActiveSupport::Concern
|
|
3
|
+
module Ibrain::Core::ControllerHelpers::CurrentHost
|
|
4
|
+
extend ActiveSupport::Concern
|
|
8
5
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
6
|
+
included do
|
|
7
|
+
before_action do
|
|
8
|
+
ActiveStorage::Current.host = request.base_url
|
|
15
9
|
end
|
|
16
10
|
end
|
|
17
11
|
end
|
|
@@ -1,53 +1,47 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Ibrain
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
message: message || I18n.t('ibrain.system.message.ok'),
|
|
47
|
-
data: data.as_json
|
|
48
|
-
}, status: :ok
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
3
|
+
module Ibrain::Core::ControllerHelpers::Response
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
helper_method :render_json_error
|
|
8
|
+
helper_method :render_json_ok
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
protected
|
|
12
|
+
|
|
13
|
+
def render_json_error(error, status)
|
|
14
|
+
e_message = error.try(:record).try(:errors).try(:full_messages).try(:first)
|
|
15
|
+
e_message = error.try(:message) if e_message.blank?
|
|
16
|
+
e_message = error.try(:details) if e_message.blank?
|
|
17
|
+
|
|
18
|
+
backtrace = error.try(:backtrace).try(:join, "\n")
|
|
19
|
+
|
|
20
|
+
Ibrain::Logger.error e_message
|
|
21
|
+
Ibrain::Logger.error backtrace
|
|
22
|
+
|
|
23
|
+
render json: {
|
|
24
|
+
errors: [{
|
|
25
|
+
message: e_message,
|
|
26
|
+
extensions: {
|
|
27
|
+
code: status,
|
|
28
|
+
exception: {
|
|
29
|
+
stacktrace: [
|
|
30
|
+
backtrace
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}],
|
|
35
|
+
message: e_message,
|
|
36
|
+
data: nil
|
|
37
|
+
}, status: status
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def render_json_ok(data, message, errors = [])
|
|
41
|
+
render json: {
|
|
42
|
+
errors: errors,
|
|
43
|
+
message: message || I18n.t('ibrain.system.message.ok'),
|
|
44
|
+
data: data.as_json
|
|
45
|
+
}, status: :ok
|
|
52
46
|
end
|
|
53
47
|
end
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Ibrain
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def permitted_attributes
|
|
8
|
-
Ibrain::PermittedAttributes
|
|
9
|
-
end
|
|
3
|
+
module Ibrain::Core::ControllerHelpers::StrongParameters
|
|
4
|
+
def permitted_attributes
|
|
5
|
+
Ibrain::PermittedAttributes
|
|
6
|
+
end
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
delegate(*Ibrain::PermittedAttributes::ATTRIBUTES,
|
|
9
|
+
to: :permitted_attributes,
|
|
10
|
+
prefix: :permitted)
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
12
|
+
def permitted_user_attributes
|
|
13
|
+
permitted_attributes.user_attributes
|
|
20
14
|
end
|
|
21
15
|
end
|
data/lib/ibrain/core/engine.rb
CHANGED
|
@@ -2,15 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
require 'ibrain/config'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
isolate_namespace Ibrain::Core
|
|
9
|
-
config.generators.api_only = true
|
|
5
|
+
class Ibrain::Core::Engine < ::Rails::Engine
|
|
6
|
+
isolate_namespace Ibrain::Core
|
|
7
|
+
config.generators.api_only = true
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
end
|
|
9
|
+
initializer "ibrain.environment", before: :load_config_initializers do |app|
|
|
10
|
+
app.config.ibrain = Ibrain::Config.environment
|
|
15
11
|
end
|
|
16
12
|
end
|