rails_base 0.53.1 → 0.57.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d20109ef6d422bfe9f2d9ea381e0bae71bfd9cb9a3585554f97fb378baf00d50
4
- data.tar.gz: '08666f477b07d62d5fffd6505785b12b643bc9164ccd1c038585f7d895fa78c7'
3
+ metadata.gz: 64ddb52ebfed26fcec5bd3ea7e44feab2d2308591958c7e90a4cc476811332ba
4
+ data.tar.gz: d89ad080614e89f901d7d51ad22cfb1c77e32b67e0712fae1d31fa2a9b2aa746
5
5
  SHA512:
6
- metadata.gz: b67025f0a012ed6c7024671a048f74026f30b9870115f13f5c2ff047f1a5fed7e5b31e61c2074a8f193d5cdd8392465deaa816c6a651d9cfb6f2788de4bcfeb0
7
- data.tar.gz: 3b44a97ffc9ebd160941fe29b517d1ab114b61250562a6a51d4cf72cb29702233b31b39c6aa550664527b1e78a787600549dba4c06e96c9b9c2feb2b838b30e3
6
+ metadata.gz: b1110d8afad68484b6a28f00c8fcbe41253984b6e3a820c2d13c6d9125c6000e2b53d114b78426b81ea73ddf12767a2e710a495bca820001c0a5f197e4c5185c
7
+ data.tar.gz: 60116d2b2d6d99f1736ef44702999ac55598085d22fc6c0cd29df9b06cd9aef2e60b0a02d17fb0201590ef4f85f6ecd95b21d6c78ca938e730cdc8ba2dbaefdb
@@ -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
@@ -19,6 +19,9 @@ module RailsBase
19
19
  User.all.select do |user|
20
20
  proc.call(user)
21
21
  end.map(&:inspect_name)
22
+ rescue StandardError => e
23
+ Rails.logger.warn("Error -> #{e}")
24
+ nil
22
25
  end
23
26
 
24
27
  def array_for_proc(proc, array)
@@ -8,15 +8,22 @@ module RailsBase::Authentication
8
8
  delegate :user, to: :context
9
9
  delegate :reason, to: :context
10
10
 
11
- MAX_USE_COUNT = 1.freeze
12
11
  DATA_USE = :alphanumeric
13
12
  VELOCITY_MAX = 5
14
13
  VELOCITY_MAX_IN_FRAME = 10.minutes
15
14
  VELOCITY_FRAME = 1.hour
16
15
 
17
16
  REASON_MAPPER = {
18
- Constants::SVE_LOGIN_REASON => { method: :email_verification, url_method: :email_verification_url },
19
- Constants::SVE_FORGOT_REASON => { method: :forgot_password, url_method: :forgot_password_auth_url }
17
+ Constants::SVE_LOGIN_REASON => {
18
+ method: :email_verification,
19
+ url_method: :email_verification_url,
20
+ max_use: RailsBase.config.login_behavior.email_max_use_verification
21
+ },
22
+ Constants::SVE_FORGOT_REASON => {
23
+ method: :forgot_password,
24
+ url_method: :forgot_password_auth_url,
25
+ max_use: RailsBase.config.login_behavior.email_max_use_forgot
26
+ }
20
27
  }
21
28
 
22
29
  def call
@@ -61,7 +68,7 @@ module RailsBase::Authentication
61
68
  def create_short_lived_data
