thecore 1.7.0 → 1.7.1

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: a42f1257e5672fb290d24c7027cbc14baebf612018d63b912d2db48cff759d9d
4
- data.tar.gz: 8874f2abd2862b30887b1341ab0f17eb05b369ac2c01ad5ad2b98ab3917af14b
3
+ metadata.gz: 4ce48dbc0e595f1962f34e8ee821d692016f8660894a2005e842fb2c19edbfcf
4
+ data.tar.gz: b31674c73a91b29fdf531cd83b95ae98a19cdcc9352364297cb633eac82fcac6
5
5
  SHA512:
6
- metadata.gz: 147f5fcfccfa0d13abdeb0253a2822827105ed31ab9e7daff29c4749cabde4be6fcfa4bbf3fe38e48b7a0a17dd263628293608160a3470897c41f873128b9fbb
7
- data.tar.gz: 1487ecb62f3b73dabdac2c267a5eb1656411d259d04f0c7dc163665cb9ba33400a79925ab06743d8db764e8abf88eb9431d7cc8dfdb59b4549f088f1b85c7542
6
+ metadata.gz: 34e6022ac82ce72dc8582138c55118fbc5e6755807b074f49caa6949c7aad0f5c23fad1c4d41cd91a4d68e81b4e8abadb68305169b15089816627bcb9ad905a3
7
+ data.tar.gz: 1298ff9576a42d7e1bb089be3ce859b70f13c870c97513aef0139b7320c60d09a3e79c07d7ef2e84cc857f272d7e0381f251638bd943267485d69f173354981b
@@ -2,7 +2,7 @@ require 'active_support/concern'
2
2
 
3
3
  module ThecoreConcern
4
4
  extend ActiveSupport::Concern
5
-
5
+
6
6
  included do
7
7
  # Prevent CSRF attacks by raising an exception.
8
8
  # For APIs, you may want to use :null_session instead.
@@ -13,18 +13,19 @@ module ThecoreConcern
13
13
  end
14
14
  include HttpAcceptLanguage::AutoLocale
15
15
  Rails.logger.debug "Selected Locale: #{I18n.locale}"
16
+ before_action :store_user_location!, if: :storable_location?
16
17
  before_action :configure_permitted_parameters, if: :devise_controller?
17
18
  before_action :reject_locked!, if: :devise_controller?
18
-
19
+
19
20
  helper_method :reject_locked!
20
21
  helper_method :require_admin!
21
22
  helper_method :line_break
22
23
  helper_method :title
23
24
  helper_method :bootstrap_class_for
24
-
25
+
25
26
  # Redirects on successful sign in
26
27
  def after_sign_in_path_for resource
27
- Rails.logger.debug("SUCCESFULL SIGNIN, USER IS ADMIN? #{current_user.admin?}")
28
+ # Rails.logger.debug("SUCCESFULL SIGNIN, USER IS ADMIN? #{current_user.admin?}")
28
29
  #if current_user.admin?
29
30
  # GETTING JUST THE ROOT ACTIONS I (CURRENT_USER) CAN MANAGE
30
31
  root_actions = RailsAdmin::Config::Actions.all(:root).select {|action| can? action.action_name, :all }
@@ -33,20 +34,14 @@ module ThecoreConcern
33
34
  action = root_actions.collect(&:action_name).first
34
35
  # Rails.logger.debug "FIRST ACTION: #{action}"
35
36
  # REDIRECT TO THAT ACTION
36
- rails_admin.send("#{action}_path").sub("#{ENV['RAILS_RELATIVE_URL_ROOT']}#{ENV['RAILS_RELATIVE_URL_ROOT']}", "#{ENV['RAILS_RELATIVE_URL_ROOT']}")
37
- #rails_admin.dashboard_path.sub("#{ENV['RAILS_RELATIVE_URL_ROOT']}#{ENV['RAILS_RELATIVE_URL_ROOT']}", "#{ENV['RAILS_RELATIVE_URL_ROOT']}")
38
- #elsif current_user.has_role? :workers
39
- # rails_admin.new_path('timetable').sub("#{ENV['RAILS_RELATIVE_URL_ROOT']}#{ENV['RAILS_RELATIVE_URL_ROOT']}", "#{ENV['RAILS_RELATIVE_URL_ROOT']}")
40
- #else
41
- # inside_path
42
- #end
37
+ stored_location_for(resource) || rails_admin.send("#{action}_path").sub("#{ENV['RAILS_RELATIVE_URL_ROOT']}#{ENV['RAILS_RELATIVE_URL_ROOT']}", "#{ENV['RAILS_RELATIVE_URL_ROOT']}")
43
38
  end
