Skip to content

NewsPaperからActiveSupport::Notificationsに3クラス分実装を置き換える#8935

Merged
komagata merged 9 commits intomainfrom
chore/replace-creator-and-notifier
Aug 22, 2025
Merged

NewsPaperからActiveSupport::Notificationsに3クラス分実装を置き換える#8935
komagata merged 9 commits intomainfrom
chore/replace-creator-and-notifier

Conversation

@thmz337
Copy link
Copy Markdown
Contributor

@thmz337 thmz337 commented Jul 15, 2025

Issue

概要

下記の2クラスの実装を、newspaperからActiveSupport::Notificationsに置き換えました。

  • TimesChannelCreator
    • 生徒・研修生を作成した際に、Discord上に分報チャンネルを作成するクラス
  • RegularEventUpdateNotifier
    • 定期イベント更新時に、参加者にメールで通知を行うクラス

また、下記のクラスを削除しました。

  • SignUpNotifier
    • メール配信停止用の一意なトークンを生成して、ユーザーオブジェクトの属性に設定するクラス

変更確認方法

  1. chore/replace-creator-and-notifierをローカルに取り込む
  2. TimesChannelCreatorのログ確認
    1. トップ画面から参加登録を押下し、ユーザー登録を行う。
      • コンソール上で[Discord API] #{ユーザー名}の分報チャンネルが作成できませんでした。というアラートが出ていることを確認する。(開発環境では分報チャンネルを作成できないため)
    2. 管理者(komagata)でログインする。
      • 企業ページから、研修生招待リンクを押下し研修生の登録を行う。この時、特殊ユーザー属性を研修生とすること。image
      • コンソール上で[Discord API] #{ユーザー名}の分報チャンネルが作成できませんでした。というアラートが出ていることを確認する。
  3. RegularEventUpdateNotifierのメール確認
    • メールを受け取ることのできるユーザーでログインし、定期イベントのページから参加登録を行う。その後別のユーザーで定期イベントの更新を行う。最後にletter_openerを確認して、参加登録を行ったユーザー宛にメールが届いていることを確認する。
  4. SignUpNotifier削除後のメール通知解除動作確認
    1. トップ画面から参加登録を押下し、ユーザー登録を行う。
    2. 登録を行ったユーザーでログインし、相談部屋でコメントを入力する。
    3. komagataでログインし、コメントに返信をする。
    4. メールを確認し、登録を行ったユーザー宛にメールが届いていることを確認する。
    5. 当該メールから、メールでの通知オフはこちらからをクリックしメールの配信停止を行う。
    6. ⅰ~Ⅲまでの手順を再度行い、今度はメールが届いていないことを確認する。

Summary by CodeRabbit

  • 新機能

    • ユーザー作成時に「unsubscribe_email_token」が自動で付与されるようになりました。
  • バグ修正

    • ユーザー作成時の不要な通知処理が削除され、関連する重複や副作用が解消されました。
  • リファクタリング

    • 不要な通知ハンドラとイベント購読を削除・整理し、イベント購読の順序を調整しました。

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 15, 2025

Walkthrough

ユーザー作成時の user.create 通知サブスクリプション(SignUpNotifier)を削除し、controller 内で unsubscribe_email_token を直接生成して設定するように制御フローを移動。initializer 内で他の通知サブスクリプションの順序を整理。

Changes

Cohort / File(s) Change Summary
ユーザー作成処理の直接変更
app/controllers/users_controller.rb
ActiveSupport::Notifications.instrument('user.create', ...) を削除し、unsubscribe_email_tokenSecureRandom.urlsafe_base64 で生成・設定するロジックを追加。
サインアップ通知クラスの削除
app/models/sign_up_notifier.rb
SignUpNotifier クラスとその call メソッドを削除。
イベントサブスクリプションの整理
config/initializers/active_support_notifications.rb
user.create の購読を削除し、regular_event.update / student_or_trainee.create の購読を to_prepare ブロック内で前倒しに移動(順序変更)。

Sequence Diagram(s)

