From b623acadbb200be315fd46c042e529c48ca9189a Mon Sep 17 00:00:00 2001 From: nicole2525 Date: Wed, 3 Jan 2024 15:12:54 +0900 Subject: [PATCH] =?UTF-8?q?newspaper=E3=81=AE=E5=BC=95=E6=95=B0=E3=82=92?= =?UTF-8?q?=E3=83=8F=E3=83=83=E3=82=B7=E3=83=A5=E3=81=A7=E3=81=AE=E5=8F=97?= =?UTF-8?q?=E3=81=91=E6=B8=A1=E3=81=97=E3=81=AB=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin/users_controller.rb | 2 +- app/controllers/api/checks_controller.rb | 2 +- app/controllers/api/practices/learning_controller.rb | 2 +- app/controllers/comeback_controller.rb | 2 +- app/controllers/products_controller.rb | 6 +++--- app/models/comeback_notifier.rb | 3 ++- app/models/comment/after_create_callback.rb | 4 ++-- app/models/comment_notifier.rb | 3 ++- app/models/comment_notifier_for_admin.rb | 3 ++- app/models/learning_cache_destroyer.rb | 3 ++- app/models/learning_status_updater.rb | 8 +------- app/models/product_author_watcher.rb | 3 ++- app/models/product_notifier_for_colleague.rb | 8 +------- app/models/product_notifier_for_practice_watcher.rb | 3 ++- test/models/product_notifier_for_practice_watcher_test.rb | 2 +- 15 files changed, 24 insertions(+), 30 deletions(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index a1f66f9a587..f2df8fc6d2f 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -35,7 +35,7 @@ def destroy # 制限をかけておく redirect_to admin_users_url, alert: '自分自身を削除する場合、退会から処理を行ってください。' if current_user.id == params[:id] user = User.find(params[:id]) - Newspaper.publish(:learning_destroy, user) + Newspaper.publish(:learning_destroy, { user: }) user.destroy redirect_to admin_users_url, notice: "#{user.name} さんを削除しました。" end diff --git a/app/controllers/api/checks_controller.rb b/app/controllers/api/checks_controller.rb index b1c440a9502..dceffef8721 100644 --- a/app/controllers/api/checks_controller.rb +++ b/app/controllers/api/checks_controller.rb @@ -15,7 +15,7 @@ def create user: current_user, checkable: checkable ) - Newspaper.publish(:check_create, @check) + Newspaper.publish(:check_create, { check: @check }) head :created else render json: { message: "この#{checkable.class.model_name.human}は確認済です。" }, status: :unprocessable_entity diff --git a/app/controllers/api/practices/learning_controller.rb b/app/controllers/api/practices/learning_controller.rb index 98b39dd944d..c2a78f99d8c 100644 --- a/app/controllers/api/practices/learning_controller.rb +++ b/app/controllers/api/practices/learning_controller.rb @@ -29,7 +29,7 @@ def update status = learning.new_record? ? :created : :ok if learning.save - Newspaper.publish(:learning_create, learning.user) + Newspaper.publish(:learning_create, { user: learning.user }) notify_to_chat_for_employment_counseling(learning) if status == :created && learning.practice.title == '就職相談部屋を作る' head status else diff --git a/app/controllers/comeback_controller.rb b/app/controllers/comeback_controller.rb index ed2f7f7576c..abf51bd5b5d 100644 --- a/app/controllers/comeback_controller.rb +++ b/app/controllers/comeback_controller.rb @@ -12,7 +12,7 @@ def create if @user if @user&.hibernated? @user.comeback! - Newspaper.publish(:comeback_update, @user) + Newspaper.publish(:comeback_update, { user: @user }) @user.create_comebacked_comment redirect_to root_url, notice: '休会から復帰しました。' else diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index df1726d4bf0..aec239e73b4 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -40,8 +40,8 @@ def create set_wip update_published_at if @product.save - Newspaper.publish(:product_create, @product) - Newspaper.publish(:product_save, @product) + Newspaper.publish(:product_create, { product: @product }) + Newspaper.publish(:product_save, { product: @product }) redirect_to Redirection.determin_url(self, @product), notice: notice_message(@product, :create) else render :new @@ -56,7 +56,7 @@ def update update_published_at if @product.update(product_params) Newspaper.publish(:product_update, { product: @product, current_user: current_user }) - Newspaper.publish(:product_save, @product) + Newspaper.publish(:product_save, { product: @product }) notice_another_mentor_assigned_as_checker redirect_to Redirection.determin_url(self, @product), notice: notice_message(@product, :update) else diff --git a/app/models/comeback_notifier.rb b/app/models/comeback_notifier.rb index fdc4124da76..1112ba9da18 100644 --- a/app/models/comeback_notifier.rb +++ b/app/models/comeback_notifier.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true class ComebackNotifier - def call(user) + def call(payload) + user = payload[:user] User.admins_and_mentors.each do |admin_or_mentor| ActivityDelivery.with(sender: user, receiver: admin_or_mentor).notify(:comebacked) end diff --git a/app/models/comment/after_create_callback.rb b/app/models/comment/after_create_callback.rb index 12c8b6df8bf..47d79dc161e 100644 --- a/app/models/comment/after_create_callback.rb +++ b/app/models/comment/after_create_callback.rb @@ -6,7 +6,7 @@ def after_commit(comment) create_watch(comment) notify_to_watching_user(comment) elsif comment.sender != comment.receiver - Newspaper.publish(:came_comment, comment) + Newspaper.publish(:came_comment, { comment: }) end if comment.commentable.instance_of?(Talk) @@ -74,7 +74,7 @@ def delete_assigned_and_unreplied_product_count_cache(comment) end def notify_to_admins(comment) - Newspaper.publish(:came_comment_in_talk, comment) + Newspaper.publish(:came_comment_in_talk, { comment: }) end def update_action_completed(comment) diff --git a/app/models/comment_notifier.rb b/app/models/comment_notifier.rb index b2fc09f6a46..0521a64b523 100644 --- a/app/models/comment_notifier.rb +++ b/app/models/comment_notifier.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true class CommentNotifier - def call(comment) + def call(payload) + comment = payload[:comment] return if comment.nil? commentable_path = Rails.application.routes.url_helpers.polymorphic_path(comment.commentable) diff --git a/app/models/comment_notifier_for_admin.rb b/app/models/comment_notifier_for_admin.rb index f225c0e5c38..8fbccef066d 100644 --- a/app/models/comment_notifier_for_admin.rb +++ b/app/models/comment_notifier_for_admin.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true class CommentNotifierForAdmin - def call(comment) + def call(payload) + comment = payload[:comment] return if comment.nil? User.admins.each do |admin_user| diff --git a/app/models/learning_cache_destroyer.rb b/app/models/learning_cache_destroyer.rb index f6c5a536449..47b9ff43df8 100644 --- a/app/models/learning_cache_destroyer.rb +++ b/app/models/learning_cache_destroyer.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true class LearningCacheDestroyer - def call(user) + def call(payload) + user = payload[:user] Rails.cache.delete "/model/user/#{user.id}/completed_percentage" end end diff --git a/app/models/learning_status_updater.rb b/app/models/learning_status_updater.rb index 52506535ca0..e2d2c0e7a06 100644 --- a/app/models/learning_status_updater.rb +++ b/app/models/learning_status_updater.rb @@ -2,13 +2,7 @@ class LearningStatusUpdater def call(payload) - product_or_associated_object = - case payload - when Hash - payload[:product] - else - payload - end + product_or_associated_object = payload[:product] || payload[:check] case product_or_associated_object when Product update_after_submission(product_or_associated_object) diff --git a/app/models/product_author_watcher.rb b/app/models/product_author_watcher.rb index 5af730aa1b6..d92cee7bb41 100644 --- a/app/models/product_author_watcher.rb +++ b/app/models/product_author_watcher.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true class ProductAuthorWatcher - def call(product) + def call(payload) + product = payload[:product] Watch.create!(user: product.user, watchable: product) end end diff --git a/app/models/product_notifier_for_colleague.rb b/app/models/product_notifier_for_colleague.rb index 3e1975c4ba4..7840a322ac3 100644 --- a/app/models/product_notifier_for_colleague.rb +++ b/app/models/product_notifier_for_colleague.rb @@ -2,13 +2,7 @@ class ProductNotifierForColleague def call(payload) - product = - case payload - when Hash - payload[:product] - else - payload - end + product = payload[:product] return if product.wip notify_advisers product if product.user.trainee? && product.user.company diff --git a/app/models/product_notifier_for_practice_watcher.rb b/app/models/product_notifier_for_practice_watcher.rb index ade0182ad30..87a2162cf97 100644 --- a/app/models/product_notifier_for_practice_watcher.rb +++ b/app/models/product_notifier_for_practice_watcher.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true class ProductNotifierForPracticeWatcher - def call(product) + def call(payload) + product = payload[:product] return if product.wip practice = Practice.find(product.practice_id) diff --git a/test/models/product_notifier_for_practice_watcher_test.rb b/test/models/product_notifier_for_practice_watcher_test.rb index f1059aa8c01..6e27188b383 100644 --- a/test/models/product_notifier_for_practice_watcher_test.rb +++ b/test/models/product_notifier_for_practice_watcher_test.rb @@ -24,7 +24,7 @@ class ProductNotifierForPracticeWatcherTest < ActiveSupport::TestCase product.save! perform_enqueued_jobs do - ProductNotifierForPracticeWatcher.new.call(product) + ProductNotifierForPracticeWatcher.new.call({ product: }) end assert Notification.where(user_id: watch.user_id, sender_id: product.user_id, message: "#{product.user.login_name}さんが「#{product.practice.title}」の提出物を提出しました。").exists?