thecore_backend_commons 3.1.2 → 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: 8d36b1d264e07258e473fd2cf61f416b13c1f90f824df789caf1fa59a2256a10
4
- data.tar.gz: 1555f66225ca9351fb662200e2e1aae8316db72d3860efcb84e8f462df61d7df
3
+ metadata.gz: 7497a63c6b2cf568f786b24734477b49d8a38a8b6dbec82f370ee1c02d463038
4
+ data.tar.gz: 4659432eab9e8b37b37c7e412010f82d8ba0aba879eadffc1ab22d79bae33dc0
5
5
  SHA512:
6
- metadata.gz: d360689783298699ad923937becd16bd2196d6c11ed003ada2ecba3d2da057d5738eed9f09afede7f12db4cce7bc9c8c0fa4f538b76d6aff52086754c1d84326
7
- data.tar.gz: aa70cf87907c29a39e526f688c5f92c0fe4d1e1c9972fd8f246ac713085e904443f0962f3fcc77a47cf581e353bd135c175c268426ca8fc7c1ddf592d2a685cb
6
+ metadata.gz: 3da399e4ee0c80efb21447a3c50088a50e1a302531faf16d4f0fc8b0acc247b5f63968a738bc99dfd2b8b0f7ccca84f0242d0cdc2f365a9ae2d4d4c470910515
7
+ data.tar.gz: da3e94fa7c2c17da98d4c2aeac681a9fb59362d49738a6f17fd486ccfaa759767073e2a4dd70843ea1de1e0b04d3983a0b3fd606e8b2099276b36a75ddd00425
@@ -7,10 +7,7 @@ class ActivityLogChannel < ApplicationCable::Channel
7
7
  # Any cleanup needed when channel is unsubscribed
8
8
  end
9
9
 
10
- # https://cableready.stimulusreflex.com/troubleshooting/#verify-actioncable
11
-
12
10
  def receive(data)
13
- puts data["message"]
14
- ActionCable.server.broadcast("messages", "ActionCable is connected")
11
+ ActionCable.server.broadcast("messages", {message: "ActionCable is connected and received: #{data["message"]}", topic: data["topic"].presence || "general"}) if data["namespace"] == "subscriptions"
15
12
  end
16
13
  end
@@ -1,2 +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:\/\/*/, "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.2
4
+ version: 3.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni