rails_base 0.52.1 → 0.54.0

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/rails_base/application.js +0 -1
  3. data/app/controllers/rails_base/admin_controller.rb +2 -1
  4. data/app/helpers/rails_base/appearance_helper.rb +2 -2
  5. data/app/helpers/rails_base/application_helper.rb +1 -1
  6. data/app/mailers/rails_base/email_verification_mailer.rb +3 -3
  7. data/app/mailers/rails_base/event_mailer.rb +2 -2
  8. data/app/models/rails_base/application_record.rb +1 -1
  9. data/app/models/short_lived_data.rb +2 -2
  10. data/app/models/user.rb +2 -2
  11. data/app/services/rails_base/admin_update_attribute.rb +1 -1
  12. data/app/services/rails_base/authentication/single_sign_on_send.rb +6 -3
  13. data/app/views/layouts/rails_base/application.html.erb +31 -2
  14. data/app/views/rails_base/devise/registrations/new.html.erb +1 -1
  15. data/app/views/rails_base/email_verification_mailer/email_verification.html.erb +1 -1
  16. data/app/views/rails_base/email_verification_mailer/event.html.erb +1 -1
  17. data/app/views/rails_base/mfa_auth/mfa_code.html.erb +1 -0
  18. data/app/views/rails_base/shared/_appearance_mode_selector.html.erb +7 -3
  19. data/config/initializers/switch_user.rb +1 -1
  20. data/lib/rails_base/admin/default_index_tile.rb +0 -1
  21. data/lib/rails_base/config.rb +3 -0
  22. data/lib/rails_base/configuration/admin.rb +10 -2
  23. data/lib/rails_base/configuration/app.rb +5 -5
  24. data/lib/rails_base/configuration/appearance.rb +21 -11
  25. data/lib/rails_base/configuration/display/back_to_top.rb +20 -0
  26. data/lib/rails_base/configuration/display/bg_light.rb +25 -0
  27. data/lib/rails_base/configuration/display/card.rb +24 -0
  28. data/lib/rails_base/configuration/display/footer.rb +1 -1
  29. data/lib/rails_base/configuration/display/text.rb +0 -1
  30. data/lib/rails_base/engine.rb +13 -12
  31. data/lib/rails_base/version.rb +2 -2
  32. data/lib/rails_base.rb +22 -1
  33. data/lib/velocity_limiter.rb +6 -1
  34. metadata +6 -4
  35. data/app/assets/javascripts/rails_base/cable.js +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f233f2247fd157198f76161529bca1bb88d55fee96b45104eaaa013882584c6
4
- data.tar.gz: d5512bc281ea3ebef98bf1fd4cb8afd1f8c115494c2086f28ed305c0d7761916
3
+ metadata.gz: fe27d75cdddcc15a030ab4fa65a259e47cf05f2213495291b29aca0b31ea1bbf
4
+ data.tar.gz: 88fa8e22d35ffaf1357341ce223873a86ea313f0a628fdc9b1710583df358126
5
5
  SHA512:
6
- metadata.gz: 0ee1fea7d46172fa3f51475c01b6accfa4e725182e46de18b3c0f4697a5f2e932036be43cd945461ddf6985ba250ffd3163d3c79df2dfabe57c4fd2a496b9e64
7
- data.tar.gz: 17c9610469692e46e1c664f6bfea0a031de650090e8963c45986d5002fa86df9ed96c46eb29eadb9664c73b36e98123f0f3313090a448afb973d76d5048166c2
6
+ metadata.gz: 9b0b2c4d3685e8030655c05d294b25bc27740e547354eeb69400fbcb2383a84b515b3275493cea85315ddda0bd4417891098afd5620f0d1934e24f54b8f3d831
7
+ data.tar.gz: 2d1dab3b919b1b0b3534aa613b2aa40b79f6b34bc8f594602856d2266ba524f833616fee4f3a7fd474a7f7814e4dc5667ed455feaa11029a6f2365cfda3119bc
@@ -11,7 +11,6 @@
11
11
  // about supported directives.
12
12
  //
13
13
  // = require rails-ujs
14
- // = require activestorage
15
14
  // = require turbolinks
16
15
  // = require_tree .
17
16
 
@@ -298,7 +298,8 @@ module RailsBase
298
298
  session.delete(RailsBase::Authentication::Constants::ADMIN_REMEMBER_REASON)
299
299
 
300
300
  flash[:notice] = 'You no longer have an identity crisis. You are back to normal.'
301
- redirect_to RailsBase.url_routes.admin_base_path
301
+ redirect_url = RailsBase.config.admin.admin_impersonate_return.call(request, params)
302
+ redirect_to redirect_url
302
303
  end