44
39
  end
45
-
40
+
46
41
  def title value = "Thecore"
47
42
  @title = value
48
43
  end
49
-
44
+
50
45
  def bootstrap_class_for flash_type
51
46
  case flash_type
52
47
  when 'success'
@@ -61,53 +56,68 @@ module ThecoreConcern
61
56
  flash_type.to_s
62
57
  end
63
58
  end
64
-
59
+
65
60
  def line_break s
66
61
  s.gsub("\n", "<br/>")
67
62
  end
68
63
  # Devise permitted params
69
64
  def configure_permitted_parameters
70
- devise_parameter_sanitizer.permit(:sign_in) { |u| u.permit(
71
- :username,
72
- :password,
73
- :password_confirmation,
74
- :remember_me)
75
- }
76
- devise_parameter_sanitizer.permit(:sign_up) { |u| u.permit(
77
- :username,
78
- :password,
79
- :password_confirmation)
80
- }
81
- devise_parameter_sanitizer.permit(:account_update) { |u| u.permit(
82
- :username,
83
- :password,
84
- :password_confirmation,
85
- :current_password
86
- )
87
- }
88
- end
89
-
90
- # Auto-sign out locked users
91
- def reject_locked!
92
- if current_user && current_user.locked?
93
- sign_out current_user
94
- user_session = nil
95
- current_user = nil
96
- flash[:alert] = "Your account is locked."
97
- flash[:notice] = nil
98
- redirect_to root_url
65
+ devise_parameter_sanitizer.permit(:sign_in) {
66
+ |u| u.permit(
67
+ :username,
68
+ :password,
69
+ :password_confirmation,
70
+ :remember_me)
71
+ }
72
+ devise_parameter_sanitizer.permit(:sign_up) { |u| u.permit(
73
+ :username,
74
+ :password,
75
+ :password_confirmation)
76
+ }
77
+ devise_parameter_sanitizer.permit(:account_update) { |u| u.permit(
78
+ :username,
79
+ :password,
80
+ :password_confirmation,
81
+ :current_password)
82
+ }
99
83
  end
100
- end
101
-
102
- # Only permits admin users
103
- def require_admin!
104
- authenticate_user!
105
-
106
- if current_user && !current_user.admin?
107
- redirect_to inside_path
84
+
85
+ # Auto-sign out locked users
86
+ def reject_locked!
87
+ if current_user && current_user.locked?
88
+ sign_out current_user
89
+ user_session = nil
90
+ current_user = nil
91
+ flash[:alert] = "Your account is locked."
92
+ flash[:notice] = nil
93
+ redirect_to root_url
94
+ end
95
+ end
96
+
97
+ # Only permits admin users
98
+ def require_admin!
99
+ authenticate_user!
100
+
101
+ if current_user && !current_user.admin?
102
+ redirect_to inside_path
103
+ end
104
+ end
105
+
106
+ # Its important that the location is NOT stored if:
107
+ # - The request method is not GET (non idempotent)
108
+ # - The request is handled by a Devise controller such as Devise::SessionsController as that could cause an
109
+ # infinite redirect loop.
110
+ # - The request is an Ajax request as this can lead to very unexpected behaviour.
111
+ def storable_location?
112
+ request.get? && is_navigational_format? && !devise_controller? && !request.xhr?
113
+ end
114
+
115
+ def store_user_location!
116
+ # :user is the scope we are authenticating
117
+ store_location_for(:user, request.fullpath)
108
118
  end
109
119
  end
110
- end
111
-
112
- # include the extension
113
- ActionController::Base.send(:include, ThecoreConcern)
120
+
121
+ # include the extension
122
+ ActionController::Base.send(:include, ThecoreConcern)
123
+
@@ -1,3 +1,3 @@
1
1
  module Thecore
2
- VERSION = '1.7.0'.freeze
2
+ VERSION = '1.7.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-12 00:00:00.000000000 Z
11
+ date: 2020-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails