From c73f35fc82785a00059ecf894fc2b0365304ee63 Mon Sep 17 00:00:00 2001 From: a-kuroki-gs Date: Fri, 9 Feb 2024 10:56:25 +0900 Subject: [PATCH] =?UTF-8?q?=E5=95=8F=E3=81=84=E5=90=88=E3=82=8F=E3=81=9B?= =?UTF-8?q?=E3=81=8C=E6=9D=A5=E3=81=9F=E3=82=89=E7=AE=A1=E7=90=86=E8=80=85?= =?UTF-8?q?=E3=81=AB=E5=AF=BE=E3=81=97=E3=81=A6=E3=83=94=E3=83=A8=E3=83=AB?= =?UTF-8?q?=E3=83=89=E3=81=8B=E3=82=89=E9=80=9A=E7=9F=A5=E3=82=92=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/inquiries_controller.rb | 11 ++++++++- app/models/notification.rb | 27 ++-------------------- app/notifiers/activity_notifier.rb | 16 +++++++++++++ db/fixtures/discord_profiles.yml | 2 +- db/fixtures/files/users/avatars/pjord.jpg | Bin 0 -> 4100 bytes test/fixtures/users.yml | 18 +++++++++++++++ test/notifiers/activity_notifier_test.rb | 17 ++++++++++++++ 7 files changed, 64 insertions(+), 27 deletions(-) create mode 100644 db/fixtures/files/users/avatars/pjord.jpg 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 b4f679d6439..8fddba00d3e 100644 --- a/app/notifiers/activity_notifier.rb +++ b/app/notifiers/activity_notifier.rb @@ -352,4 +352,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 a49ebfe138a..9df7a00b204 100644 --- a/db/fixtures/discord_profiles.yml +++ b/db/fixtures/discord_profiles.yml @@ -285,7 +285,7 @@ discord_profile_nagai-kyuukai: account_name: times_url: -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 0000000000000000000000000000000000000000..7ecce2f41ff80a3520b593d6818002c38e0e4a86 GIT binary patch literal 4100 zcmZ{nXEYlC*T-YUC?(X6(HONGt5)sUTVgA*YlIpRT51zYQ`H)^N^4b7wQA2&vxvQS zQG%j2Z{IJ^InRgZ!@a-rzvukU{c^wDcw<8?8Y(s_002OvqYX3tN6Y^&ihm7&xc1rn z2VzG(Eg0Y?4mZ&HFOdi67-*1hl8{l+u^B7)hV~c!NcUw5jzJ>GfUnuswShNuf-TmG56uAg6d-CL&r|^@@&# zb5T-F)Nh%2cb(F8FzlkO(3)*WLGX7C+%4gq2q{3HIrWZQptZmz^N*bt)q3L=!c_k2 z?TRE$b&7%K%d4x>$N@U$wI)ses+jj2@8lGd4-6%9WO|OI=*}$P%EvJ4CtPj@{t06! zDt}=3y|fb$-VWVGo+0q(io)t-z`I*zjoDYH?A<>GoXq2!KHdt!_-%5|pk!gM@11s0 zU@O%vyylx8heMw9UML=^pHo#@F_2=_mFpT5=2^+nQ~lCkkwcle(wF0cqA!JZ@^$Bu zIbL8VskY;>X(*%isWM6Wivfl9TNjibENKgOhvH>9D5*1wvqQC3{FXRo(&U3Wzc?6h zA}`3>S)R`=Og}-<^RK17tz#JBAI}O%PHNPq2mM09D+4JrpBW9^367_=pnF97b7vp0 zN97<%6@O@GkkGw!!r|QPyYXi|x@0m9_7mL^YYaKF@TW9A(ZJU-;a z%Q4`l*XR6AT5yyPt?MPs8P5YWmrf>74x8vi*?WDOdw)V_iox5!mbd%b3~8HmOc;|s zEeBIU9ZsaqQ<@YBs~`K?;>JPQS-B@FD}pPqJ)V}2!C5T;B=Se+GAtBb#ov z|MLx_(IO8-Xov4>dS{ZGX@sw9e$S>j?Ok+0Du~Vbp4Wsx@PGU?v9@pNxp5<>i z`z1yeRFtLN^f>KX=v|1|MT5=!dr*?tUO_1XSuw=%j!(Z;x~v&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xUPH5S{IUfWe(@sV6-n2+QKp!?Ed=H=8=`lE zze+xLAUP=alrE`o%`LzZS3F`*8x7v}P>F^Y5cF?+2Nlw_2^z%A@>_p0oQ( zRNxbS%DkEsY0Qk&_6SzE!*hE&WZU0ufy)$D3^`9?%S>h}C93{_L4ZJv_Ys0=6X$Q5 zz9Nf4!@@|*ME0|(?*BXTHY6FKFkaXG3eDjgpVc#(;rmDu6I9ynjB#}g&ZMx`9fxEXrf?8H+qr>1R1-5F!xsq)6l&m zv$&S9?&64Kwp`@LiLWmfpW8<)7>VrgD4Y{574}f!cyr~C)cK?;drNwoJCc9}ZCHhw zffMgvznIKSRBi^WbRsWZ{{p`FFB4Fu4$Wx7Z0TEb6(8yckB<{=K5uN8zaV{75y!>B zNWfGRUvp`!@@p$TSvnk#vG93gE-fP~3xL*4ct7>pUwZR}ocb^A1}`wLz1*49K&|6W zNli&!dHuY{$Y!lW@+XuoQb}wt<0F41e(ZPQ zR`Z^kIb|cX5_fpD`nKJ}z5^AIy_3ZKjip6VWx2-5%Fd)b{&uvvFC|HY3?G&9&aYni zYwm(5puf$QmjP&ht340`9D6)tV1ovj{SxI{$suX4a)#$ zhX5COCqI{e07yV3q(q^TqEKmsI8dF6h$_tZ^|2Y614MSMD8Zz?#005DlU;qFB literal 0 HcmV?d00001 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 9eb74b51342..def66ff83c4 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -963,3 +963,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 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