303
304
 
304
305
  private
@@ -1,6 +1,6 @@
1
1
  module RailsBase::AppearanceHelper
2
- APPEARANCE_MODE_COOKIE = "_#{Rails.application.class.parent_name}_appearance_mode".gsub(' ', '-').downcase
3
- APPEARANCE_MODE_ACTUAL_COOKIE = "_#{Rails.application.class.parent_name}_appearance_actual_mode".gsub(' ', '-').downcase
2
+ APPEARANCE_MODE_COOKIE = "_#{RailsBase.app_name}_appearance_mode".gsub(' ', '-').downcase
3
+ APPEARANCE_MODE_ACTUAL_COOKIE = "_#{RailsBase.app_name}_appearance_actual_mode".gsub(' ', '-').downcase
4
4
  APPEARANCE_TEXT_CLASS = RailsBase::Configuration::Display::Text::APPEARANCE_TEXT_CLASS
5
5
 
6
6
  VIEWPORT_EXTRA_SMALL = 'xs'.freeze
@@ -1,6 +1,6 @@
1
1
  module RailsBase::ApplicationHelper
2
2
 
3
- TIMEZONE_OFFSET_COOKIE = "_#{Rails.application.class.parent_name}_timeoffset"
3
+ TIMEZONE_OFFSET_COOKIE = "_#{RailsBase.app_name}_timeoffset"
4
4
  TIMEZONE_SESSION_NAME = TIMEZONE_THREAD_NAME = :tz_info
5
5
 
6
6
  def browser
@@ -4,19 +4,19 @@ class RailsBase::EmailVerificationMailer < RailsBase::ApplicationMailer
4
4
  def email_verification(user:, url:)
5
5
  @user = user
6
6
  @sso_url_for_user = url
7
- mail(to: @user.email, subject: "Welcome to #{Rails.application.class.parent_name}")
7
+ mail(to: @user.email, subject: "Welcome to #{RailsBase.app_name}")
8
8
  end
9
9
 
10
10
  def forgot_password(user:, url:)
11
11
  @user = user
12
12
  @sso_url_for_user = url
13
- mail(to: @user.email, subject: "#{Rails.application.class.parent_name}: Forgot Password")
13
+ mail(to: @user.email, subject: "#{RailsBase.app_name}: Forgot Password")
14
14
  end
15
15
 
16
16
  def event(user:, event:, msg: nil)
17
17
  @user = user
18
18
  @event = event
19
19
  @msg = msg
20
- mail(to: @user.email, subject: "#{Rails.application.class.parent_name}: #{event}")
20
+ mail(to: @user.email, subject: "#{RailsBase.app_name}: #{event}")
21
21
  end
22
22
  end
@@ -4,13 +4,13 @@ class RailsBase::EventMailer < RailsBase::ApplicationMailer
4
4
  def send_sso(user:, message:)
5
5
  @user = user
6
6
  @message = message
7
- mail(to: user.email, subject: "#{Rails.application.class.parent_name}: SSO login", template_name: 'event')
7
+ mail(to: user.email, subject: "#{RailsBase.app_name}: SSO login", template_name: 'event')
8
8
  # event(user: user, event: 'SSO login', message: message)
9
9
  end
10
10
 
11
11
  def event(user:, event:, message:)
12
12
  @user = user
13
13
  @message = message
14
- mail(to: @user.email, subject: "#{Rails.application.class.parent_name}: #{event}", template_name: 'event')
14
+ mail(to: @user.email, subject: "#{RailsBase.app_name}: #{event}", template_name: 'event')
15
15
  end
16
16
  end
@@ -6,7 +6,7 @@ module RailsBase
6
6
  columns.each do |column|
7
7
  next unless [:datetime].include?(column.type)
8
8
 
9
- # This is actually pretty cool. If you set the thrad corectly, you can
9
+ # This is actually pretty cool. If you set the thread corectly, you can
10
10
  define_method("#{column.name}") do
11
11
  thread_tz = Thread.current[RailsBase::ApplicationController::TIMEZONE_THREAD_NAME]
12
12
  return super() if thread_tz.nil?
@@ -97,7 +97,7 @@ class ShortLivedData < RailsBase::ApplicationRecord
97
97
  # only update if count is valid and we can add things -- save db call
98
98
  return false unless used_count_valid?
99
99
 
100
- update_attributes(exclusive_use_count: exclusive_use_count + 1)
100
+ update(exclusive_use_count: exclusive_use_count + 1)
101
101
  end
102
102
 
103
103
  def invalid_reason
@@ -126,7 +126,7 @@ class ShortLivedData < RailsBase::ApplicationRecord
126
126
  end
