ibrain-core 0.4.6 → 0.4.7
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 +14 -12
- data/app/controllers/ibrain/core/graphql_controller.rb +83 -79
- data/app/graphql/ibrain/base_schema.rb +52 -50
- data/app/graphql/ibrain/extentions/default_value.rb +11 -7
- data/app/graphql/ibrain/extentions/roles.rb +20 -15
- data/app/graphql/ibrain/extentions/session_required.rb +14 -10
- data/app/graphql/ibrain/lazy/base.rb +6 -2
- data/app/graphql/ibrain/loaders/association_loader.rb +55 -51
- data/app/graphql/ibrain/mutations/base_mutation.rb +56 -52
- data/app/graphql/ibrain/policies/base_policy.rb +47 -43
- data/app/graphql/ibrain/policies/graphql_policy.rb +6 -2
- data/app/graphql/ibrain/resolvers/base_aggregate.rb +10 -6
- data/app/graphql/ibrain/resolvers/base_resolver.rb +12 -8
- data/app/graphql/ibrain/types/aggregate_type.rb +8 -4
- data/app/graphql/ibrain/types/attribute_type.rb +5 -2
- data/app/graphql/ibrain/types/base_api_connection.rb +10 -6
- data/app/graphql/ibrain/types/base_api_edge.rb +8 -4
- data/app/graphql/ibrain/types/base_api_field.rb +11 -7
- data/app/graphql/ibrain/types/base_api_object.rb +10 -6
- data/app/graphql/ibrain/types/base_argument.rb +7 -3
- data/app/graphql/ibrain/types/base_connection.rb +11 -7
- data/app/graphql/ibrain/types/base_edge.rb +7 -3
- data/app/graphql/ibrain/types/base_enum.rb +5 -1
- data/app/graphql/ibrain/types/base_field.rb +10 -6
- data/app/graphql/ibrain/types/base_input_object.rb +10 -6
- data/app/graphql/ibrain/types/base_interface.rb +9 -5
- data/app/graphql/ibrain/types/base_object.rb +16 -12
- data/app/graphql/ibrain/types/base_scalar.rb +5 -1
- data/app/graphql/ibrain/types/base_type.rb +10 -4
- data/app/graphql/ibrain/types/base_union.rb +7 -3
- data/app/graphql/ibrain/types/filter_type.rb +5 -1
- data/app/graphql/ibrain/types/node_type.rb +8 -4
- data/app/graphql/ibrain/util/field_combiner.rb +9 -5
- data/app/graphql/ibrain/util/query_combiner.rb +8 -4
- data/app/models/concerns/ibrain/soft_deletable.rb +8 -6
- data/app/models/concerns/ibrain/user_api_authentication.rb +16 -14
- data/app/models/concerns/ibrain/user_methods.rb +13 -11
- data/app/models/ibrain/ability.rb +32 -31
- data/app/models/ibrain/aggregate.rb +7 -5
- data/app/models/ibrain/application_record.rb +4 -2
- data/app/models/ibrain/legacy_user.rb +13 -7
- data/app/models/ibrain/role.rb +8 -6
- data/app/models/ibrain/role_user.rb +10 -8
- data/app/repositories/ibrain/base_repository.rb +11 -9
- data/lib/generators/ibrain/core/model_generator.rb +21 -17
- data/lib/generators/ibrain/graphql/core.rb +59 -55
- data/lib/generators/ibrain/graphql/mutation_generator.rb +66 -58
- data/lib/generators/ibrain/graphql/object_generator.rb +70 -58
- data/lib/generators/ibrain/graphql/resolver_generator.rb +25 -17
- data/lib/generators/ibrain/graphql/resolvers_generator.rb +67 -59
- data/lib/generators/ibrain/graphql/templates/aggregate.erb +7 -5
- data/lib/generators/ibrain/graphql/templates/input.erb +9 -5
- data/lib/generators/ibrain/graphql/templates/mutation.erb +26 -24
- data/lib/generators/ibrain/graphql/templates/object.erb +10 -6
- data/lib/generators/ibrain/graphql/templates/resolver.erb +11 -9
- data/lib/generators/ibrain/graphql/templates/resolvers.erb +10 -8
- data/lib/generators/ibrain/graphql/type_generator.rb +88 -84
- data/lib/generators/ibrain/install/install_generator.rb +140 -137
- data/lib/generators/ibrain/install/templates/graphql/types/mutation_type.rb.tt +15 -13
- data/lib/generators/ibrain/install/templates/graphql/types/query_type.rb.tt +13 -11
- data/lib/generators/ibrain/install/templates/rubocop.yml.tt +30 -83
- data/lib/ibrain/app_configuration.rb +36 -34
- data/lib/ibrain/core/class_constantizer.rb +33 -30
- data/lib/ibrain/core/controller_helpers/auth.rb +59 -53
- data/lib/ibrain/core/controller_helpers/current_host.rb +11 -5
- data/lib/ibrain/core/controller_helpers/response.rb +49 -43
- data/lib/ibrain/core/controller_helpers/strong_parameters.rb +15 -9
- data/lib/ibrain/core/engine.rb +9 -5
- data/lib/ibrain/core/environment.rb +9 -5
- data/lib/ibrain/core/environment_extension.rb +17 -13
- data/lib/ibrain/core/role_configuration.rb +54 -52
- data/lib/ibrain/core/validators/email.rb +17 -15
- data/lib/ibrain/core/version.rb +2 -2
- data/lib/ibrain/core/versioned_value.rb +65 -61
- data/lib/ibrain/encryptor.rb +20 -18
- data/lib/ibrain/logger.rb +15 -13
- data/lib/ibrain/permission_sets/base.rb +26 -22
- data/lib/ibrain/permission_sets/super_user.rb +7 -3
- data/lib/ibrain/permitted_attributes.rb +20 -18
- data/lib/ibrain/preferences/configuration.rb +137 -135
- data/lib/ibrain/preferences/preferable.rb +162 -158
- data/lib/ibrain/preferences/preferable_class_methods.rb +114 -112
- data/lib/ibrain/user_class_handle.rb +24 -22
- data/lib/ibrain_core.rb +1 -7
- metadata +1 -1
|
@@ -6,12 +6,7 @@ require:
|
|
|
6
6
|
- rubocop-graphql
|
|
7
7
|
|
|
8
8
|
AllCops:
|
|
9
|
-
|
|
10
|
-
- db/migrate/*.rb
|
|
11
|
-
- bin/*
|
|
12
|
-
- config/application.rb
|
|
13
|
-
- "**/vendor/**/*"
|
|
14
|
-
- vendor/eco-api-ruby
|
|
9
|
+
TargetRubyVersion: 2.5
|
|
15
10
|
|
|
16
11
|
# We use class vars and will have to continue doing so for compatability
|
|
17
12
|
Style/ClassVars:
|
|
@@ -32,6 +27,9 @@ Naming/AccessorMethodName:
|
|
|
32
27
|
Style/MutableConstant:
|
|
33
28
|
Enabled: false
|
|
34
29
|
|
|
30
|
+
Style/ClassAndModuleChildren:
|
|
31
|
+
Enabled: false
|
|
32
|
+
|
|
35
33
|
Style/EmptyElse:
|
|
36
34
|
Enabled: false
|
|
37
35
|
|
|
@@ -51,7 +49,7 @@ Style/ConditionalAssignment:
|
|
|
51
49
|
Enabled: false
|
|
52
50
|
|
|
53
51
|
Performance/Count:
|
|
54
|
-
Enabled:
|
|
52
|
+
Enabled: false
|
|
55
53
|
|
|
56
54
|
Style/RaiseArgs:
|
|
57
55
|
Enabled: false
|
|
@@ -68,44 +66,44 @@ Style/AsciiComments:
|
|
|
68
66
|
Enabled: false
|
|
69
67
|
|
|
70
68
|
Layout/EndAlignment:
|
|
71
|
-
Enabled:
|
|
69
|
+
Enabled: false
|
|
72
70
|
|
|
73
71
|
Layout/ElseAlignment:
|
|
74
|
-
Enabled:
|
|
72
|
+
Enabled: false
|
|
75
73
|
|
|
76
74
|
Layout/IndentationWidth:
|
|
77
|
-
Enabled:
|
|
75
|
+
Enabled: false
|
|
78
76
|
|
|
79
77
|
Layout/ParameterAlignment:
|
|
80
|
-
Enabled:
|
|
78
|
+
Enabled: false
|
|
81
79
|
|
|
82
80
|
Layout/ClosingParenthesisIndentation:
|
|
83
|
-
Enabled:
|
|
81
|
+
Enabled: false
|
|
84
82
|
|
|
85
83
|
Layout/MultilineMethodCallIndentation:
|
|
86
|
-
Enabled:
|
|
84
|
+
Enabled: false
|
|
87
85
|
|
|
88
86
|
Layout/FirstArrayElementIndentation:
|
|
89
|
-
Enabled:
|
|
87
|
+
Enabled: false
|
|
90
88
|
|
|
91
89
|
Layout/FirstHashElementIndentation:
|
|
92
|
-
Enabled:
|
|
90
|
+
Enabled: false
|
|
93
91
|
|
|
94
92
|
Layout/HashAlignment:
|
|
95
|
-
Enabled:
|
|
93
|
+
Enabled: false
|
|
96
94
|
|
|
97
95
|
Style/TrailingCommaInArguments:
|
|
98
|
-
Enabled:
|
|
96
|
+
Enabled: false
|
|
99
97
|
|
|
100
98
|
Style/TrailingCommaInArrayLiteral:
|
|
101
|
-
Enabled:
|
|
99
|
+
Enabled: false
|
|
102
100
|
|
|
103
101
|
Style/TrailingCommaInHashLiteral:
|
|
104
|
-
Enabled:
|
|
102
|
+
Enabled: false
|
|
105
103
|
|
|
106
104
|
# Symbol Arrays are ok and the %i syntax widely unknown
|
|
107
105
|
Style/SymbolArray:
|
|
108
|
-
Enabled:
|
|
106
|
+
Enabled: false
|
|
109
107
|
|
|
110
108
|
Rails/DynamicFindBy:
|
|
111
109
|
Whitelist:
|
|
@@ -116,7 +114,7 @@ Rails/DynamicFindBy:
|
|
|
116
114
|
Rails/SkipsModelValidations:
|
|
117
115
|
Exclude:
|
|
118
116
|
- db/seeds/**/*.rb
|
|
119
|
-
-
|
|
117
|
+
- '*/spec/**/*'
|
|
120
118
|
|
|
121
119
|
# We use a lot of
|
|
122
120
|
#
|
|
@@ -127,13 +125,13 @@ Rails/SkipsModelValidations:
|
|
|
127
125
|
# syntax in the specs files.
|
|
128
126
|
Lint/AmbiguousBlockAssociation:
|
|
129
127
|
Exclude:
|
|
130
|
-
-
|
|
131
|
-
-
|
|
128
|
+
- '*/spec/**/*'
|
|
129
|
+
- 'spec/**/*' # For the benefit of apps that inherit from this config
|
|
132
130
|
|
|
133
131
|
Security/Eval:
|
|
134
132
|
Exclude:
|
|
135
|
-
-
|
|
136
|
-
-
|
|
133
|
+
- 'Gemfile'
|
|
134
|
+
- '*/Gemfile'
|
|
137
135
|
|
|
138
136
|
Naming/VariableNumber:
|
|
139
137
|
Enabled: false
|
|
@@ -237,7 +235,7 @@ Layout/SpaceInsideParens:
|
|
|
237
235
|
StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens
|
|
238
236
|
|
|
239
237
|
Style/SpecialGlobalVars:
|
|
240
|
-
Enabled:
|
|
238
|
+
Enabled: false
|
|
241
239
|
StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
|
|
242
240
|
|
|
243
241
|
Style/StringLiterals:
|
|
@@ -302,9 +300,6 @@ Style/FrozenStringLiteralComment:
|
|
|
302
300
|
Enabled: true
|
|
303
301
|
EnforcedStyle: always
|
|
304
302
|
|
|
305
|
-
Style/FetchEnvVar:
|
|
306
|
-
Enabled: true
|
|
307
|
-
|
|
308
303
|
# json.() is idiomatic in jbuilder files
|
|
309
304
|
Style/LambdaCall:
|
|
310
305
|
Enabled: false
|
|
@@ -320,7 +315,7 @@ Style/IdenticalConditionalBranches:
|
|
|
320
315
|
Enabled: false
|
|
321
316
|
|
|
322
317
|
Naming/MemoizedInstanceVariableName:
|
|
323
|
-
Enabled:
|
|
318
|
+
Enabled: false
|
|
324
319
|
|
|
325
320
|
Lint/BinaryOperatorWithIdenticalOperands:
|
|
326
321
|
Enabled: false
|
|
@@ -604,7 +599,10 @@ GraphQL/FieldDescription:
|
|
|
604
599
|
Enabled: false
|
|
605
600
|
|
|
606
601
|
GraphQL/ObjectDescription:
|
|
607
|
-
Enabled:
|
|
602
|
+
Enabled: true
|
|
603
|
+
Exclude:
|
|
604
|
+
- app/graphql/policies/*.rb
|
|
605
|
+
- app/graphql/*.rb
|
|
608
606
|
|
|
609
607
|
GraphQL/ExtractType:
|
|
610
608
|
Enabled: false
|
|
@@ -614,55 +612,4 @@ Rails/UnknownEnv:
|
|
|
614
612
|
- production
|
|
615
613
|
- development
|
|
616
614
|
- test
|
|
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
|
|
615
|
+
- staging
|
|
@@ -20,54 +20,56 @@
|
|
|
20
20
|
require 'ibrain/preferences/configuration'
|
|
21
21
|
require 'ibrain/core/environment'
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
module Ibrain
|
|
24
|
+
class AppConfiguration < Preferences::Configuration
|
|
25
|
+
# Preferences (alphabetized to more easily lookup particular preferences)
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
# @!attribute [rw] guest_token_cookie_options
|
|
28
|
+
# @return [Hash] Add additional guest_token cookie options here (ie. domain or path)
|
|
29
|
+
preference :guest_token_cookie_options, :hash, default: {}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
# @!attribute [rw] generate_api_key_for_all_roles
|
|
32
|
+
# @return [Boolean] Allow generating api key automatically for user
|
|
33
|
+
# at role_user creation for all roles. (default: +false+)
|
|
34
|
+
preference :generate_api_key_for_all_roles, :boolean, default: false
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
# @!attribute [rw] mails_from
|
|
37
|
+
# @return [String] Email address used as +From:+ field in transactional emails.
|
|
38
|
+
preference :mails_from, :string, default: 'ibrain@example.com'
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
preference :graphql_policy, :string, default: 'Ibrain::Policies::GraphqlPolicy'
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
# Api version for route config
|
|
43
|
+
preference :api_version, :string, default: 'v1'
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
# Graphql Schema name
|
|
46
|
+
preference :graphql_schema, :string, default: 'Ibrain::BaseSchema'
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
# Graphql Encryptor key
|
|
49
|
+
preference :ibrain_encryptor_key, :string, default: nil
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
# Parent controller
|
|
52
|
+
preference :parent_controller, :string, default: 'ActionController::API'
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
preference :master_database, :string, default: 'primary'
|
|
54
55
|
|
|
55
|
-
|
|
56
|
+
preference :graphql_max_depth, :integer, default: 3
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
preference :is_auto_append_mutation, :boolean, default: true
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
def static_model_preferences
|
|
61
|
+
@static_model_preferences ||= Ibrain::Preferences::StaticModelPreferences.new
|
|
62
|
+
end
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
def roles
|
|
65
|
+
@roles ||= Ibrain::RoleConfiguration.new.tap do |roles|
|
|
66
|
+
roles.assign_permissions :default, ['Ibrain::PermissionSets::DefaultCustomer']
|
|
67
|
+
roles.assign_permissions :admin, ['Ibrain::PermissionSets::SuperUser']
|
|
68
|
+
end
|
|
67
69
|
end
|
|
68
|
-
end
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
def environment
|
|
72
|
+
@environment ||= Ibrain::Core::Environment.new(self)
|
|
73
|
+
end
|
|
72
74
|
end
|
|
73
75
|
end
|
|
@@ -2,37 +2,40 @@
|
|
|
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
|
-
|
|
5
|
+
module Ibrain
|
|
6
|
+
module Core
|
|
7
|
+
module ClassConstantizer
|
|
8
|
+
class Set
|
|
9
|
+
include Enumerable
|
|
10
|
+
|
|
11
|
+
def initialize
|
|
12
|
+
@collection = ::Set.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def <<(klass)
|
|
16
|
+
@collection << klass.to_s
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def concat(klasses)
|
|
20
|
+
klasses.each do |klass|
|
|
21
|
+
self << klass
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
self
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
delegate :clear, :empty?, to: :@collection
|
|
28
|
+
|
|
29
|
+
def delete(object)
|
|
30
|
+
@collection.delete(object.to_s)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def each
|
|
34
|
+
@collection.each do |klass|
|
|
35
|
+
yield klass.constantize
|
|
36
|
+
end
|
|
37
|
+
end
|
|
34
38
|
end
|
|
35
39
|
end
|
|
36
40
|
end
|
|
37
41
|
end
|
|
38
|
-
|
|
@@ -1,62 +1,68 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Ibrain
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
3
|
+
module Ibrain
|
|
4
|
+
module Core
|
|
5
|
+
module ControllerHelpers
|
|
6
|
+
module Auth
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
include Response
|
|
26
9
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
10
|
+
# @!attribute [rw] fallback_on_unauthorized
|
|
11
|
+
# @!scope class
|
|
12
|
+
# Extension point for overriding behaviour of access denied errors.
|
|
13
|
+
# Default behaviour is to redirect back or to "/unauthorized" with a flash
|
|
14
|
+
# message.
|
|
15
|
+
# @return [Proc] action to take when access denied error is raised.
|
|
31
16
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
end
|
|
17
|
+
included do
|
|
18
|
+
before_action :set_guest_token
|
|
19
|
+
helper_method :try_ibrain_current_user
|
|
36
20
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
# )
|
|
43
|
-
# end
|
|
44
|
-
end
|
|
21
|
+
class_attribute :fallback_on_unauthorized
|
|
22
|
+
self.fallback_on_unauthorized = -> do
|
|
23
|
+
error = ::Struct.new(
|
|
24
|
+
message: I18n.t('ibrain.authorization_failure')
|
|
25
|
+
)
|
|
45
26
|
|
|
46
|
-
|
|
47
|
-
|
|
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)
|
|
56
|
-
end
|
|
57
|
-
rescue StandardError => e
|
|
58
|
-
Ibrain::Logger.warn e.message.to_s
|
|
27
|
+
render_json_error(error, :unauthorized)
|
|
28
|
+
end
|
|
59
29
|
|
|
60
|
-
|
|
30
|
+
rescue_from CanCan::AccessDenied do
|
|
31
|
+
instance_exec(&fallback_on_unauthorized)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Needs to be overriden so that we use Brain's Ability rather than anyone else's.
|
|
36
|
+
def current_ability
|
|
37
|
+
@current_ability ||= Ibrain::Ability.new(try_ibrain_current_user)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def set_guest_token
|
|
41
|
+
# if cookies.signed[:guest_token].blank?
|
|
42
|
+
# cookies.permanent.signed[:guest_token] = Ibrain::Config[:guest_token_cookie_options].merge(
|
|
43
|
+
# value: SecureRandom.urlsafe_base64(nil, false),
|
|
44
|
+
# httponly: true
|
|
45
|
+
# )
|
|
46
|
+
# end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# proxy method to *possible* ibrain_current_user method
|
|
50
|
+
# Authentication extensions (such as ibrain-auth) are meant to provide ibrain_current_user
|
|
51
|
+
def try_ibrain_current_user
|
|
52
|
+
# This one will be defined by apps looking to hook into Ibrain
|
|
53
|
+
# As per authentication_helpers.rb
|
|
54
|
+
if respond_to?(:ibrain_current_user, true)
|
|
55
|
+
try(:ibrain_current_user)
|
|
56
|
+
# This one will be defined by Devise
|
|
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
|
|
62
|
+
|
|
63
|
+
nil
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
61
67
|
end
|
|
62
68
|
end
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Ibrain
|
|
4
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module Core
|
|
5
|
+
module ControllerHelpers
|
|
6
|
+
module CurrentHost
|
|
7
|
+
extend ActiveSupport::Concern
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
included do
|
|
10
|
+
before_action do
|
|
11
|
+
ActiveStorage::Current.host = request.base_url
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
9
15
|
end
|
|
10
16
|
end
|
|
11
17
|
end
|
|
@@ -1,47 +1,53 @@
|
|
|
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
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module Core
|
|
5
|
+
module ControllerHelpers
|
|
6
|
+
module Response
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
helper_method :render_json_error
|
|
11
|
+
helper_method :render_json_ok
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
protected
|
|
15
|
+
|
|
16
|
+
def render_json_error(error, status)
|
|
17
|
+
e_message = error.try(:record).try(:errors).try(:full_messages).try(:first)
|
|
18
|
+
e_message = error.try(:message) if e_message.blank?
|
|
19
|
+
e_message = error.try(:details) if e_message.blank?
|
|
20
|
+
|
|
21
|
+
backtrace = error.try(:backtrace).try(:join, "\n")
|
|
22
|
+
|
|
23
|
+
Ibrain::Logger.error e_message
|
|
24
|
+
Ibrain::Logger.error backtrace
|
|
25
|
+
|
|
26
|
+
render json: {
|
|
27
|
+
errors: [{
|
|
28
|
+
message: e_message,
|
|
29
|
+
extensions: {
|
|
30
|
+
code: status,
|
|
31
|
+
exception: {
|
|
32
|
+
stacktrace: [
|
|
33
|
+
backtrace
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}],
|
|
38
|
+
message: e_message,
|
|
39
|
+
data: nil
|
|
40
|
+
}, status: status
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def render_json_ok(data, message, errors = [])
|
|
44
|
+
render json: {
|
|
45
|
+
errors: errors,
|
|
46
|
+
message: message || I18n.t('ibrain.system.message.ok'),
|
|
47
|
+
data: data.as_json
|
|
48
|
+
}, status: :ok
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
46
52
|
end
|
|
47
53
|
end
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Ibrain
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module Core
|
|
5
|
+
module ControllerHelpers
|
|
6
|
+
module StrongParameters
|
|
7
|
+
def permitted_attributes
|
|
8
|
+
Ibrain::PermittedAttributes
|
|
9
|
+
end
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
delegate(*Ibrain::PermittedAttributes::ATTRIBUTES,
|
|
12
|
+
to: :permitted_attributes,
|
|
13
|
+
prefix: :permitted)
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
def permitted_user_attributes
|
|
16
|
+
permitted_attributes.user_attributes
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
14
20
|
end
|
|
15
21
|
end
|
data/lib/ibrain/core/engine.rb
CHANGED
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
require 'ibrain/config'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
module Ibrain
|
|
6
|
+
module Core
|
|
7
|
+
class Engine < ::Rails::Engine
|
|
8
|
+
isolate_namespace Ibrain::Core
|
|
9
|
+
config.generators.api_only = true
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
initializer "ibrain.environment", before: :load_config_initializers do |app|
|
|
12
|
+
app.config.ibrain = Ibrain::Config.environment
|
|
13
|
+
end
|
|
14
|
+
end
|
|
11
15
|
end
|
|
12
16
|
end
|