sequenceDiagram
  participant C as UsersController
  participant DB as User / DB
  participant OldN as SignUpNotifier (removed)

  rect rgba(200,230,255,0.4)
  Note right of C: 旧フロー(削除)
  C->>OldN: instrument 'user.create' (payload: user)
  OldN->>DB: set unsubscribe_email_token on user
  C->>DB: save user
  end

  rect rgba(200,255,200,0.3)
  Note right of C: 新フロー(現在)
  C->>C: generate unsubscribe_email_token (SecureRandom.urlsafe_base64)
  C->>DB: assign token & save user
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • komagata

Poem

うさぎがぽんとコード跳ね、
古い鈴はそっとはずしたよ。
小さなトークンは秘密の芽、
サインアップは穏やかに伸びる。
ぴょん 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 RuboCop (1.76.1)
app/controllers/users_controller.rb

rubocop-minitest extension supports plugin, specify plugins: rubocop-minitest instead of require: rubocop-minitest in /.rubocop.yml.
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
rubocop-capybara extension supports plugin, specify plugins: rubocop-capybara instead of require: rubocop-capybara in /.rubocop.yml.
For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
Unable to find gem rubocop-fjord; is the gem installed? Gem::MissingSpecError
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:309:in rescue in gem_config_path' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:293:in gem_config_path'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:84:in block (2 levels) in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:82:in reverse_each'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:82:in block in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:76:in each_pair'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader_resolver.rb:76:in resolve_inheritance_from_gems' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_loader.rb:58:in load_file'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/config_store.rb:29:in options_config=' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:162:in act_on_options'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:47:in block in run' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:82:in profile_if_needed'
/var/lib/gems/3.1.0/gems/rubocop-1.79.2/lib/rubocop/cli.rb:43:in run' /var/lib/gems/3.1.0/gems/rubocop-1.79.2/exe/rubocop:19:in <top (required)>'
/usr/local/bin/rubocop:25:in load' /usr/local/bin/rubocop:25:in

'

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between cd6e551 and fd09bb9.

📒 Files selected for processing (2)
  • app/controllers/users_controller.rb (1 hunks)
  • app/models/sign_up_notifier.rb (0 hunks)
💤 Files with no reviewable changes (1)
  • app/models/sign_up_notifier.rb
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/controllers/users_controller.rb
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/replace-creator-and-notifier

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@thmz337 thmz337 self-assigned this Jul 15, 2025
@thmz337 thmz337 force-pushed the chore/replace-creator-and-notifier branch from a3932b2 to 2228e3c Compare July 16, 2025 15:36
@thmz337 thmz337 marked this pull request as ready for review July 16, 2025 15:37
@machida
Copy link
Copy Markdown
Member

machida commented Jul 17, 2025

@thmz337
このPRにthmz337 さんをアサイン付けておきましたー
自分自身をPRの担当者につけておいていただけると、PRの一覧を見たときにすぐ誰のPRかわかるので助かります🙏

@thmz337
Copy link
Copy Markdown
Contributor Author

thmz337 commented Jul 17, 2025

@machida

ありがとうございます!以後忘れないようにします。

@thmz337
Copy link
Copy Markdown
Contributor Author

thmz337 commented Jul 17, 2025

@tyrrell-IH

お疲れ様です!こちらレビュー可能でしょうか?
ご確認よろしくお願いいたします。

@thmz337 thmz337 requested a review from tyrrell-IH July 17, 2025 15:10
@tyrrell-IH
Copy link
Copy Markdown
Contributor

@thmz337

レビューさせていただきます👍

土日祝が稼働できない可能性があるので、お返しできるのが週明けになると思います🙏

@thmz337
Copy link
Copy Markdown
Contributor Author

thmz337 commented Jul 19, 2025

@tyrrell-IH

お疲れ様です!ご確認ありがとうございます。
週明けで問題ございませんので、よろしくお願いいたします。

Copy link
Copy Markdown
Contributor

@tyrrell-IH tyrrell-IH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thmz337
レビューしました!
動作自体はOKでした!

コメントを1件残したのでご確認ください。

その他でもう2点確認したいことがあり、以下に書いてありますのでご確認ください。
私の指摘した事項について、わからない点、間違っている点等ありましたら遠慮なくおっしゃってください🙏

前提

現在のSignUpNotifierクラスは
「ユーザー登録時に通知を行うクラス」ではなく、「メール配信停止用の一意なトークンを生成して、ユーザーオブジェクトの属性に設定するクラス」ではないかと思います。

