wallaby-core 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/wallaby/resources_controller.rb +6 -375
- data/app/security/ability.rb +1 -1
- data/config/locales/wallaby.en.yml +92 -128
- data/config/locales/wallaby_class.en.yml +0 -21
- data/lib/adaptors/wallaby/custom/model_service_provider.rb +8 -8
- data/lib/authorizers/wallaby/cancancan_authorization_provider.rb +2 -1
- data/lib/authorizers/wallaby/pundit_authorization_provider.rb +2 -2
- data/lib/concerns/wallaby/application_concern.rb +111 -0
- data/lib/concerns/wallaby/authentication_concern.rb +93 -0
- data/lib/concerns/wallaby/authorizable.rb +1 -1
- data/lib/concerns/wallaby/decoratable.rb +1 -1
- data/lib/concerns/wallaby/paginatable.rb +1 -1
- data/lib/concerns/wallaby/resourcable.rb +4 -0
- data/lib/concerns/wallaby/resources_concern.rb +433 -0
- data/lib/concerns/wallaby/servicable.rb +1 -1
- data/lib/errors/wallaby/model_not_found.rb +1 -1
- data/lib/errors/wallaby/resource_not_found.rb +1 -1
- data/lib/helpers/wallaby/application_helper.rb +6 -0
- data/lib/helpers/wallaby/form_helper.rb +2 -3
- data/lib/helpers/wallaby/index_helper.rb +2 -2
- data/lib/helpers/wallaby/links_helper.rb +5 -5
- data/lib/helpers/wallaby/styling_helper.rb +17 -3
- data/lib/interfaces/wallaby/mode.rb +2 -2
- data/lib/interfaces/wallaby/model_decorator.rb +1 -1
- data/lib/paginators/wallaby/model_paginator.rb +1 -1
- data/lib/routes/wallaby/resources_router.rb +1 -1
- data/lib/servicers/wallaby/model_servicer.rb +2 -1
- data/lib/services/wallaby/map/model_class_collector.rb +1 -1
- data/lib/services/wallaby/type_renderer.rb +2 -2
- data/lib/utils/wallaby/locale.rb +53 -0
- data/lib/utils/wallaby/logger.rb +21 -0
- data/lib/utils/wallaby/model_utils.rb +1 -1
- data/lib/utils/wallaby/module_utils.rb +1 -1
- data/lib/utils/wallaby/utils.rb +1 -1
- data/lib/wallaby/core.rb +6 -0
- data/lib/wallaby/core/version.rb +1 -1
- data/lib/wallaby/engine.rb +3 -3
- data/lib/wallaby/map.rb +1 -1
- metadata +7 -4
- data/app/controllers/wallaby/application_controller.rb +0 -84
- data/app/controllers/wallaby/secure_controller.rb +0 -81
@@ -1,84 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Wallaby
|
4
|
-
# Like ordinary Rails application, it's the base controller that
|
5
|
-
# other Wallaby controllers inherit from.
|
6
|
-
#
|
7
|
-
# However, the difference is that the controller class that {Wallaby::ApplicationController} inherits from
|
8
|
-
# can be configured via {Wallaby::Configuration#base_controller}
|
9
|
-
#
|
10
|
-
# Here, it provides the most basic functions e.g. error handling for common 4xx HTTP status, helpers method,
|
11
|
-
# and URL handling.
|
12
|
-
class ApplicationController < configuration.base_controller
|
13
|
-
extend Engineable::ClassMethods
|
14
|
-
include Engineable
|
15
|
-
include SharedHelpers
|
16
|
-
helper ApplicationHelper
|
17
|
-
|
18
|
-
rescue_from NotFound, with: :not_found
|
19
|
-
rescue_from ::ActionController::ParameterMissing, with: :bad_request
|
20
|
-
rescue_from ::ActiveRecord::StatementInvalid, with: :unprocessable_entity
|
21
|
-
rescue_from NotImplemented, with: :not_implemented
|
22
|
-
rescue_from UnprocessableEntity, with: :unprocessable_entity
|
23
|
-
|
24
|
-
delegate(*ConfigurationHelper.instance_methods(false), :url_for, to: :helpers)
|
25
|
-
|
26
|
-
# Health check page for e.g. NewRelic
|
27
|
-
def healthy
|
28
|
-
render plain: 'healthy'
|
29
|
-
end
|
30
|
-
|
31
|
-
# Not found page
|
32
|
-
# @param exception [Exception] comes from **rescue_from**
|
33
|
-
def not_found(exception = nil)
|
34
|
-
render_error exception, __callee__
|
35
|
-
end
|
36
|
-
|
37
|
-
# Bad request page
|
38
|
-
# @param exception [Exception] comes from **rescue_from**
|
39
|
-
def bad_request(exception = nil)
|
40
|
-
render_error exception, __callee__
|
41
|
-
end
|
42
|
-
|
43
|
-
# Unprocessable entity page
|
44
|
-
# @param exception [Exception] comes from **rescue_from**
|
45
|
-
def unprocessable_entity(exception = nil)
|
46
|
-
render_error exception, __callee__
|
47
|
-
end
|
48
|
-
|
49
|
-
# Internal server error page
|
50
|
-
# @param exception [Exception] comes from **rescue_from**
|
51
|
-
def internal_server_error(exception = nil)
|
52
|
-
render_error exception, __callee__
|
53
|
-
end
|
54
|
-
|
55
|
-
# Not implemented
|
56
|
-
# @param exception [Exception] comes from **rescue_from**
|
57
|
-
def not_implemented(exception = nil)
|
58
|
-
render_error exception, __callee__
|
59
|
-
end
|
60
|
-
|
61
|
-
# {https://api.rubyonrails.org/classes/ActionController/Helpers.html#method-i-helpers helpers}
|
62
|
-
# exists since Rails 5.0, need to mimic this to support Rails 4.2.
|
63
|
-
# @see https://api.rubyonrails.org/classes/ActionController/Helpers.html#method-i-helpers
|
64
|
-
# ActionController::Helpers#helpers
|
65
|
-
# @see https://github.com/rails/rails/blob/5-0-stable/actionpack/lib/action_controller/metal/helpers.rb#L118
|
66
|
-
def helpers
|
67
|
-
@helpers ||= defined?(super) ? super : view_context
|
68
|
-
end
|
69
|
-
|
70
|
-
protected
|
71
|
-
|
72
|
-
# Capture exceptions and display the error using error template.
|
73
|
-
# @param exception [Exception]
|
74
|
-
# @param symbol [Symbol] http status symbol
|
75
|
-
def render_error(exception, symbol)
|
76
|
-
Rails.logger.error exception
|
77
|
-
|
78
|
-
@exception = exception
|
79
|
-
@symbol = symbol
|
80
|
-
@code = Rack::Utils::SYMBOL_TO_STATUS_CODE[symbol].to_i
|
81
|
-
respond_with @exception, status: @code, template: ERROR_PATH, prefixes: _prefixes
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Wallaby
|
4
|
-
# This is the controller with only authentication logics.
|
5
|
-
class SecureController < ::Wallaby::ApplicationController
|
6
|
-
helper SecureHelper
|
7
|
-
helper_method :current_user
|
8
|
-
|
9
|
-
rescue_from NotAuthenticated, with: :unauthorized
|
10
|
-
rescue_from Forbidden, with: :forbidden
|
11
|
-
|
12
|
-
# Unauthorized page.
|
13
|
-
# @param exception [Exception] exception comes from `rescue_from`
|
14
|
-
def unauthorized(exception = nil)
|
15
|
-
render_error exception, __callee__
|
16
|
-
end
|
17
|
-
|
18
|
-
# Forbidden page.
|
19
|
-
# @param exception [Exception] exception comes from `rescue_from`
|
20
|
-
def forbidden(exception = nil)
|
21
|
-
render_error exception, __callee__
|
22
|
-
end
|
23
|
-
|
24
|
-
# @note This is a template method that can be overridden by subclasses
|
25
|
-
# This {current_user} method will try to looking up the actual implementation from the following
|
26
|
-
# places from high precedence to low:
|
27
|
-
#
|
28
|
-
# - {Wallaby::Configuration::Security#current_user}
|
29
|
-
# - `super`
|
30
|
-
# - do nothing
|
31
|
-
#
|
32
|
-
# It can be replaced completely in subclasses:
|
33
|
-
#
|
34
|
-
# ```
|
35
|
-
# def current_user
|
36
|
-
# # NOTE: please ensure `@current_user` is assigned, for instance:
|
37
|
-
# @current_user ||= User.new params.slice(:email)
|
38
|
-
# end
|
39
|
-
# ```
|
40
|
-
# @return [Object] a user object
|
41
|
-
def current_user
|
42
|
-
@current_user ||=
|
43
|
-
if security.current_user? || !defined? super
|
44
|
-
instance_exec(&security.current_user)
|
45
|
-
else
|
46
|
-
super
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# @note This is a template method that can be overridden by subclasses
|
51
|
-
# This {authenticate_user!} method will try to looking up the actual implementation from the following
|
52
|
-
# places from high precedence to low:
|
53
|
-
#
|
54
|
-
# - {Wallaby::Configuration::Security#authenticate}
|
55
|
-
# - `super`
|
56
|
-
# - do nothing
|
57
|
-
#
|
58
|
-
# It can be replaced completely in subclasses:
|
59
|
-
#
|
60
|
-
# ```
|
61
|
-
# def authenticate_user!
|
62
|
-
# authenticate_or_request_with_http_basic do |username, password|
|
63
|
-
# username == 'too_simple' && password == 'too_naive'
|
64
|
-
# end
|
65
|
-
# end
|
66
|
-
# ```
|
67
|
-
# @return [true] when user is authenticated successfully
|
68
|
-
# @raise [Wallaby::NotAuthenticated] when user fails to authenticate
|
69
|
-
def authenticate_user!
|
70
|
-
authenticated =
|
71
|
-
if security.authenticate? || !defined? super
|
72
|
-
instance_exec(&security.authenticate)
|
73
|
-
else
|
74
|
-
super
|
75
|
-
end
|
76
|
-
raise NotAuthenticated unless authenticated
|
77
|
-
|
78
|
-
true
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|