Skip to content

Commit

Permalink
Merge pull request #7819 from fjordllc/feature/administrator-release-…
Browse files Browse the repository at this point in the history
…users-github

管理者は自分以外のユーザーのGitHubアカウント連携を解除できるように修正
  • Loading branch information
komagata authored Jul 2, 2024
2 parents fe3b0c8 + 8fd7037 commit 2f8b194
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
9 changes: 7 additions & 2 deletions app/controllers/connection/git_hub_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ class Connection::GitHubController < ApplicationController
skip_before_action :require_active_user_login, raise: false

def destroy
current_user.update(github_id: nil)
redirect_to root_path, notice: 'GitHubとの連携を解除しました。'
user = User.find(params[:user_id])
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
end
end
2 changes: 1 addition & 1 deletion app/views/users/form/_sns.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
.a-form-help
p
| GitHub アカウントは登録されています。(
= link_to connection_git_hub_path, method: :delete, class: 'a-form-help-link is-muted-text' do
= link_to connection_git_hub_path(user_id: @user.id), method: :delete, class: 'a-form-help-link is-muted-text' do
| GitHub アカウントの登録を解除する
| )
- else
Expand Down
2 changes: 2 additions & 0 deletions db/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ komagata:
twitter_account: komagata
facebook_url: https://www.facebook.com/fjordllc/komagata1111
github_account: komagata
github_id: github-komagata
blog_url: http://komagata.org
company: company1
description: "平日10〜19時勤務です。"
Expand Down Expand Up @@ -210,6 +211,7 @@ hatsuno:
name_kana: ハツノ シンジ
twitter_account: hatsuno
facebook_url: https://www.facebook.com/fjordllc/hatsuno
github_id: github-hatsuno
blog_url: http://hatsuno.org
description: "初野です。課金しています。"
customer_id: "cus_12345678"
Expand Down
20 changes: 20 additions & 0 deletions test/system/authentication/github_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,24 @@ class Authentication::GithubSystemTest < ApplicationSystemTestCase
visit '/current_user/edit'
assert_link 'GitHub アカウントを登録する'
end

test 'release other user GitHub account' do
admin_user = users(:komagata)
admin_user.update!(github_id: '12345')

released_user = users(:hatsuno)
released_user.update!(github_id: '67890')

visit_with_auth "/admin/users/#{released_user.id}/edit", 'komagata'
assert_text 'GitHub アカウントは登録されています。'

click_link 'GitHub アカウントの登録を解除する'
assert_text 'GitHubとの連携を解除しました。'

visit_with_auth "/admin/users/#{released_user.id}/edit", 'komagata'
assert_link 'GitHub アカウントを登録する'

visit '/current_user/edit'
assert_text 'GitHub アカウントは登録されています。'
end
end

0 comments on commit 2f8b194

Please sign in to comment.