127
127
 
128
128
  def user=(u)
129
- update_attributes(user_id: u.id)
129
+ update(user_id: u.id)
130
130
  u.id
131
131
  end
132
132
  end
data/app/models/user.rb CHANGED
@@ -50,7 +50,7 @@ class User < RailsBase::ApplicationRecord
50
50
  end
51
51
 
52
52
  define_method("admin_#{admin_method}!") do
53
- update_attributes!(admin: admin_method)
53
+ update!(admin: admin_method)
54
54
  end
55
55
 
56
56
  #### metods on the class
@@ -109,7 +109,7 @@ class User < RailsBase::ApplicationRecord
109
109
  return if last_known_timezone == tz_name
110
110
 
111
111
  Rails.logger.info { "#{id}: Setting tz_name: #{tz_name}" }
112
- update_attributes(last_known_timezone: tz_name, last_known_timezone_update: Time.now )
112
+ update(last_known_timezone: tz_name, last_known_timezone_update: Time.now )
113
113
  end
114
114
 
115
115
  def timezone
@@ -14,7 +14,7 @@ module RailsBase
14
14
 
15
15
  original_value = model_row.public_send(attribute)
16
16
  begin
17
- model_row.update_attributes!(attribute => sanitized_value)
17
+ model_row.update!(attribute => sanitized_value)
18
18
  rescue ActiveRecord::RecordInvalid => e
19
19
  context.fail!(message: "Failed to update [#{attribute}] with #{sanitized_value} on #{model}##{model_row.id}. #{e.message}")
20
20
  rescue StandardError
@@ -9,6 +9,7 @@ module RailsBase::Authentication
9
9
  delegate :reason, to: :context
10
10
  delegate :token_type, to: :context
11
11
  delegate :url_redirect, to: :context
12
+ delegate :msg_proc, to: :context
12
13
 
13
14
  SSO_DECISION_TWILIO = :twilio
14
15
  SSO_DECISION_EMAIL = :email
@@ -38,17 +39,19 @@ module RailsBase::Authentication
38
39
  case sso_decision_type
39
40
  when SSO_DECISION_TWILIO
40
41
  context.sso_destination = :sms
41
- send_to_twilio!(message: message(url: url))
42
+ send_to_twilio!(message: message(url: url, full_name: user.full_name))
42
43
  when SSO_DECISION_EMAIL
43
44
  context.sso_destination = :email
44
- send_to_email!(message: message(url: url))
45
+ send_to_email!(message: message(url: url, full_name: user.full_name))
45
46
  end
46
47
  end
47
48
 
48
49
  # This method is expected to be overridden by the main app
49
50
  # This is the default message
50
51
  # Might consider shipping this to a locales that can be easily overridden in downstream app
51
- def message(url:)
52
+ def message(url:, full_name:)
53
+ return msg_proc.call(url, full_name) if msg_proc.is_a?(Proc)
54
+
52
55
  "Hello #{user.full_name}. This is your SSO link to your favorite site.\n#{url}"
53
56
  end
54
57
 
@@ -20,6 +20,7 @@
20
20
  <link href="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/css/bootstrap4-toggle.min.css" rel="stylesheet">
21
21
  <script src="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/js/bootstrap4-toggle.min.js"></script>
22
22
  <script src="https://unpkg.com/sticky-table-headers"></script>
23
+ <script src="https://kit.fontawesome.com/3b649de495.js" crossorigin="anonymous"></script>
23
24
 
24
25
  <%=
25
26
  if RailsBase.config.app.favicon_path
@@ -31,7 +32,7 @@
31
32
  <body>
32
33
  <script type="text/javascript">
33
34
  // Load at top so available for rest of body oddy
34
- function set_cookie(name, value, path ) {
35
+ function set_cookie(name, value, path) {
35
36
  path ||= '/'
36
37
  document.cookie = `${name}=${value}; path=${path}`
37
38
  }
@@ -126,6 +127,34 @@
126
127
  <% end %>
127
128
  </div>
128
129
 
130
+ <% if RailsBase.appearance.back_to_top.enable? %>
131
+ <a id="rails-base-back-to-top" class="btn btn-light btn-lg back-to-top" role="button"><i class="fas fa-chevron-up"></i></a>
132
+ <script type="text/javascript">
133
+ $(document).ready(function(){
134
+ $(window).scroll(function () {
135
+ if ($(this).scrollTop() > 100) {
136
+ $('#rails-base-back-to-top').fadeIn();
137
+ } else {
138
+ $('#rails-base-back-to-top').fadeOut();
139
+ }
140
+ });
141
+ $('#rails-base-back-to-top').click(function () {
142
+ $('body,html').animate({
143
+ scrollTop: 0
144
+ }, 400);
145
+ });
146
+ });
147
+ </script>
148
+ <style type="text/css">
149
+ .back-to-top {
150
+ position: fixed;
151
+ bottom: 50px;
152
+ right: 25px;
153
+ display: none;
154
+ }
155
+ </style>
156
+ <% end %>
157
+
129
158
  <script>
130
159
  modify_layout();
131
160
  function _rails_base_display_success(msg){
@@ -168,7 +197,7 @@
168
197
 
169
198
  // Attempt to set timezone on every request
170
199
  set_cookie('<%= RailsBase::ApplicationController::TIMEZONE_OFFSET_COOKIE %>', new Date().getTimezoneOffset())
171
- });
200
+ });
172
201
  <% end %>