62
69
  params = {
63
70
  user: user,
64
- max_use: MAX_USE_COUNT,
71
+ max_use: REASON_MAPPER[reason][:max_use],
65
72
  reason: reason,
66
73
  data_use: DATA_USE,
67
74
  ttl: Constants::SVE_TTL,
@@ -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
 
@@ -32,7 +32,7 @@
32
32
  <body>
33
33
  <script type="text/javascript">
34
34
  // Load at top so available for rest of body oddy
35
- function set_cookie(name, value, path ) {
35
+ function set_cookie(name, value, path) {
36
36
  path ||= '/'
37
37
  document.cookie = `${name}=${value}; path=${path}`
38
38
  }
@@ -126,7 +126,7 @@
126
126
  </footer>
127
127
  <% end %>
128
128
  </div>
129
-
129
+
130
130
  <% if RailsBase.appearance.back_to_top.enable? %>
131
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
132
  <script type="text/javascript">
@@ -1,7 +1,9 @@
1
1
  <p>Hello <%= @user.full_name %>!</p>
2
2
 
3
3
  <p>
4
- Welcome to <%= RailsBase.config.app.communication_name %>. Where you have the ability to keep track of all of your optiosn accross different companies and life events
4
+ Welcome to <%= RailsBase.config.app.communication_name %>.
5
+ </br>
6
+ <%= RailsBase.config.mailer.verification_content(@user) %>
5
7
  </br>
6
8
  Please finish your registration by following this <a href="<%=@sso_url_for_user%>" target="_blank"> Registration Link </a>
7
9
  </br>
@@ -14,7 +14,7 @@
14
14
  <% case object[:type] %>
15
15
  <% when :proc %>
16
16
  <td>
17
- <% users = users_for_proc(instance.public_send(name)) %>
17
+ <% users = users_for_proc(instance.public_send(name)) || ['Yikes! Probably a proc with different values'] %>
18
18
  <a tabindex="0" class="btn btn_secondary" role="button" data-toggle="popover" data-trigger="focus" title="Users with ability" data-html=true data-content="<%=users.join('</br>')%>">View Users</a>
19
19
  </td>
20
20
  <% when :string_proc %>
@@ -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 %>
@@ -59,7 +59,7 @@
59
59
  </br>
60
60
  <div class='row'>
61
61
  <div class='col'>
62
- <a class="btn btn_info btn-block" href="<%=RailsBase.url_routes.user_settings_path%>" role="button">Modify User</a>
62
+ <a class="btn btn_info btn-block" href="<%=RailsBase.url_routes.user_settings_path %>" role="button">Modify User</a>
63
63
  </div>
64
64
  </div>
65
65
  </br>
@@ -69,6 +69,14 @@
69
69
  </div>
70
70
  </div>
71
71
  </br>
72
+ <% if RailsBase.config.templates.logged_in_header_modal %>
73
+ <div class='row'>
74
+ <div class='col'>
75
+ <%= render partial: RailsBase.config.templates.logged_in_header_modal, locals: { current_user: current_user } %>
76
+ </div>
77
+ </div>
78
+ </br>
79
+ <% end %>
72
80
  <div class="dropdown-divider"></div>
73
81
  <div class='row'>
74
82
  <div class='col'>
@@ -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,
@@ -11,6 +11,7 @@ require 'rails_base/configuration/appearance'
11
11
  require 'rails_base/configuration/user'
12
12
  require 'rails_base/configuration/login_behavior'
13
13
  require 'rails_base/configuration/active_job'
14
+ require 'rails_base/configuration/templates'
14
15
 
15
16
  module RailsBase
16
17
  class Config
@@ -28,7 +29,8 @@ module RailsBase
28
29
  appearance: nil,
29
30
  user: nil,
30
31
  active_job: nil,
31
- login_behavior: nil
32
+ login_behavior: nil,
33
+ templates: nil,
32
34
  }
33
35
  attr_reader *VARIABLES.keys
34
36
 
@@ -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
@@ -14,6 +14,9 @@ require 'rails_base/configuration/display/navbar'
14
14
  require 'rails_base/configuration/display/table_body'
15
15
  require 'rails_base/configuration/display/table_header'
16
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'
17
20
 
18
21
  module RailsBase
19
22
  module Configuration
@@ -27,6 +30,8 @@ module RailsBase
27
30
  :btn_info,
28
31
  :btn_light,
29
32
  :btn_dark,
33
+ :bg_light,
34
+
30
35
  ]
31
36
 