例えば手元でActiveSupport::Notifications.subscribe('user.create', SignUpNotifier.new)をコメントアウトしても、ユーザー登録時の通知は有効になっているようでした。

実際にユーザー登録時の通知を出しているのはこの辺かなと思います。

確認したいこと1

まず、

SignUpNotifierの通知確認
- トップ画面から参加登録を押下し、ユーザー登録を行う。
- 登録を行ったユーザー以外でログインし、通知が来ていることを確認する。

という確認方法では、前述した通り'user.create'イベントが発行されて、それが適切に購読されているかどうかの判別はつかないので、記載を変更した方が良いのかなと思いました。

私はSignUpNotifierクラスのcallメソッド定義内にRails.logger.info "[Debug] SignUpNotifierが呼ばれました"と書いて確認しました。

確認したいこと2

今回のissueはnewspaperをActiveSupport::Notificationsに置き換えるという目的なので、この実装でも問題はないと思いますが、通知機能を備えていないSignUpNotifierをそのまま残しておいていいのか疑問に思いました。

また、本来ActiveSupport::Notifications.instrument('user.create', user: @user)のようなイベントは@user.saveの後で発行される方が良いのではと思いますが、この実装では@user.saveの前に呼ばれています。
これはuser.unsubscribe_email_token = SecureRandom.urlsafe_base64@user.saveの前に処理したいからだと思いますが、この辺はsub/pub機構の使い方としておかしいのでは?🤔と思いました。

今後の対応としては

  1. このPRでは何もしないが別のissueを立てる。
  2. このPRで修正を加える。
    例えば、SignUpNotifierクラスを削除してcreateアクション内の68行目くらいに
    @user.unsubscribe_email_token = SecureRandom.urlsafe_base64と書いてしまう等
  3. 何もしない

等があると思いますが、対応についてのご意見を賜りたいです🙏

link: "/regular_events/#{@regular_event.id}",
kind: Notification.kinds[:regular_event_updated]
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この空行の削除はリファクタリングと捉えていいですか?
意図しない修正なら戻しておいた方がいいのかなと思ったので一応の確認です🙏

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご指摘ありがとうございます。こちらは私のミスです。
変更前の状態に戻しました。

@thmz337 thmz337 force-pushed the chore/replace-creator-and-notifier branch 2 times, most recently from 61b2f32 to 90f93a6 Compare July 26, 2025 12:25
@thmz337
Copy link
Copy Markdown
Contributor Author

thmz337 commented Jul 26, 2025

@tyrrell-IH

お疲れ様です!ご確認ありがとうございました。

確認したいこと1

おっしゃる通りです。変更確認方法を修正しました。

確認したいこと2

こちらもおっしゃる通りかと思います。今回、2で対応しました。

以上ご確認よろしくお願いいたします。

@tyrrell-IH
Copy link
Copy Markdown
Contributor

@thmz337
7/29(火)までには返します!少々お待ちください🙏

@tyrrell-IH tyrrell-IH self-requested a review July 28, 2025 06:57
@tyrrell-IH
Copy link
Copy Markdown
Contributor

@thmz337
SignUpNotifierの通知確認の方法を変更していただいていますが、こちらの動作確認は必要なものですか?
よろしければ必要な理由を教えていただきたいです🙏

私としては、SignUpNotifierを削除したので動作確認の必要は無いとの認識でした。

@thmz337
Copy link
Copy Markdown
Contributor Author

thmz337 commented Jul 29, 2025

@tyrrell-IH

お疲れ様です。ご確認ありがとうございました。

SignUpNotifierの通知確認の方法を変更していただいていますが、こちらの動作確認は必要なものですか?

こちらについて、動作確認を残した意図としては、トークンの生成と設定をSignUpNotifierからモデルに移したことで、不具合が起きていないかを確認するためになります。個人的には必要であると考えています。
ただ、概要と変更確認方法が実態に沿っていないものになっていたので修正しました。

以上ご確認よろしくお願いいたします。

@tyrrell-IH
Copy link
Copy Markdown
Contributor

tyrrell-IH commented Jul 29, 2025

@thmz337
すいません、理解しました🙏

SignUpNotifierを削除してusers_controllerに直接@user.unsubscribe_email_token = SecureRandom.urlsafe_base64を書いたので、メール配信停止機能がちゃんと動作しているか確認したいということですね👍