173
202
  <% if Rails.env == 'production' %>
174
203
  // Disable console logging
@@ -69,7 +69,7 @@
69
69
  <div class="col-md-10 offset-md-1 text-center">
70
70
  <div class="row">
71
71
  <div class="col-md-9">
72
- <%= f.submit "Sign Up for #{Rails.application.class.parent_name}", class: "btn btn_success btn-block #{submit_klass}" %>
72
+ <%= f.submit "Sign Up for #{RailsBase.app_name}", class: "btn btn_success btn-block #{submit_klass}" %>
73
73
  </div>
74
74
  <div class="col-md-3">
75
75
  <a class="btn btn_primary btn-block" href="<%=RailsBase.url_routes.new_user_session_path%>" role="button">Have an Account? Sign In</a>
@@ -7,7 +7,7 @@
7
7
  </br>
8
8
  </br>
9
9
  Best wishes,</br>
10
- <%= Rails.application.class.parent_name %> team
10
+ <%= RailsBase.app_name %> team
11
11
 
12
12
  </p>
13
13
  </br>
@@ -9,7 +9,7 @@
9
9
  </p>
10
10
  <% end %>
11
11
  <p>
12
- If this is in error please login to your account: <a href=<%= RailsBase::ApplicationMailer::CONTACT_URL %>> Login link for <%= Rails.application.class.parent_name %> </a>
12
+ If this is in error please login to your account: <a href=<%= RailsBase::ApplicationMailer::CONTACT_URL %>> Login link for <%= RailsBase.app_name %> </a>
13
13
  </p>
14
14
 
15
15
  </br>
@@ -8,3 +8,4 @@
8
8
  </div>
9
9
  </div>
10
10
  </div>
11
+
@@ -111,6 +111,11 @@
111
111
  '<%= dark %>': '<%= RailsBase.appearance.text.dark_mode %>',
112
112
  '<%= light %>': '<%= RailsBase.appearance.text.light_mode %>'
113
113
  },
114
+ {
115
+ 'descriptor': '.card',
116
+ '<%= dark %>': '<%= RailsBase.appearance.card.dark_mode %>',
117
+ '<%= light %>': '<%= RailsBase.appearance.card.light_mode %>'
118
+ },
114
119
  // buttons
115
120
  <% RailsBase.appearance.class::BUTTONS.each do |klass| %>
116
121
  {
@@ -119,7 +124,6 @@
119
124
  '<%= light %>': '<%= RailsBase.appearance.dig(klass, :light_mode) %>'
120
125
  },
121
126
  <% end %>
122
-
123
127
  ]
124
128
 
125
129
  function toggle_dark_mode(set_key){
@@ -146,7 +150,7 @@
146
150
  set_and_toggle_mode(value)
147
151
  })
148
152
  // This function MUST be called outside of document ready
149
- // to ensure dark mode does not activate after docuemnt is loaded
153
+ // to ensure dark mode does not activate after document is loaded
150
154
  set_and_toggle_mode( `<%= cookies[RailsBase::ApplicationController::APPEARANCE_MODE_COOKIE] || RailsBase.appearance.default_mode %>`)
151
155
  $('#appearance_mode_selector').appendTo('body');
152
156
  $(document).ready(function(){
@@ -180,4 +184,4 @@
180
184
  set_and_toggle_mode(get_cookie(cookie_name))
181
185
  });
182
186
  </script>
183
- <% end %>
187
+ <% end %>
@@ -41,7 +41,7 @@ SwitchUser.setup do |config|
41
41
 
42
42
  # redirect_path is a block, it returns which page will be redirected
43
43
  # after switching a user.
44
- config.redirect_path = ->(_request, _params) { RailsBase.url_routes.authenticated_root_path }
44
+ config.redirect_path = ->(request, params) { RailsBase.config.admin.admin_impersonate_redirect.call(request, params) }
45
45
 