32
37
  DOWNSTREAM_CLASSES = [
@@ -35,9 +40,9 @@ module RailsBase
35
40
  :bg_color,
36
41
  :navbar,
37
42
  :text,
43
+ :card,
38
44
  :footer,
39
45
  :back_to_top,
40
-
41
46
  ] + BUTTONS
42
47
 
43
48
  SKIP_DOWNSTREAM_CLASSES = [:footer, :back_to_top]
@@ -85,9 +90,10 @@ module RailsBase
85
90
  @bg_color = Configuration::Display::BackgroundColor.new
86
91
  @navbar = Configuration::Display::Navbar.new
87
92
  @text = Configuration::Display::Text.new
88
-
93
+ @card = Configuration::Display::Card.new
89
94
  @footer = Configuration::Display::Footer.new
90
95
  @back_to_top = Configuration::Display::BackTotop.new
96
+ @bg_light = Configuration::Display::BgLight.new
91
97
 
92
98
  @btn_primary = Configuration::Display::BtnPrimary.new
93
99
  @btn_secondary = Configuration::Display::BtnSecondary.new
@@ -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
@@ -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
 
@@ -9,7 +9,17 @@ module RailsBase
9
9
  type: :boolean,
10
10
  default: true,
11
11
  description: 'Enable capturing requests context when login fails. Upon login, redirect user to page they tried to go to.',
12
- }
12
+ },
13
+ email_max_use_verification:{
14
+ type: :integer,
15
+ default: 2,
16
+ description: 'Maximum number of times User can click link for verifiaction',
17
+ },
18
+ email_max_use_forgot:{
19
+ type: :integer,
20
+ default: 2,
21
+ description: 'Maximum number of times User can click link for forgot password flow',
22
+ },
13
23
  }
14
24
  attr_accessor *DEFAULT_VALUES.keys
15
25
  end
@@ -107,7 +107,12 @@ module RailsBase
107
107
  default: 'mailers',
108
108
  on_assignment: ->(val, _instance) { ACTION_MAILER_PROC.call(:deliver_later_queue_name, val) },
109
109
  description: 'The active job queue to send twilio messages from. Ensure that adapter is bound to the queue',
110
- }
110
+ },
111
+ verification_content: {
112
+ type: :string_proc,
113
+ default: ->(user) { "We are pleased to have you here" },
114
+ description: 'Description of app for verification mailer. User is passed in.',
115
+ },
111
116
  }
112
117
 
113
118
  attr_accessor *DEFAULT_VALUES.keys
@@ -0,0 +1,18 @@
1
+ require 'rails_base/configuration/base'
2
+
3
+ module RailsBase
4
+ module Configuration
5
+ class Templates < Base
6
+
7
+ DEFAULT_VALUES = {
8
+ logged_in_header_modal: {
9
+ type: :string_nil,
10
+ default: nil,
11
+ description: 'The template to render in the logged in header modal. `current_user` is passed in',
12
+ },
13
+ }
14
+
15
+ attr_accessor *DEFAULT_VALUES.keys
16
+ end
17
+ end
18
+ end
@@ -1,7 +1,7 @@
1
1
  module RailsBase
2
2
  MAJOR = '0'
3
- MINOR = '53'
4
- PATCH = '1'
3
+ MINOR = '57'
4
+ PATCH = '0'
5
5
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
6
6
 
7
7
  def self.print_version
@@ -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.53.1
4
+ version: 0.57.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-08-28 00:00:00.000000000 Z
11
+ date: 2021-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -569,6 +569,7 @@ files:
569
569
  - lib/rails_base/configuration/base.rb
570
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
@@ -588,6 +590,7 @@ files:
588
590
  - lib/rails_base/configuration/mfa.rb
589
591
  - lib/rails_base/configuration/owner.rb
590
592
  - lib/rails_base/configuration/redis.rb
593
+ - lib/rails_base/configuration/templates.rb
591
594
  - lib/rails_base/configuration/user.rb
592
595
  - lib/rails_base/engine.rb
593
596
  - lib/rails_base/version.rb