thecore_backend_commons 3.1.3 → 3.1.4

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: cb20c15ff661ae29da36dd49e741a06f2fcebfe66d6d396ab8d13e56bc19cfaf
4
- data.tar.gz: 0eb50b593ab125d7ea382429cd8c5239bff1bdcbecf374684696afe07decc2b4
3
+ metadata.gz: 7497a63c6b2cf568f786b24734477b49d8a38a8b6dbec82f370ee1c02d463038
4
+ data.tar.gz: 4659432eab9e8b37b37c7e412010f82d8ba0aba879eadffc1ab22d79bae33dc0
5
5
  SHA512:
6
- metadata.gz: 11f14abba150e961335fc6ba119606c2e4fed084294fbc0896f31069441eced1310dfa1c243e1638375b7afe8c38e75ddf1e0b5036df2378f51ab5c5e7e9a176
7
- data.tar.gz: 546044d1eef76e68c3542cc4fc23692259e527e5e3dc544912f1d95e12bee58bbcca58eea668fe22491ce74da6e4d8e29bfbe89afda71c053ee0b764a382d758
6
+ metadata.gz: 3da399e4ee0c80efb21447a3c50088a50e1a302531faf16d4f0fc8b0acc247b5f63968a738bc99dfd2b8b0f7ccca84f0242d0cdc2f365a9ae2d4d4c470910515
7
+ data.tar.gz: da3e94fa7c2c17da98d4c2aeac681a9fb59362d49738a6f17fd486ccfaa759767073e2a4dd70843ea1de1e0b04d3983a0b3fd606e8b2099276b36a75ddd00425
@@ -1,3 +1,3 @@
1
1
  Rails.application.config.active_storage.configure :Disk, root: Rails.root.join("storage")
2
2
  Rails.application.config.action_mailer.delivery_method = :smtp
3
- Rails.application.config.action_cable.allowed_request_origins = [ ENV["FRONTEND_URL"].presence || /http:\/\/*/, ENV["BACKEND_URL"].presence || /http:\/\/*/ ].uniq
3
+ Rails.application.config.action_cable.allowed_request_origins = [ ENV["FRONTEND_URL"].presence || /http:\/\/*/, ENV["BACKEND_URL"].presence || /http:\/\/*/, "https://localhost:8100" ].uniq
@@ -10,15 +10,23 @@ module ApplicationRecordConcern
10
10
  after_rollback :message_ko
11
11
 
12
12
  def validation_ko
13
- ActionCable.server.broadcast("messages", { topic: :record, action: detect_action, success: false, valid: false, errors: self.errors.full_messages.uniq, record: self}) if self.errors.any?
13
+ ActionCable.server.broadcast("messages", build_message(false, false, self.errors.full_messages.uniq)) if self.errors.any? && !is_model_forbidden
14
14
  end
15
15
 
16
16
  def message_ok
17
- ActionCable.server.broadcast("messages", { topic: :record, action: detect_action, success: true, valid: true, errors: [], record: self})
17
+ ActionCable.server.broadcast("messages", build_message(true, true, [])) unless is_model_forbidden
18
18
  end
19
19
 
20
20
  def message_ko
21
- ActionCable.server.broadcast("messages", { topic: :record, action: detect_action, success: false, valid: true, errors: [], record: self})
21
+ ActionCable.server.broadcast("messages", build_message(false, true, [])) unless is_model_forbidden
22
+ end
23
+
24
+ def is_model_forbidden
25
+ [ 'User', 'Role' ].include?(self.class.name)
26
+ end
27
+
28
+ def build_message success, valid, errors
29
+ { topic: :record, action: detect_action, class: self.class.name, success: success, valid: valid, errors: errors, record: self}
22
30
  end
23
31
 
24
32
  def detect_action
@@ -12,7 +12,10 @@ module CableConnectionConcern
12
12
  protected
13
13
 
14
14
  def find_verified_user # this checks whether a user is authenticated with devise
15
- if verified_user = env['warden'].user
15
+ m = request.query_parameters["token"]
16
+
17
+ body = ::HashWithIndifferentAccess.new(::JWT.decode(m, ::Rails.application.credentials.dig(:secret_key_base).presence||ENV["SECRET_KEY_BASE"], false)[0]) rescue nil
18
+ if verified_user = (env['warden'].user.presence || User.find_by(id: body[:user_id]))
16
19
  verified_user
17
20
  else
18
21
  reject_unauthorized_connection
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore_backend_commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.3
4
+ version: 3.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni