diff --git a/app/controllers/inquiries_controller.rb b/app/controllers/inquiries_controller.rb index ceac6676435..f0bd71c7ec3 100644 --- a/app/controllers/inquiries_controller.rb +++ b/app/controllers/inquiries_controller.rb @@ -10,9 +10,10 @@ def new def create @inquiry = Inquiry.new(inquiry_params) - result = valid_recaptcha?('inquiry') + if result && @inquiry.save + Newspaper.publish(:came_inquiry, { inquiry: @inquiry }) InquiryMailer.incoming(@inquiry).deliver_later redirect_to new_inquiry_url, notice: 'お問い合わせを送信しました。' else diff --git a/app/models/inquiry_notifier.rb b/app/models/inquiry_notifier.rb new file mode 100644 index 00000000000..fc51872db3a --- /dev/null +++ b/app/models/inquiry_notifier.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class InquiryNotifier + NOTIFICATION_SENDER_NAME = 'pjord' + + def call(payload) + inquiry = payload[:inquiry] + return if inquiry.nil? + + sender = User.find_by(login_name: NOTIFICATION_SENDER_NAME) + User.admins.each do |receiver| + ActivityDelivery.with(inquiry:, receiver:, sender:).notify(:came_inquiry) + end + end +end diff --git a/app/models/notification.rb b/app/models/notification.rb index 6d6b615cd24..ad21fcb7b99 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -41,7 +41,8 @@ class Notification < ApplicationRecord no_correct_answer: 22, comebacked: 23, create_article: 24, - added_work: 25 + added_work: 25, + came_inquiry: 26 } scope :unreads, -> { where(read: false) } @@ -60,30 +61,6 @@ class Notification < ApplicationRecord after_update NotificationCallbacks.new after_destroy NotificationCallbacks.new - class << self - def checked(check) - Notification.create!( - kind: kinds[:checked], - user: check.receiver, - sender: check.sender, - link: Rails.application.routes.url_helpers.polymorphic_path(check.checkable), - message: "#{check.sender.login_name}さんが#{check.checkable.title}を確認しました。", - read: false - ) - end - - def came_answer(answer) - Notification.create!( - kind: kinds[:answered], - user: answer.receiver, - sender: answer.sender, - link: Rails.application.routes.url_helpers.polymorphic_path(answer.question), - message: "#{answer.user.login_name}さんから回答がありました。", - read: false - ) - end - end - def unread? !read end diff --git a/app/notifiers/activity_notifier.rb b/app/notifiers/activity_notifier.rb index e2e19a02937..0ab2e4df326 100644 --- a/app/notifiers/activity_notifier.rb +++ b/app/notifiers/activity_notifier.rb @@ -383,4 +383,20 @@ def added_work(params = {}) read: false ) end + + def came_inquiry(params = {}) + params.merge!(@params) + inquiry = params[:inquiry] + sender = params[:sender] + receiver = params[:receiver] + + notification( + body: "#{inquiry.name}さんから問い合わせがありました。", + kind: :came_inquiry, + receiver:, + sender:, + link: Rails.application.routes.url_helpers.admin_inquiry_path(inquiry), + read: false + ) + end end diff --git a/config/initializers/newspaper.rb b/config/initializers/newspaper.rb index 9f72148d637..f8df39bc4f1 100644 --- a/config/initializers/newspaper.rb +++ b/config/initializers/newspaper.rb @@ -76,4 +76,6 @@ Newspaper.subscribe(:work_create, WorkNotifier.new) Newspaper.subscribe(:work_destroy, WorkNotificationDestroyer.new) + + Newspaper.subscribe(:came_inquiry, InquiryNotifier.new) end diff --git a/db/fixtures/discord_profiles.yml b/db/fixtures/discord_profiles.yml index aaf9581f370..19d25b16257 100644 --- a/db/fixtures/discord_profiles.yml +++ b/db/fixtures/discord_profiles.yml @@ -286,7 +286,7 @@ discord_profile_nagai-kyuukai: times_url: https://discord.com/channels/1079802367970656257/1224708078847397908 times_id: 1224708078847397908 -discord_profire_pjord: +discord_profile_pjord: user: pjord account_name: times_url: diff --git a/db/fixtures/files/users/avatars/pjord.jpg b/db/fixtures/files/users/avatars/pjord.jpg new file mode 100644 index 00000000000..7ecce2f41ff Binary files /dev/null and b/db/fixtures/files/users/avatars/pjord.jpg differ diff --git a/db/fixtures/talks.yml b/db/fixtures/talks.yml index 6c67800518a..2bc7096adfe 100644 --- a/db/fixtures/talks.yml +++ b/db/fixtures/talks.yml @@ -228,6 +228,6 @@ talk_kensyu-not-setting-end-date: user: kensyu-not-setting-end-date action_completed: true -talk_harikirio: - user: harikirio +talk_pjord: + user: pjord action_completed: true diff --git a/db/fixtures/users.yml b/db/fixtures/users.yml index e0dca5c87cd..457a9bf76ac 100644 --- a/db/fixtures/users.yml +++ b/db/fixtures/users.yml @@ -1405,7 +1405,7 @@ paginataion-jirou: pjord: login_name: pjord - email: + email: pjord@fjord.jp crypted_password: $2a$10$n/xv4/1luueN6plzm2OyDezWlZFyGHjQEf4hwAW1r3k.lCm0frPK. # testtest salt: zW3kQ9ubsxQQtzzzs4ap name: ピヨルド @@ -1418,7 +1418,7 @@ pjord: course: course1 company: company1 admin: true - mentor: false + mentor: true unsubscribe_email_token: Xw-T0PjrO2LTkCx1C8KA9w updated_at: "2024-03-09 00:00:30" created_at: "2024-03-05 00:00:30" diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index ea3075c80b6..b18d35d2994 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -1018,3 +1018,21 @@ harikirio: #必修でないプラクティスも修了しているユーザー created_at: "2020-01-01 00:00:12" sent_student_followup_message: true last_activity_at: "2020-01-01 00:00:12" + +pjord: + login_name: pjord + email: pjord@fjord.jp + crypted_password: $2a$10$n/xv4/1luueN6plzm2OyDezWlZFyGHjQEf4hwAW1r3k.lCm0frPK. # testtest + salt: zW3kQ9ubsxQQtzzzs4ap + name: ピヨルド + name_kana: ピヨルド + company: company1 + description: "管理者のピヨルドです。バイキングの末裔です。" + course: course1 + job: office_worker + os: 回答なし + admin: true + adviser: true + updated_at: "2014-01-01 00:00:01" + created_at: "2014-01-01 00:00:01" + last_activity_at: "2014-01-01 00:00:01" diff --git a/test/models/generation_test.rb b/test/models/generation_test.rb index b954aa57ecf..ea3ec9883ce 100644 --- a/test/models/generation_test.rb +++ b/test/models/generation_test.rb @@ -35,7 +35,7 @@ class GenerationTest < ActiveSupport::TestCase assert_equal 3, Generation.new(5).count_classmates_by_target(:trainees) assert_equal 1, Generation.new(5).count_classmates_by_target(:hibernated) assert_equal 2, Generation.new(5).count_classmates_by_target(:graduated) - assert_equal 2, Generation.new(5).count_classmates_by_target(:advisers) + assert_equal 3, Generation.new(5).count_classmates_by_target(:advisers) assert_equal 2, Generation.new(5).count_classmates_by_target(:retired) end end diff --git a/test/notifiers/activity_notifier_test.rb b/test/notifiers/activity_notifier_test.rb index fa082caa190..c0dc34b3950 100644 --- a/test/notifiers/activity_notifier_test.rb +++ b/test/notifiers/activity_notifier_test.rb @@ -144,4 +144,21 @@ class ActivityNotifierTest < ActiveSupport::TestCase notification.notify_later end end + + test '#came_inquiry' do + params = { + inquiry: Inquiry.first, + sender: users(:pjord), + receiver: users(:komagata) + } + notification = ActivityNotifier.with(params).came_inquiry + + assert_difference -> { AbstractNotifier::Testing::Driver.deliveries.count }, 1 do + notification.notify_now + end + + assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 1 do + notification.notify_later + end + end end