diff --git a/app/controllers/inquiries_controller.rb b/app/controllers/inquiries_controller.rb index ceac6676435..6cc0da406fc 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 + notify_inquiry InquiryMailer.incoming(@inquiry).deliver_later redirect_to new_inquiry_url, notice: 'お問い合わせを送信しました。' else @@ -26,4 +27,12 @@ def create def inquiry_params params.require(:inquiry).permit(:name, :email, :body, :privacy_policy) end + + def notify_inquiry + sender = User.find_by(login_name: 'pjord') + + User.admins.each do |receiver| + ActivityDelivery.with(inquiry: @inquiry, receiver:, sender:).notify(:came_inquiry) + end + end end diff --git a/app/models/notification.rb b/app/models/notification.rb index 3a6e2eaedbd..b991079e30a 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -39,7 +39,8 @@ class Notification < ApplicationRecord signed_up: 20, regular_event_updated: 21, no_correct_answer: 22, - comebacked: 23 + comebacked: 23, + came_inquiry: 24 } scope :unreads, -> { where(read: false) } @@ -58,30 +59,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 10acaa518e7..4314a7216f6 100644 --- a/app/notifiers/activity_notifier.rb +++ b/app/notifiers/activity_notifier.rb @@ -367,4 +367,20 @@ def moved_up_event_waiting_user(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/db/fixtures/discord_profiles.yml b/db/fixtures/discord_profiles.yml index 0197813a856..de9bb8ca35c 100644 --- a/db/fixtures/discord_profiles.yml +++ b/db/fixtures/discord_profiles.yml @@ -264,3 +264,8 @@ discord_profile_nagai-kyuukai: user: nagai-kyuukai account_name: times_url: + +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/users.yml b/db/fixtures/users.yml index 073a04284fa..97141c4142f 100644 --- a/db/fixtures/users.yml +++ b/db/fixtures/users.yml @@ -1251,3 +1251,21 @@ nagai-kyuukai: created_at: "2014-01-01 00:00:13" sent_student_followup_message: true last_activity_at: "2014-01-01 00:00:04" + +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/fixtures/users.yml b/test/fixtures/users.yml index 2d7092ff104..60921d25238 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -930,3 +930,21 @@ marumarushain<%= i %>: # ページネーション確認のためのユーザー last_activity_at: "2014-01-01 00:00:0<%= 2 + (i - 1) / 2 %>" sent_student_followup_message: true <% end %> + +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/notifiers/activity_notifier_test.rb b/test/notifiers/activity_notifier_test.rb index 7359a9cc983..0ac85271876 100644 --- a/test/notifiers/activity_notifier_test.rb +++ b/test/notifiers/activity_notifier_test.rb @@ -156,4 +156,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