Skip to content

Commit

Permalink
問い合わせが来たら管理者に対してピヨルドから通知をするようにした。
Browse files Browse the repository at this point in the history
  • Loading branch information
a-kuroki-gs authored and goruchanchan committed Mar 26, 2024
1 parent b58970e commit 994be36
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 27 deletions.
11 changes: 10 additions & 1 deletion app/controllers/inquiries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
27 changes: 2 additions & 25 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions app/notifiers/activity_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion db/fixtures/discord_profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ discord_profile_nagai-kyuukai:
account_name:
times_url:

discord_profire_pjord:
discord_profile_pjord:
user: pjord
account_name:
times_url:
Binary file added db/fixtures/files/users/avatars/pjord.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -962,3 +962,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: [email protected]
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"
17 changes: 17 additions & 0 deletions test/notifiers/activity_notifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 994be36

Please sign in to comment.