46
46
  # helper_with_guest is a boolean value, if it set to false
47
47
  # the guest item in the helper won't be shown
@@ -144,7 +144,6 @@ params = {
144
144
  instance = RailsBase::Admin::IndexTile.new(**params)
145
145
  RailsBase::Admin::IndexTile.add(instance)
146
146
 
147
-
148
147
  # Impersonation Tile
149
148
  params = {
150
149
  type: :button,
@@ -1,3 +1,4 @@
1
+ require 'singleton'
1
2
  require 'rails_base/configuration/admin'
2
3
  require 'rails_base/configuration/mfa'
3
4
  require 'rails_base/configuration/authentication'
@@ -13,6 +14,8 @@ require 'rails_base/configuration/active_job'
13
14
 
14
15
  module RailsBase
15
16
  class Config
17
+ include Singleton
18
+
16
19
  VARIABLES = {
17
20
  admin: nil,
18
21
  mfa: nil,
@@ -190,6 +190,16 @@ module RailsBase
190
190
  default: ENV.fetch('ADMIN_VELOCITY_FRAME', 5).to_i.hours,
191
191
  description: 'Debug purposes. How long to keep admin_velocity_max attempts',
192
192
  },
193
+ admin_impersonate_redirect:{
194
+ type: :proc,
195
+ default: ->(_request, _params) { RailsBase.url_routes.authenticated_root_path },
196
+ description: 'Redirection to impersonation -- Landing page when having an identity cris',
197
+ },
198
+ admin_impersonate_return:{
199
+ type: :proc,
200
+ default: ->(_request, _params) { RailsBase.url_routes.admin_base_path },
201
+ description: 'Redirection from impersonation -- Page to return from when you have found yourself',
202
+ }
193
203
  }
194
204
 
195
205
  attr_accessor *DEFAULT_VALUES.keys
@@ -211,8 +221,6 @@ module RailsBase
211
221
  admin_page_filter.flatten!
212
222
  end
213
223
 
214
- private
215
-
216
224
  def convenience_methods
217
225
  # defines instance methods like
218
226
  # user.at_least_super?
@@ -16,27 +16,27 @@ module RailsBase
16
16
  },
17
17
  web_name_logged_in: {
18
18
  type: :string_proc,
19
- default: ->(user) { Rails.application.class.parent_name },
19
+ default: ->(user) { RailsBase.app_name },
20
20
  description: 'Name of the application when authenticated user is present. Name in the tab of the browser. Allows for dynamic tab names'
21
21
  },
22
22
  web_name_logged_out: {
23
23
  type: :string_proc,
24
- default: ->(*) { Rails.application.class.parent_name },
24
+ default: ->(*) { RailsBase.app_name },
25
25
  description: 'Name of the application when no authenticated user. Name in the tab of the browser. Allows for dynamic tab names'
26
26
  },
27
27
  web_title_logged_in: {
28
28
  type: :string_proc,
29
- default: ->(user) { Rails.application.class.parent_name },
29
+ default: ->(user) { RailsBase.app_name },
30
30
  description: 'Title in nav for the web when logged in. String or proc accepted. When proc, current user will be passed in.'
31
31
  },
32
32
  web_title_logged_out: {
33
33
  type: :string_proc,
34
- default: ->(*) { Rails.application.class.parent_name },
34
+ default: ->(*) { RailsBase.app_name },
35
35
  description: 'Title in nav for the web when logged in. String or proc accepted. When proc, current user will be passed in.'
36
36
  },
37
37
  communication_name: {
38
38
  type: :string_proc,
39
- default: ->(*) { Rails.application.class.parent_name },
39
+ default: ->(*) { RailsBase.app_name },
40
40
  description: 'Name used when communicating with users.'
41
41
  },
