thecore_ui_commons 3.1.5 → 3.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7c120eedf4dca232e5d22b6b87d71f7eddad81af8e1611dd5f190f6339be78d
4
- data.tar.gz: d567304745fff1ad9f6387104b0d74693eb6364ed55dd54d65085ecc49e835eb
3
+ metadata.gz: fd6232595aa3e317fbfe577e1e4abddcdac5692bf90d09cf1c71dea6ce5ef3b5
4
+ data.tar.gz: 06a943dbb148675096b94c9845ae15db2b78f012028e08ea2c7b95ecb46a0f7e
5
5
  SHA512:
6
- metadata.gz: b1c795e77b22556c32f79aba53590601a0863ec37006c3f1e96ae82a57585f078bd26980c033ed93252005824cdc885044ebba44882dbd1ae9e679d2ac58bcff
7
- data.tar.gz: 8b5ea7538e46a1103157149e6f48c62e7c58cae08e8ff230da8f575dbcaf8b0c4499c57e74037bb29520163421de0cbdb363c4f93bdeee56fa8b9652083efd16
6
+ metadata.gz: f5ee92273720eacc56372b96dd4ef1778b176a77fe7b2f6cb64d4bbc1eba98ad7a1b20dba50f7a940948130598795421591a01fee2ba100f6c442bd169b502fc
7
+ data.tar.gz: 5623c5a81ae20cfd042c8143cc58ca5239418620dd60e83c6c84a41daef38709fcf85481fcbe22e350af4b25b19192923dfd2783d30bb76e914d523de72805c1
@@ -1,8 +1,7 @@
1
1
  Rails.application.configure do
2
2
  config.after_initialize do
3
3
  # Controllers
4
- ApplicationController.send :include, ConcernApplicationController
5
- RailsAdmin::ApplicationController.send :include, ConcernApplicationController
4
+ ApplicationController.send(:include, ConcernCommonApplicationController)
6
5
  User.send(:include, ThecoreUiCommonsUserConcern)
7
6
  end
8
7
  end
@@ -0,0 +1,47 @@
1
+ Rails.logger.debug "ApplicationController Concern from ThecoreUiCommons"
2
+ require 'active_support/concern'
3
+
4
+ module ConcernCommonApplicationController
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ # protect_from_forgery prepend: true
9
+ protect_from_forgery except: :sign_in, prepend: true
10
+
11
+ rescue_from CanCan::AccessDenied do |exception|
12
+ redirect_to main_app.root_url, alert: exception.message
13
+ end
14
+
15
+ before_action :store_user_location!, if: :storable_location?
16
+ before_action :reject_locked!, if: :devise_controller?
17
+
18
+ # Auto-sign out locked users
19
+ def reject_locked!
20
+ if !current_user.blank? && current_user.locked?
21
+ Rails.logger.debug " - Cleaning session"
22
+ sign_out current_user
23
+ user_session = nil
24
+ current_user = nil
25
+ flash[:alert] = "Your account is locked."
26
+ flash[:notice] = nil
27
+ redirect_to root_url
28
+ end
29
+ end
30
+
31
+ # Its important that the location is NOT stored if:
32
+ # - The request method is not GET (non idempotent)
33
+ # - The request is handled by a Devise controller such as
34
+ # Devise::SessionsController as that could cause an
35
+ # infinite redirect loop.
36
+ # - The request is an Ajax request as this can lead to very unexpected
37
+ # behaviour.
38
+ def storable_location?
39
+ request.get? && is_navigational_format? && !devise_controller? && !request.xhr?
40
+ end
41
+
42
+ def store_user_location!
43
+ # :user is the scope we are authenticating
44
+ store_location_for(:user, request.fullpath)
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module ThecoreUiCommons
2
- VERSION = "3.1.5".freeze
2
+ VERSION = "3.1.7".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore_ui_commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.5
4
+ version: 3.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-02 00:00:00.000000000 Z
11
+ date: 2024-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thecore_backend_commons
@@ -131,7 +131,7 @@ files:
131
131
  - config/initializers/after_initialize.rb
