-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
退会時に分報チャンネルを自動で削除する #6626
Merged
Merged
退会時に分報チャンネルを自動で削除する #6626
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
11f9ad1
休会三ヶ月で自動退会しないフラグを追加
ogawa-tomo 08670ab
休会三ヶ月で自動退会しないフラグを管理者ページから操作できるようにする
ogawa-tomo 9f9b998
休会三ヶ月で自動退会のテスト
ogawa-tomo 5a3598e
休会三ヶ月で退会しないフラグの名前を変更
ogawa-tomo e06002c
余分な差分をもとに戻す
ogawa-tomo 5208192
退会時に分報チャンネルを自動で削除する
ogawa-tomo 21c373d
server testの追加
ogawa-tomo 943d81a
times_channel_destroyer_testを追加
ogawa-tomo 5cd4b43
system testを追加
ogawa-tomo 3268bc1
不要なマイグレーションファイルを削除
ogawa-tomo f9b34fc
不要なファイルを削除
ogawa-tomo a74e406
discord_profileのデータ形式に対応
ogawa-tomo 1bcded6
管理者が退会させるときも分報が削除されるように修正
ogawa-tomo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class TimesChannelDestroyer | ||
def call(user) | ||
return unless user.discord_profile.times_id | ||
|
||
if Discord::Server.delete_text_channel(user.discord_profile.times_id) | ||
user.discord_profile.update!(times_id: nil) | ||
else | ||
Rails.logger.warn "[Discord API] #{user.login_name}の分報チャンネルが削除できませんでした。" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
test/cassettes/discord/server/delete_text_channel_with_unauthorized.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
test/cassettes/discord/server/delete_text_channel_with_unknown_channel_id.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class TimesChannelCreatorTest < ActiveSupport::TestCase | ||
test '#call' do | ||
logs = [] | ||
user = users(:hajime) | ||
user.discord_profile.update!(times_id: '987654321987654321') | ||
Rails.logger.stub(:warn, ->(message) { logs << message }) do | ||
Discord::Server.stub(:delete_text_channel, true) do | ||
TimesChannelDestroyer.new.call(user) | ||
end | ||
assert_nil user.discord_profile.times_id | ||
assert_nil logs.last | ||
end | ||
end | ||
|
||
test '#call with failure' do | ||
logs = [] | ||
user = users(:hajime) | ||
user.discord_profile.update!(times_id: '987654321987654321') | ||
Rails.logger.stub(:warn, ->(message) { logs << message }) do | ||
Discord::Server.stub(:delete_text_channel, nil) do | ||
TimesChannelDestroyer.new.call(user) | ||
end | ||
assert_equal '987654321987654321', user.discord_profile.times_id | ||
assert_equal "[Discord API] #{user.login_name}の分報チャンネルが削除できませんでした。", logs.last | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
今回、チャンネル削除処理をNewspaper経由で呼ぶことにしましたが、その際に一緒に呼ばれるのがこのクラスです。ユーザーの未確認提出物の削除・WIP日報の削除・就職活動フラグOFFの操作をしています。
この箇所では「ユーザーの退会フラグに変更があったか」を判断しそのときのみ処理を実行するようになっていますが、その判断は呼び出し側で行うべき(このクラスの責務ではない)と考え、処理を移しています。
この処理を呼んでいるのは以下の3箇所であり、いずれも退会処理を行うときに呼んでいます。(ユーザーが自ら退会するとき、管理画面から退会させるとき、休会六ヶ月で自動退会するとき)
bootcamp/app/controllers/retirement_controller.rb
Line 15 in 1bcded6
bootcamp/app/controllers/admin/users_controller.rb
Line 25 in 1bcded6
bootcamp/app/controllers/scheduler/daily/auto_retire_controller.rb
Line 18 in 1bcded6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ご説明ありがとうございます〜
そうですね、確かにUnfinishedDataDestroyerではなく呼び出し側でフラグOFFの操作を行った方が良いと思います。