42
42
  favicon_path: {
@@ -1,18 +1,22 @@
1
1
  require 'rails_base/configuration/base'
2
- require 'rails_base/configuration/display/table_header'
3
- require 'rails_base/configuration/display/table_body'
2
+ require 'rails_base/configuration/display/back_to_top'
4
3
  require 'rails_base/configuration/display/background_color'
5
- require 'rails_base/configuration/display/navbar'
6
- require 'rails_base/configuration/display/text'
7
- require 'rails_base/configuration/display/footer'
4
+ require 'rails_base/configuration/display/btn_danger'
5
+ require 'rails_base/configuration/display/btn_dark'
6
+ require 'rails_base/configuration/display/btn_info'
7
+ require 'rails_base/configuration/display/btn_light'
8
8
  require 'rails_base/configuration/display/btn_primary'
9
9
  require 'rails_base/configuration/display/btn_secondary'
10
10
  require 'rails_base/configuration/display/btn_success'
11
- require 'rails_base/configuration/display/btn_danger'
12
11
  require 'rails_base/configuration/display/btn_warning'
13
- require 'rails_base/configuration/display/btn_info'
14
- require 'rails_base/configuration/display/btn_light'
15
- require 'rails_base/configuration/display/btn_dark'
12
+ require 'rails_base/configuration/display/footer'
13
+ require 'rails_base/configuration/display/navbar'
14
+ require 'rails_base/configuration/display/table_body'
15
+ require 'rails_base/configuration/display/table_header'
16
+ require 'rails_base/configuration/display/text'
17
+ require 'rails_base/configuration/display/card'
18
+ require 'rails_base/configuration/display/card'
19
+ require 'rails_base/configuration/display/bg_light'
16
20
 
17
21
  module RailsBase
18
22
  module Configuration
@@ -26,6 +30,8 @@ module RailsBase
26
30
  :btn_info,
27
31
  :btn_light,
28
32
  :btn_dark,
33
+ :bg_light,
34
+
29
35
  ]
30
36
 
31
37
  DOWNSTREAM_CLASSES = [
@@ -34,11 +40,12 @@ module RailsBase
34
40
  :bg_color,
35
41
  :navbar,
36
42
  :text,
43
+ :card,
37
44
  :footer,
38
-
45
+ :back_to_top,
39
46
  ] + BUTTONS
40
47
 
41
- SKIP_DOWNSTREAM_CLASSES = [:footer]
48
+ SKIP_DOWNSTREAM_CLASSES = [:footer, :back_to_top]
42
49
  DARK_MODE = :dark
43
50
  LIGHT_MODE = :light
44
51
  MATCH_OS = :match_os
@@ -83,7 +90,10 @@ module RailsBase
83
90
  @bg_color = Configuration::Display::BackgroundColor.new
84
91
  @navbar = Configuration::Display::Navbar.new
85
92
  @text = Configuration::Display::Text.new
93
+ @card = Configuration::Display::Card.new
86
94
  @footer = Configuration::Display::Footer.new
95
+ @back_to_top = Configuration::Display::BackTotop.new
96
+ @bg_light = Configuration::Display::BgLight.new
87
97
 
88
98
  @btn_primary = Configuration::Display::BtnPrimary.new
89
99
  @btn_secondary = Configuration::Display::BtnSecondary.new
@@ -0,0 +1,20 @@
1
+ require 'rails_base/configuration/base'
2
+
3
+ module RailsBase
4
+ module Configuration
5
+ module Display
6
+ class BackTotop < Base
7
+
8
+ DEFAULT_VALUES = {
9
+ enable: {
10
+ type: :boolean,
11
+ default: true,
12
+ description: 'Enable Back to top icon on all pages',
13
+ },
14
+ }
15
+
16
+ attr_accessor *DEFAULT_VALUES.keys
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ require 'rails_base/configuration/base'
2
+
3
+ module RailsBase
4
+ module Configuration
5
+ module Display
6
+ class BgLight < Base
7
+
8
+ DEFAULT_VALUES = {
9
+ dark_mode: {
10
+ type: :string_nil,
11
+ default: 'bg-secondary',
12
+ description: 'Background to use in Dark mode'
13
+ },
14
+ light_mode: {
15
+ type: :string_nil,
16
+ default: 'bg-light',
17
+ description: 'Background to use in light mode'
18
+ },
19
+ }
20
+
21
+ attr_accessor *DEFAULT_VALUES.keys
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails_base/configuration/base'
2
+
3
+ module RailsBase
4
+ module Configuration
5
+ module Display
6
+ class Card < Base
7
+ DEFAULT_VALUES = {
8
+ dark_mode: {
9
+ type: :string_nil,
10
+ default: 'bg-dark',
11
+ description: 'Color of card for dark mode: https://getbootstrap.com/docs/4.0/utilities/colors/'
12
+ },
13
+ light_mode: {
14
+ type: :string_nil,
15
+ default: '',
16
+ description: 'Color of card for light mode : https://getbootstrap.com/docs/4.0/utilities/colors/'
17
+ },
18
+ }
19
+
20
+ attr_accessor *DEFAULT_VALUES.keys
21
+ end
22
+ end
23
+ end
24
+ end
@@ -12,7 +12,7 @@ module RailsBase
12
12
  'RailsBase::MfaAuthController' => [:mfa_code],
13
13
  'RailsBase::SecondaryAuthenticationController' => [:static, :after_email_login_session_new, :forgot_password],
14
14
  }