132
132
  - config/initializers/application_config.rb
133
133
  - config/initializers/assets.rb
134
- - config/initializers/concern_application_controller.rb
134
+ - config/initializers/concern_common_application_controller.rb
135
135
  - config/initializers/concern_user.rb
136
136
  - config/initializers/helper_charts.rb
137
137
  - config/locales/en.ra_settings.yml
@@ -1,81 +0,0 @@
1
- puts "ApplicationController Concern from ThecoreUiCommons"
2
- require 'active_support/concern'
3
-
4
- module ConcernApplicationController
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- # protect_from_forgery prepend: true
9
- protect_from_forgery except: :sign_in, prepend: true
10
-
11
- rescue_from CanCan::AccessDenied do |exception|
12
- redirect_to main_app.root_url, alert: exception.message
13
- end
14
-
15
- before_action :store_user_location!, if: :storable_location?
16
- before_action :reject_locked!, if: :devise_controller?
17
-
18
- # Redirects on successful sign in
19
- def after_sign_in_path_for resource
20
- root_actions = RailsAdmin::Config::Actions.all(:root).select {|action| can? action.action_name, :all }.collect(&:action_name)
21
-
22
- # Default root action as landing page: the first to which I have authorization to read
23
- action = root_actions.first
24
- puts "after_sign_in_path_for action: #{action}"
25
- # Otherwise, if I set a Manual override for landing actions in config, I can test if I'm authorized to see it
26
- override_landing_page = Settings.ns(:main).after_sign_in_redirect_to_root_action
27
- action = override_landing_page.to_sym if !override_landing_page.blank? && root_actions.include?(override_landing_page.to_sym)
28
-
29
- # If I ask for a specific page, Let's try to go back there if I need to login or re-login
30
- # This takes precedence on automatic computed action
31
- stored_location = stored_location_for(resource)
32
- puts "after_sign_in_path_for stored_location: #{stored_location}"
33
- if !stored_location.blank? && can?(resource, :all)
34
- # Go to the latest navigated page
35
- puts "after_sign_in_path_for Redirect to stored_location"
36
- return stored_location
37
- elsif action
38
- path = rails_admin.send("#{action}_path").sub("#{ENV['RAILS_RELATIVE_URL_ROOT']}#{ENV['RAILS_RELATIVE_URL_ROOT']}", "#{ENV['RAILS_RELATIVE_URL_ROOT']}")
39
- puts "after_sign_in_path_for Redirect to action #{path}"
40
- return path
41
- else
42
- puts "after_sign_in_path_for ERROR! Signing out user :-("
43
- sign_out current_user
44
- user_session = nil
45
- current_user = nil
46
- flash[:alert] = "Your user is not authorized to access any page."
47
- flash[:notice] = nil
48
- return root_path
49
- end
50
- end
51
-
52
- # Auto-sign out locked users
53
- def reject_locked!
54
- if !current_user.blank? && current_user.locked?
55
- puts " - Cleaning session"
56
- sign_out current_user
57
- user_session = nil
58
- current_user = nil
59
- flash[:alert] = "Your account is locked."
60
- flash[:notice] = nil
61
- redirect_to root_url
62
- end
63
- end
64
-
65
- # Its important that the location is NOT stored if:
66
- # - The request method is not GET (non idempotent)
67
- # - The request is handled by a Devise controller such as
68
- # Devise::SessionsController as that could cause an
69
- # infinite redirect loop.
70
- # - The request is an Ajax request as this can lead to very unexpected
71
- # behaviour.
72
- def storable_location?
73
- request.get? && is_navigational_format? && !devise_controller? && !request.xhr?
74
- end
75
-
76
- def store_user_location!
77
- # :user is the scope we are authenticating
78
- store_location_for(:user, request.fullpath)
79
- end
80
- end
81
- end