From ec961d262976fd1c6a5e5d1f2acd4f4d8e716fd6 Mon Sep 17 00:00:00 2001 From: stage-rl Date: Sun, 5 Jan 2025 15:20:44 +0100 Subject: [PATCH] New message notification --- Gemfile | 35 ++-- Gemfile.lock | 182 ++++++++---------- app/controllers/message_threads_controller.rb | 9 +- app/controllers/messages_controller.rb | 2 +- .../authorize_delivery_notification_job.rb | 2 +- app/jobs/govbox/download_message_job.rb | 4 +- app/jobs/govbox/process_message_job.rb | 7 +- app/views/message_threads/show.html.erb | 5 + .../_new_message_alert.turbo_stream.erb | 34 ++++ config/cable.yml | 9 +- 10 files changed, 155 insertions(+), 134 deletions(-) create mode 100644 app/views/messages/_new_message_alert.turbo_stream.erb diff --git a/Gemfile b/Gemfile index 0101fe068..162fb18c4 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ ruby '3.3.0' gem 'rails', '~> 7.1' gem 'rails-i18n' +gem 'actioncable-enhanced-postgresql-adapter' gem 'pg', '~> 1.5' gem 'with_advisory_lock' @@ -13,8 +14,8 @@ gem 'puma', '~> 6.4' gem 'turbo-rails' # Styles -gem 'sprockets-rails' gem 'importmap-rails' +gem 'sprockets-rails' gem 'tailwindcss-rails' gem 'view_component' @@ -26,20 +27,20 @@ gem 'good_job' # Auth gem 'omniauth-google-oauth2' -gem 'omniauth-saml', '~> 2.2.1' gem 'omniauth-rails_csrf_protection' +gem 'omniauth-saml', '~> 2.2.1' gem 'pundit' # Utilities -gem 'rest-client' -gem 'rack-attack' +gem 'grover' gem 'jbuilder' -gem 'rubyzip', require: 'zip' -gem 'jwt' -gem 'stimulus-rails' gem 'jsbundling-rails' +gem 'jwt' gem 'pdf-reader' -gem 'grover' +gem 'rack-attack' +gem 'rest-client' +gem 'rubyzip', require: 'zip' +gem 'stimulus-rails' # Monitoring gem 'rollbar' @@ -53,28 +54,28 @@ gem 'bootsnap', '>= 1.4.4', require: false group :development, :test do gem "brakeman" gem 'dotenv-rails' - gem 'pry-rails' - gem 'pry-byebug' gem 'foreman' + gem 'pry-byebug' + gem 'pry-rails' end group :development do gem 'annotate' - gem 'listen' - gem 'web-console' - gem 'solargraph' - gem 'htmlbeautifier' gem 'erb_lint' - gem 'ruby-lsp-rails' + gem 'htmlbeautifier' + gem 'listen' gem 'rdbg' gem 'rubocop' gem 'rubocop-rails' + gem 'ruby-lsp' + gem 'ruby-lsp-rails' + gem 'web-console' end group :test do - gem 'selenium-webdriver' gem 'capybara' gem 'capybara-screenshot' - gem 'webmock' + gem 'selenium-webdriver' gem 'simplecov', require: false + gem 'webmock' end diff --git a/Gemfile.lock b/Gemfile.lock index 4362ba58e..5f9987266 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,6 +8,10 @@ GEM nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) + actioncable-enhanced-postgresql-adapter (1.0.1) + actioncable (>= 6.0) + connection_pool (>= 2.2.5) + pg (~> 1.5) actionmailbox (7.1.3) actionpack (= 7.1.3) activejob (= 7.1.3) @@ -83,23 +87,21 @@ GEM activerecord (>= 3.2, < 8.0) rake (>= 10.4, < 14.0) ast (2.4.2) - backport (1.2.0) base64 (0.2.0) - benchmark (0.3.0) - better_html (2.0.2) + better_html (2.1.1) actionview (>= 6.0) activesupport (>= 6.0) ast (~> 2.0) erubi (~> 1.4) parser (>= 2.4) smart_properties - bigdecimal (3.1.6) + bigdecimal (3.1.8) bindex (0.8.1) bootsnap (1.18.3) msgpack (~> 1.2) - brakeman (6.1.2) + brakeman (6.2.2) racc - builder (3.2.4) + builder (3.3.0) byebug (11.1.3) capybara (3.40.0) addressable @@ -120,41 +122,43 @@ GEM combine_pdf (1.0.26) matrix ruby-rc4 (>= 0.1.5) - concurrent-ruby (1.2.3) + concurrent-ruby (1.3.4) connection_pool (2.4.1) crack (1.0.0) bigdecimal rexml crass (1.0.6) date (3.3.4) - debug (1.9.1) + debug (1.9.2) irb (~> 1.10) reline (>= 0.3.8) - diff-lcs (1.5.1) docile (1.4.0) domain_name (0.6.20240107) - dotenv (3.1.0) - dotenv-rails (3.1.0) - dotenv (= 3.1.0) + dotenv (3.1.4) + dotenv-rails (3.1.4) + dotenv (= 3.1.4) railties (>= 6.1) drb (2.2.1) - e2mmap (0.1.0) - erb_lint (0.5.0) + erb_lint (0.7.0) activesupport better_html (>= 2.0.1) parser (>= 2.7.1.4) rainbow - rubocop + rubocop (>= 1) smart_properties - erubi (1.12.0) + erubi (1.13.0) et-orbi (1.2.7) tzinfo faraday (2.9.0) faraday-net_http (>= 2.0, < 3.2) faraday-net_http (3.1.0) net-http - ffi (1.16.3) - foreman (0.87.2) + ffi (1.17.0) + ffi (1.17.0-aarch64-linux-gnu) + ffi (1.17.0-arm64-darwin) + ffi (1.17.0-x86_64-darwin) + ffi (1.17.0-x86_64-linux-gnu) + foreman (0.88.1) fugit (1.9.0) et-orbi (~> 1, >= 1.2.7) raabro (~> 1.4) @@ -173,40 +177,36 @@ GEM hashdiff (1.1.0) hashery (2.1.2) hashie (5.0.0) - htmlbeautifier (1.4.2) + htmlbeautifier (1.4.3) http-accept (1.7.0) http-cookie (1.0.5) domain_name (~> 0.5) - i18n (1.14.1) + i18n (1.14.6) concurrent-ruby (~> 1.0) importmap-rails (2.0.1) actionpack (>= 6.0.0) activesupport (>= 6.0.0) railties (>= 6.0.0) io-console (0.7.2) - irb (1.11.2) - rdoc + irb (1.14.1) + rdoc (>= 4.0.0) reline (>= 0.4.2) - jaro_winkler (1.5.6) jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) jsbundling-rails (1.3.0) railties (>= 6.0.0) - json (2.7.1) + json (2.8.2) jwt (2.8.1) base64 - kramdown (2.4.0) - rexml - kramdown-parser-gfm (1.1.0) - kramdown (~> 2.0) language_server-protocol (3.17.0.3) launchy (2.5.2) addressable (~> 2.8) - listen (3.8.0) + listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.22.0) + logger (1.6.1) + loofah (2.23.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -216,16 +216,16 @@ GEM net-smtp marcel (1.0.2) matrix (0.4.2) - method_source (1.0.0) + method_source (1.1.0) mime-types (3.5.2) mime-types-data (~> 3.2015) mime-types-data (3.2024.0206) mini_mime (1.1.5) - mini_portile2 (2.8.6) - minitest (5.22.2) + mini_portile2 (2.8.8) + minitest (5.25.2) msgpack (1.7.2) multi_xml (0.6.0) - mutex_m (0.2.0) + mutex_m (0.3.0) net-http (0.4.1) uri net-imap (0.4.10) @@ -239,16 +239,16 @@ GEM net-protocol netrc (0.11.0) nio4r (2.7.0) - nokogiri (1.16.2) + nokogiri (1.16.7) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.16.2-aarch64-linux) + nokogiri (1.16.7-aarch64-linux) racc (~> 1.4) - nokogiri (1.16.2-arm64-darwin) + nokogiri (1.16.7-arm64-darwin) racc (~> 1.4) - nokogiri (1.16.2-x86_64-darwin) + nokogiri (1.16.7-x86_64-darwin) racc (~> 1.4) - nokogiri (1.16.2-x86_64-linux) + nokogiri (1.16.7-x86_64-linux) racc (~> 1.4) oauth2 (2.0.9) faraday (>= 0.17.3, < 3.0) @@ -275,8 +275,8 @@ GEM omniauth-saml (2.2.1) omniauth (~> 2.1) ruby-saml (~> 1.17) - parallel (1.24.0) - parser (3.3.0.5) + parallel (1.26.3) + parser (3.3.6.0) ast (~> 2.4.1) racc pdf-reader (2.12.0) @@ -289,16 +289,16 @@ GEM pg_search (2.3.6) activerecord (>= 5.2) activesupport (>= 5.2) - prism (0.19.0) + prism (1.2.0) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) pry-byebug (3.10.1) byebug (~> 11.0) pry (>= 0.13, < 0.15) - pry-rails (0.3.9) - pry (>= 0.10.4) - psych (5.1.2) + pry-rails (0.3.11) + pry (>= 0.13.0) + psych (5.2.0) stringio public_suffix (5.0.4) puma (6.4.2) @@ -306,8 +306,8 @@ GEM pundit (2.3.1) activesupport (>= 3.0.0) raabro (1.4.0) - racc (1.7.3) - rack (3.0.9.1) + racc (1.8.1) + rack (3.1.8) rack-attack (6.7.0) rack (>= 1.0, < 4) rack-protection (4.0.0) @@ -317,9 +317,8 @@ GEM rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rackup (2.1.0) + rackup (2.2.1) rack (>= 3) - webrick (~> 1.8) rails (7.1.3) actioncable (= 7.1.3) actionmailbox (= 7.1.3) @@ -353,55 +352,50 @@ GEM thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) rainbow (3.1.1) - rake (13.1.0) + rake (13.2.1) rb-fsevent (0.11.2) - rb-inotify (0.10.1) + rb-inotify (0.11.1) ffi (~> 1.0) - rbs (2.8.4) + rbs (3.6.1) + logger rdbg (0.1.0) debug (>= 1.2.2) - rdoc (6.6.2) + rdoc (6.8.1) psych (>= 4.0.0) - regexp_parser (2.9.0) - reline (0.4.3) + regexp_parser (2.9.2) + reline (0.5.11) io-console (~> 0.5) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) - reverse_markdown (2.1.1) - nokogiri - rexml (3.2.6) + rexml (3.3.9) rollbar (3.5.1) - rubocop (1.60.2) + rubocop (1.69.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.30.0, < 2.0) + regexp_parser (>= 2.4, < 3.0) + rubocop-ast (>= 1.36.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.30.0) - parser (>= 3.2.1.0) - rubocop-rails (2.23.1) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.36.1) + parser (>= 3.3.1.0) + rubocop-rails (2.27.0) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.33.0, < 2.0) - rubocop-ast (>= 1.30.0, < 2.0) - ruby-lsp (0.13.4) + rubocop (>= 1.52.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-lsp (0.22.1) language_server-protocol (~> 3.17.0) - prism (>= 0.19.0, < 0.20) + prism (>= 1.2, < 2.0) + rbs (>= 3, < 4) sorbet-runtime (>= 0.5.10782) - ruby-lsp-rails (0.2.9) - actionpack (>= 6.0) - activerecord (>= 6.0) - railties (>= 6.0) - ruby-lsp (>= 0.13.0, < 0.14.0) - sorbet-runtime (>= 0.5.9897) + ruby-lsp-rails (0.3.27) + ruby-lsp (>= 0.22.0, < 0.23.0) ruby-progressbar (1.13.0) ruby-rc4 (0.1.5) ruby-saml (1.17.0) @@ -423,23 +417,7 @@ GEM snaky_hash (2.0.1) hashie version_gem (~> 1.1, >= 1.1.1) - solargraph (0.50.0) - backport (~> 1.2) - benchmark - bundler (~> 2.0) - diff-lcs (~> 1.4) - e2mmap - jaro_winkler (~> 1.5) - kramdown (~> 2.3) - kramdown-parser-gfm (~> 1.1) - parser (~> 3.0) - rbs (~> 2.0) - reverse_markdown (~> 2.0) - rubocop (~> 1.38) - thor (~> 1.0) - tilt (~> 2.0) - yard (~> 0.9, >= 0.9.24) - sorbet-runtime (0.5.11247) + sorbet-runtime (0.5.11668) sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) @@ -449,7 +427,7 @@ GEM sprockets (>= 3.0.0) stimulus-rails (1.3.3) railties (>= 6.0.0) - stringio (3.1.0) + stringio (3.1.2) tailwindcss-rails (2.3.0) railties (>= 6.0.0) tailwindcss-rails (2.3.0-aarch64-linux) @@ -460,9 +438,8 @@ GEM railties (>= 6.0.0) tailwindcss-rails (2.3.0-x86_64-linux) railties (>= 6.0.0) - thor (1.3.1) - tilt (2.3.0) - timeout (0.4.1) + thor (1.3.2) + timeout (0.4.2) ttfunk (1.7.0) turbo-rails (2.0.2) actionpack (>= 6.0.0) @@ -470,7 +447,9 @@ GEM railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.5.0) + unicode-display_width (3.1.2) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) uri (0.13.0) version_gem (1.1.3) view_component (3.10.0) @@ -486,7 +465,6 @@ GEM addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.8.1) websocket (1.2.10) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) @@ -496,8 +474,7 @@ GEM zeitwerk (>= 2.6) xpath (3.2.0) nokogiri (~> 1.8) - yard (0.9.34) - zeitwerk (2.6.13) + zeitwerk (2.7.1) PLATFORMS aarch64-linux @@ -508,6 +485,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + actioncable-enhanced-postgresql-adapter annotate bootsnap (>= 1.4.4) brakeman @@ -543,11 +521,11 @@ DEPENDENCIES rollbar rubocop rubocop-rails + ruby-lsp ruby-lsp-rails rubyzip selenium-webdriver simplecov - solargraph sprockets-rails stimulus-rails tailwindcss-rails diff --git a/app/controllers/message_threads_controller.rb b/app/controllers/message_threads_controller.rb index 1c1f6b832..2d69c9ab6 100644 --- a/app/controllers/message_threads_controller.rb +++ b/app/controllers/message_threads_controller.rb @@ -10,8 +10,13 @@ class MessageThreadsController < ApplicationController after_action :mark_thread_as_read, only: %i[show history] before_action :set_reload + def index + authorize MessageThread + end + def show authorize @message_thread + @notify = params[:notify] end def rename @@ -29,10 +34,6 @@ def update end end - def index - authorize MessageThread - end - def scroll authorize MessageThread end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index c8abef70b..9e86fd379 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -39,7 +39,7 @@ def authorize_delivery_notification @message.transaction do if Govbox::AuthorizeDeliveryNotificationAction.run(@message) - redirect_to message_thread_path(@message.thread), notice: 'Správa bola zaradená na prevzatie' + redirect_to message_thread_path(@message.thread, notify: true), notice: 'Správa bola zaradená na prevzatie' else redirect_to message_thread_path(@message.thread), alert: 'Správu nie je možné prevziať' end diff --git a/app/jobs/govbox/authorize_delivery_notification_job.rb b/app/jobs/govbox/authorize_delivery_notification_job.rb index b181865cf..5fd3777f8 100644 --- a/app/jobs/govbox/authorize_delivery_notification_job.rb +++ b/app/jobs/govbox/authorize_delivery_notification_job.rb @@ -19,6 +19,6 @@ def perform(message, upvs_client: UpvsEnvironment.upvs_client) # folder is not available in UPVS get_message response, therefore we're using corresponding inbox as target folder folder = Govbox::Folder.where(box: message.thread.box, name: "Inbox", system: true).first - Govbox::DownloadMessageJob.perform_later(folder, target_message_id) + Govbox::DownloadMessageJob.perform_later(folder, target_message_id, notify: true) end end diff --git a/app/jobs/govbox/download_message_job.rb b/app/jobs/govbox/download_message_job.rb index 7b5fa9ba6..43bed7933 100644 --- a/app/jobs/govbox/download_message_job.rb +++ b/app/jobs/govbox/download_message_job.rb @@ -1,6 +1,6 @@ module Govbox class DownloadMessageJob < ApplicationJob - def perform(govbox_folder, edesk_message_id, upvs_client: UpvsEnvironment.upvs_client) + def perform(govbox_folder, edesk_message_id, upvs_client: UpvsEnvironment.upvs_client, notify: false) edesk_api = upvs_client.api(govbox_folder.box).edesk response_status, raw_message = edesk_api.fetch_message(edesk_message_id) @@ -16,7 +16,7 @@ def perform(govbox_folder, edesk_message_id, upvs_client: UpvsEnvironment.upvs_c govbox_message.payload = raw_message end - ProcessMessageJob.perform_later(govbox_message) + ProcessMessageJob.perform_later(govbox_message, notify: notify) end end end diff --git a/app/jobs/govbox/process_message_job.rb b/app/jobs/govbox/process_message_job.rb index 295ce51d7..6273ac90d 100644 --- a/app/jobs/govbox/process_message_job.rb +++ b/app/jobs/govbox/process_message_job.rb @@ -4,7 +4,7 @@ module Govbox class ProcessMessageJob < ApplicationJob retry_on ::ApplicationRecord::FailedToAcquireLockError, wait: :polynomially_longer, attempts: Float::INFINITY - def perform(govbox_message) + def perform(govbox_message, notify: false) processed_message = ::Message.not_drafts.where(uuid: govbox_message.message_id).joins(:thread).where(thread: { box_id: govbox_message.box.id }).take ActiveRecord::Base.transaction do @@ -15,6 +15,7 @@ def perform(govbox_message) collapse_referenced_outbox_message(message) create_message_relations(message) download_upvs_form_related_documents(message) + notify_gui_message_created(message) if notify end unless processed_message end @@ -95,5 +96,9 @@ def download_upvs_form_related_documents(message) ::Upvs::DownloadFormRelatedDocumentsJob.perform_later(upvs_form) if upvs_form end end + + def notify_gui_message_created(message) + broadcast_render_later_to message.thread, partial: "messages/new_message_alert", locals: { message: message } + end end end diff --git a/app/views/message_threads/show.html.erb b/app/views/message_threads/show.html.erb index 7137736bd..fe6db27ff 100644 --- a/app/views/message_threads/show.html.erb +++ b/app/views/message_threads/show.html.erb @@ -4,3 +4,8 @@ thread_messages: @thread_messages, thread_last_message_draft_id: @thread_last_message_draft_id ) %> +<% if @notify %> + <%= turbo_frame_tag :new_messages_frame, target: "_top" do %> + <%= turbo_stream_from @message_thread %> + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/messages/_new_message_alert.turbo_stream.erb b/app/views/messages/_new_message_alert.turbo_stream.erb new file mode 100644 index 000000000..b5a7dad35 --- /dev/null +++ b/app/views/messages/_new_message_alert.turbo_stream.erb @@ -0,0 +1,34 @@ +
+
+
+
+
+ +
+
+

+ <%= link_to "Doručená nová správa, klikni pre prečítanie", message_path(message), class: "underline" %> +

+
+
+
+ +
+
+
+
+
+
\ No newline at end of file diff --git a/config/cable.yml b/config/cable.yml index 6b8ebb62d..818d8394d 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -1,11 +1,8 @@ development: - adapter: redis - url: redis://localhost:6379/1 + adapter: enhanced_postgresql test: - adapter: test + adapter: enhanced_postgresql production: - adapter: redis - url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> - channel_prefix: govbox_pro_production + adapter: enhanced_postgresql