15
- DEFAULT_FOOTER_HTML = "© 2021 Year of the Rona: Bad Ass Rails Starter <a href='https://github.com/matt-taylor/' target='_blank'>@matt-taylor</a>"
15
+ DEFAULT_FOOTER_HTML = "© #{DateTime.now.year} Year of the Rona: Bad Ass Rails Starter built by <a href='https://github.com/matt-taylor/' target='_blank'>@matt-taylor</a>"
16
16
 
17
17
  DEFAULT_VALUES = {
18
18
  enable: {
@@ -15,7 +15,6 @@ module RailsBase
15
15
  type: :string_nil,
16
16
  default: 'text-dark',
17
17
  description: 'Color of text for light mode. Text that is outside of standard elems (tables, navbars): https://getbootstrap.com/docs/4.0/utilities/colors/'
18
-
19
18
  },
20
19
  }
21
20
 
@@ -1,18 +1,26 @@
1
1
  module RailsBase
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace RailsBase
4
+ ActiveSupport::Reloader.to_prepare do
5
+ if RailsBase.___execute_initializer___?
6
+ RailsBase.config.admin.convenience_methods
7
+
8
+ RailsBase::ApplicationRecord.descendants.each do |model|
9
+ model._magically_defined_time_objects
10
+ end
11
+ end
12
+ end
4
13
 
5
14
  initializer 'instantiate RailsBase configs' do |_app|
6
- RailsBase.config if ___execute_initializer___?
15
+ RailsBase.config if RailsBase.___execute_initializer___?
7
16
  end
8
17
 
9
18
  initializer 'remove write access to RailsBase config', after: 'after_initialize' do |app|
10
- RailsBase::Configuration::Base._unset_allow_write! if ___execute_initializer___?
19
+ RailsBase::Configuration::Base._unset_allow_write! if RailsBase.___execute_initializer___?
11
20
  end
12
21
 
13
22
  initializer 'define magic convenionce methods for converting team', after: 'active_record.initialize_database' do |app|
14
- if ___execute_initializer___?
15
- raise
23
+ if RailsBase.___execute_initializer___?
16
24
  # need to eager load Models
17
25
  Rails.application.eager_load!
18
26
 
@@ -39,13 +47,6 @@ module RailsBase
39
47
  end
40
48
  end
41
49
 
42
- def ___execute_initializer___?
43
- # Only execute when not doing DB actions
44
- boolean = defined?(ARGV) ? true : false # for when no ARGVs are provided, we know its a railsc or rails s explicit
45
- boolean = false if boolean && ARGV[0]&.include?('db') # when its the DB rake tasks
46
- boolean = false if boolean && ARGV[0]&.include?('asset') # when its an asset
47
- boolean = false if boolean && ARGV[0]&.include?(':') # else this delim should never be included
48
- boolean = false if ENV['SKIP_CUSTOM_INIT']=='true' # explicitly set the variable to skip shit
49
- end
50
+
50
51
  end
51
52
  end
@@ -1,7 +1,7 @@
1
1
  module RailsBase
2
2
  MAJOR = '0'
3
- MINOR = '52'
4
- PATCH = '1'
3
+ MINOR = '54'
4
+ PATCH = '0'
5
5
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
6
6
 
7
7
  def self.print_version
data/lib/rails_base.rb CHANGED
@@ -17,10 +17,31 @@ require 'rails_base/admin/action_cache'
17
17
  require 'rails_base/config'
18
18
 
19
19
  module RailsBase
20
+
21
+ # Rails 6 does not play nice with this function -- Find a different work around
22
+ def self.___execute_initializer___?
23
+ # Only execute when not doing DB actions
24
+ boolean = defined?(ARGV) ? true : false # for when no ARGVs are provided, we know its a railsc or rails s explicit
25
+ boolean = false if boolean && ARGV[0]&.include?('db') # when its the DB rake tasks
26
+ boolean = false if boolean && ARGV[0]&.include?('asset') # when its an asset
27
+ boolean = false if boolean && ARGV[0]&.include?(':') # else this delim should never be included
28
+ boolean = false if ENV['SKIP_CUSTOM_INIT']=='true' # explicitly set the variable to skip shit
29
+
30
+ boolean
31
+ end
32
+
20
33
  def self.url_routes
21
34
  Rails.application.routes.url_helpers
22
35
  end
23
36
 
37
+ def self.app_name
38
+ if ::Rails::VERSION::MAJOR >= 6
39
+ ::Rails.application.class.module_parent_name
40
+ else
41
+ ::Rails.application.class.parent_name
42
+ end
43
+ end
44
+
24
45
  def self.route_exist?(path)
25
46
  Rails.application.routes.recognize_path(path)