動作確認してまたご連絡します〜

@thmz337
Copy link
Copy Markdown
Contributor Author

thmz337 commented Jul 29, 2025

@tyrrell-IH

すいません、モデルではなくてコントローラですね。
お手数おかけしますがよろしくお願いいたします🙇

Copy link
Copy Markdown
Contributor

@tyrrell-IH tyrrell-IH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thmz337

良いと思います、approveします!

@thmz337
Copy link
Copy Markdown
Contributor Author

thmz337 commented Jul 29, 2025

@tyrrell-IH

ありがとうございます!

@komagata

ご確認よろしくお願いいたします。

@thmz337 thmz337 requested a review from komagata July 29, 2025 04:00
@komagata
Copy link
Copy Markdown
Member

@thmz337 conflictの修正をお願いします。

@thmz337 thmz337 force-pushed the chore/replace-creator-and-notifier branch from 90f93a6 to 22715ce Compare July 30, 2025 10:12
@thmz337
Copy link
Copy Markdown
Contributor Author

thmz337 commented Jul 30, 2025

@komagata

修正しましたので、よろしくお願いいたします。

@komagata
Copy link
Copy Markdown
Member

komagata commented Aug 2, 2025

@thmz337 conflictの修正をお願いします。

@thmz337 thmz337 force-pushed the chore/replace-creator-and-notifier branch 2 times, most recently from ec263c8 to 629504f Compare August 4, 2025 13:52
@thmz337
Copy link
Copy Markdown
Contributor Author

thmz337 commented Aug 4, 2025

@komagata

お疲れ様です。conflictを修正しましたので、ご確認よろしくお願いいたします。

@komagata
Copy link
Copy Markdown
Member

komagata commented Aug 4, 2025

@thmz337 テストが失敗しているようです。テストが成功していることを確認してからレビュー依頼するようにお願います〜。

@thmz337
Copy link
Copy Markdown
Contributor Author

thmz337 commented Aug 5, 2025

@komagata

失礼しました。テスト成功後ご連絡させていただきます。

@thmz337 thmz337 force-pushed the chore/replace-creator-and-notifier branch from 629504f to cd6e551 Compare August 12, 2025 00:46
@thmz337
Copy link
Copy Markdown
Contributor Author

thmz337 commented Aug 12, 2025

@komagata

お疲れ様です。こちらご確認をお願いできますでしょうか?

@user.uploaded_avatar = user_params[:avatar]

ActiveSupport::Notifications.instrument('user.create', user: @user)
@user.unsubscribe_email_token = SecureRandom.urlsafe_base64
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この処理は無くなっても大丈夫でしょうか?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@komagata

お疲れ様です。ご確認ありがとうございます。

こちらの処理でSignUpNotifierを呼び出しているのですが、行っている処理はメール配信停止用のトークンを発行して、ユーザーに設定を行うことです。

@tyrrell-IH さんともやり取りをしたのですが、クラス名と異なり通知機能を備えていない(通知は別の箇所で行っています)ため、メール配信停止トークンの設定は別途切り出し、
( @user.unsubscribe_email_token = SecureRandom.urlsafe_base64の箇所です)該当箇所を削除しました。

以上よろしくお願いいたします。

@thmz337 thmz337 force-pushed the chore/replace-creator-and-notifier branch from cd6e551 to fd09bb9 Compare August 21, 2025 13:23
Copy link
Copy Markdown
Member

@komagata komagata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確認させて頂きました。OKです〜🙆‍♂️

@machida
Copy link
Copy Markdown
Member

machida commented Sep 4, 2025

@thmz337

RegularEventUpdateNotifier のステージング確認ができました🎉

image

@thmz337
Copy link
Copy Markdown
Contributor Author

thmz337 commented Sep 4, 2025

@machida

早速のご対応ありがとうございます!
ご迷惑をおかけしまして、申し訳ないです🙇

@machida
Copy link
Copy Markdown
Member

machida commented Sep 4, 2025

@thmz337
Discordの方も確認できました!!

image

@thmz337
Copy link
Copy Markdown
Contributor Author

thmz337 commented Sep 4, 2025

@machida

ありがとうございます!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants