Skip to content
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

管理者は自分以外のユーザーのGitHubアカウント連携を解除できるように修正 #7819

Merged
merged 6 commits into from
Jul 2, 2024

Conversation

Shrimprin
Copy link
Contributor

@Shrimprin Shrimprin commented May 31, 2024

Issue

概要

管理者は自分以外のユーザーのGitHubアカウントの連携を解除できるようにしました。

変更確認方法

  1. feature/administrator-release-users-githubをローカルに取り込む
  2. bin/setupを実行
  3. foreman start -f Procfile.devでローカルサーバを立ち上げ
  4. github-admintaroでログイン
  5. hatsunoの編集ページへと進む
  6. GItHubアカウントの登録を解除するをクリックし、下記を確認する
    • hatsunoのプロフィールページにリダイレクトし、GitHubとの連携を解除しました。というメッセージが表示される
    • hatsunoの編集画面で、GitHubアカウントの登録が解除されている
    • ログインユーザーの編集画面で、GitHubアカウントの登録が解除されていない

Screenshot

変更前

  1. 対象のユーザーのGItHub連携を解除
edit
  1. root_path(ダッシュボード)にリダイレクト
before_redirect
  1. (ログインユーザーの編集画面)ログインユーザーのGitHub連携が解除されている
before_admin_profile
  1. (対象ユーザーの編集画面)対象のユーザーのGitHub連携は変化なし
before_ippan_profile

変更後

  1. 対象のユーザーのGItHub連携を解除
edit
  1. 対象のユーザーのプロフィールページにリダイレクト
after_redirect
  1. (ログインユーザーの編集画面)ログインユーザーのGitHub連携は変化なし
after_admin_profile
  1. (対象ユーザーの編集画面)対象のユーザーのGitHub連携が解除されている
after_ippan_profile

@Shrimprin Shrimprin requested a review from hirano-vm4 June 1, 2024 00:24
@Shrimprin
Copy link
Contributor Author

@hirano-vm4
お疲れ様です!
もし可能であればレビューをお願いできますでしょうか?
急ぎではありませんのでお時間あるときにご対応いただければ大丈夫です!
よろしくお願いいたします 🙏

@Shrimprin Shrimprin changed the title Feature/administrator release users GitHub 管理者は自分以外のユーザーのGitHubアカウント連携を解除できるように修正 Jun 1, 2024
@Shrimprin Shrimprin marked this pull request as ready for review June 1, 2024 07:12
@hirano-vm4
Copy link
Contributor

@Shrimprin

お疲れ様です!レビュー承知しました。少しお時間いただければと思います。来週中に確認してコメントいれますね🙌

@Shrimprin
Copy link
Contributor Author

@hirano-vm4
ありがとうございます!よろしくおねがいします〜 🙏

@Shrimprin Shrimprin self-assigned this Jun 10, 2024
Copy link
Contributor

@hirano-vm4 hirano-vm4 left a comment

Choose a reason for hiding this comment

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

@Shrimprin

すいません!バタバタしており、大変遅くなりました🙏

実際の挙動・テスト・コードそれぞれ確認させてもらいLGTMだと思いました〜!

1点だけ概要の部分だけ以下コメントさせてもらいました🙌軽微で、かつ個人的な感想の部分なのでApproveもしております😄

変更確認方法について

丁寧に書かれていてわかりやすかったです!

5番のリンク先からは編集画面にすぐに移動できなかったので、直接http://localhost:3000/admin/users/169446854/edit を記載したらもっとスムーズかな?と感じました〜

  1. github-ippankoの編集ページへと進む

@Shrimprin
Copy link
Contributor Author

@hirano-vm4
お忙しい中ご対応いただきありがとうございます!

変更確認方法についても大変参考になりました!
seedで作成されるデータはbin/setup実行のたびにIDが変わると思っていたのですが、rails db:resetしたうえで、かつseedが変更なければIDは変わらないのですね💡
ご提案いただいた案で修正いたしました~

@Shrimprin Shrimprin requested a review from komagata June 12, 2024 12:44
@Shrimprin
Copy link
Contributor Author

@komagata
メンバーからapproveいただきましたのでレビューをお願いできますでしょうか 🙏
よろしくお願いいたします!

Comment on lines 8 to 14
if !admin_login? && user != current_user
redirect_to root_path, alert: '管理者としてログインしてください'
return
end

user.update(github_id: nil)
redirect_to user_path(user), notice: 'GitHubとの連携を解除しました。'
Copy link
Member

Choose a reason for hiding this comment

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

ガード節以外ではreturnを使わず下記のような感じの方が読みやすいのではないかと思いました。

Suggested change
if !admin_login? && user != current_user
redirect_to root_path, alert: '管理者としてログインしてください'
return
end
user.update(github_id: nil)
redirect_to user_path(user), notice: 'GitHubとの連携を解除しました。'
if !admin_login? && user != current_user
redirect_to root_path, alert: '管理者としてログインしてください'
else
user.update(github_id: nil)
redirect_to user_path(user), notice: 'GitHubとの連携を解除しました。'
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

コメントありがとうございます。
ご提案いただいたコードの方が読みやすいと感じましたので修正しました。

@@ -33,4 +33,24 @@ class Authentication::GithubSystemTest < ApplicationSystemTestCase
visit '/current_user/edit'
assert_link 'GitHub アカウントを登録する'
end

test 'release other user GitHub account' do
Copy link
Member

Choose a reason for hiding this comment

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

fixtureは全てのtest caseでinsertされるので一つのtest caseでだけ必要な場合はこの行あたりでデータを作るとsystem test全体が遅くならないのでよいかもです。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

machidaさんと相談させていただき、実機ブラウザでの確認用も兼ねてfixtureで作成しました。
どのように対応すべきかご助言いただけますでしょうか。

  • 今回作成したfixtureは現状のまま
  • 今回作成したfixtureを削除し、確認用のデータは rails cなどで手動で作成する
  • 今回作成したfixtureを削除し、適当な既存のfixtureのgithub_idに値を設定して、そのfuxtureを実機確認用に使う

Copy link
Member

Choose a reason for hiding this comment

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

@Shrimprin

今回作成したfixtureを削除し、適当な既存のfixtureのgithub_idに値を設定して、そのfuxtureを実機確認用に使う

でおねがいします~

@Shrimprin Shrimprin force-pushed the feature/administrator-release-users-github branch from a0b48c2 to 6cc8fa2 Compare June 26, 2024 00:19
@Shrimprin
Copy link
Contributor Author

@komagata
レビューいただきありがとうございます!
fixtureの件について質問をさせていただきました。
よろしくお願いいたします 🙏

@komagata
Copy link
Member

@Shrimprin マージコミットがたくさん入っているようなので修正してみてください~

@Shrimprin Shrimprin force-pushed the feature/administrator-release-users-github branch from 6cc8fa2 to 8fd7037 Compare June 30, 2024 13:37
@Shrimprin
Copy link
Contributor Author

@komagata
マージコミットとfixtureの修正を行いました。
再度ご確認をお願いいたします 🙏

Copy link
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です~👌

@komagata komagata merged commit 2f8b194 into main Jul 2, 2024
2 checks passed
@komagata komagata deleted the feature/administrator-release-users-github branch July 2, 2024 22:10
@github-actions github-actions bot mentioned this pull request Jul 2, 2024
6 tasks
@Shrimprin
Copy link
Contributor Author

@komagata
ありがとうございます!

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.

3 participants