26
47
  true
@@ -35,7 +56,7 @@ module RailsBase
35
56
  end
36
57
 
37
58
  def self.config
38
- @config ||= RailsBase::Config.new
59
+ @config ||= RailsBase::Config.instance
39
60
  end
40
61
 
41
62
  def self.appearance
@@ -9,7 +9,7 @@ module VelocityLimiter
9
9
  if metadata[:velocity_reached]
10
10
  log(level: :warn, msg: "#{cache_key} has been velocity limited. #{metadata[:within_attempts_count]} attempts since #{metadata[:threshold]}. MAX allowed is #{velocity_max}")
11
11
  log(level: :warn, msg: "#{cache_key} may try again in #{metadata[:to_words]} :: #{metadata[:attempt_again_at]}. Will fully reset at #{metadata[:fully_reset_time]}")
12
- msg = "Velocity limit reached for SMS verification. You may try again in #{metadata[:to_words]}"
12
+ msg = velocity_limit_message(metadata: metadata)
13
13
  return {reached: true, msg: msg}
14
14
  end
15
15
 
@@ -35,6 +35,10 @@ module VelocityLimiter
35
35
  def velocity_frame
36
36
  end
37
37
 
38
+ def velocity_limit_message(metadata:)
39
+ "Velocity limit reached for SMS verification. You may try again in #{metadata[:to_words]}"
40
+ end
41
+
38
42
  def cache_delineator
39
43
  ','
40
44
  end
@@ -57,6 +61,7 @@ module VelocityLimiter
57
61
  obj[:velocity_reached] = within_attempts.count >= velocity_max
58
62
  obj[:within_attempts_arr] = within_attempts
59
63
  obj[:within_attempts_count] = within_attempts.count
64
+ obj[:attempts_remaining] = velocity_max - obj[:vl_write].count
60
65
  obj[:threshold] = threshold
61
66
  obj[:velocity_max] = velocity_max
62
67
  obj[:velocity_frame] = velocity_frame
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.52.1
4
+ version: 0.54.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Taylor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-02 00:00:00.000000000 Z
11
+ date: 2021-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -409,7 +409,6 @@ files:
409
409
  - app/assets/images/rails_base/favicon.ico
410
410
  - app/assets/javascripts/rails_base/admin.js
411
411
  - app/assets/javascripts/rails_base/application.js
412
- - app/assets/javascripts/rails_base/cable.js
413
412
  - app/assets/javascripts/rails_base/mfa_auth.coffee
414
413
  - app/assets/javascripts/rails_base/secondary_authentication.coffee
415
414
  - app/assets/javascripts/rails_base/sessions.js
@@ -568,7 +567,9 @@ files:
568
567
  - lib/rails_base/configuration/appearance.rb
569
568
  - lib/rails_base/configuration/authentication.rb
570
569
  - lib/rails_base/configuration/base.rb
570
+ - lib/rails_base/configuration/display/back_to_top.rb
571
571
  - lib/rails_base/configuration/display/background_color.rb
572
+ - lib/rails_base/configuration/display/bg_light.rb
572
573
  - lib/rails_base/configuration/display/btn_danger.rb
573
574
  - lib/rails_base/configuration/display/btn_dark.rb
574
575
  - lib/rails_base/configuration/display/btn_info.rb
@@ -577,6 +578,7 @@ files:
577
578
  - lib/rails_base/configuration/display/btn_secondary.rb
578
579
  - lib/rails_base/configuration/display/btn_success.rb
579
580
  - lib/rails_base/configuration/display/btn_warning.rb
581
+ - lib/rails_base/configuration/display/card.rb
580
582
  - lib/rails_base/configuration/display/footer.rb
581
583
  - lib/rails_base/configuration/display/navbar.rb
582
584
  - lib/rails_base/configuration/display/table_body.rb
@@ -613,7 +615,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
613
615
  - !ruby/object:Gem::Version
614
616
  version: '0'
615
617
  requirements: []
616
- rubygems_version: 3.2.15
618
+ rubygems_version: 3.2.22
617
619
  signing_key:
618
620
  specification_version: 4
619
621
  summary: Rails engine that takes care of the stuff you dont want to!
@@ -1,13 +0,0 @@
1
- // Action Cable provides the framework to deal with WebSockets in Rails.
2
- // You can generate new channels where WebSocket features live using the `rails generate channel` command.
3
- //
4
- //= require action_cable
5
- //= require_self
6
- //= require_tree ./channels
7
-
8
- (function() {
9
- this.App || (this.App = {});
10
-
11
- App.cable = ActionCable.createConsumer();
12
-
13
- }).call(this);