Skip to content

Commit

Permalink
Add tooltip to display why api key is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshenny committed May 6, 2022
1 parent 50aa4be commit 803437f
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 4 deletions.
14 changes: 13 additions & 1 deletion app/helpers/api_keys_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
module ApiKeysHelper
def gem_scope(api_key)
return if api_key.soft_deleted?
return invalid_gem_tooltip if api_key.soft_deleted?

api_key.rubygem ? api_key.rubygem.name : t("api_keys.all_gems")
end

private

def invalid_gem_tooltip
content_tag(
:span,
"[?]",
class: "tooltip__text",
style: "font-size:1em",
data: { tooltip: t("api_keys.gem_ownership_removed") }
)
end
end
1 change: 1 addition & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ de:
all_gems:
invalid_key:
all_gems:
gem_ownership_removed:
clearance_mailer:
change_password:
title:
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ en:
rubygem_scope_info: This scope restricts gem push/yank and owner add/remove commands to a specific gem.
invalid_key: An invalid API key cannot be edited. Please delete it and create a new one.
all_gems: All Gems
gem_ownership_removed: Ownership of the gem has been removed after being scoped to this key.
clearance_mailer:
change_password:
title: CHANGE PASSWORD
Expand Down
1 change: 1 addition & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ es:
rubygem_scope_info:
invalid_key:
all_gems:
gem_ownership_removed:
clearance_mailer:
change_password:
title: CAMBIAR CONTRASEÑA
Expand Down
1 change: 1 addition & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ fr:
rubygem_scope_info:
invalid_key:
all_gems:
gem_ownership_removed:
clearance_mailer:
change_password:
title:
Expand Down
1 change: 1 addition & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ ja:
rubygem_scope_info:
invalid_key:
all_gems:
gem_ownership_removed:
clearance_mailer:
change_password:
title:
Expand Down
1 change: 1 addition & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ nl:
rubygem_scope_info:
invalid_key:
all_gems:
gem_ownership_removed:
clearance_mailer:
change_password:
title:
Expand Down
1 change: 1 addition & 0 deletions config/locales/pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pt-BR:
rubygem_scope_info:
invalid_key:
all_gems:
gem_ownership_removed:
clearance_mailer:
change_password:
title:
Expand Down
1 change: 1 addition & 0 deletions config/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ zh-CN:
rubygem_scope_info:
invalid_key:
all_gems:
gem_ownership_removed:
clearance_mailer:
change_password:
title:
Expand Down
1 change: 1 addition & 0 deletions config/locales/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ zh-TW:
rubygem_scope_info:
invalid_key:
all_gems:
gem_ownership_removed:
clearance_mailer:
change_password:
title:
Expand Down
2 changes: 1 addition & 1 deletion test/integration/api_keys_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class ApiKeysTest < SystemTest
assert_predicate api_key.reload, :soft_deleted?

refute page.has_button? "Edit"
assert_nil page.find('.owners__cell[data-title="Gem"]').text
assert_equal "[?]", page.find('.owners__cell[data-title="Gem"]').text
visit_edit_profile_api_key_path(api_key)
assert page.has_content? "An invalid API key cannot be edited. Please delete it and create a new one."
assert_equal profile_api_keys_path, page.current_path
Expand Down
12 changes: 10 additions & 2 deletions test/unit/helpers/api_keys_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ class ApiKeysHelperTest < ActionView::TestCase
assert_equal "All Gems", gem_scope(create(:api_key))
end

should "return if key if gem ownership is removed" do
should "return error tooltip if key if gem ownership is removed" do
@ownership = create(:ownership)
@api_key = create(:api_key, push_rubygem: true, user: @ownership.user, ownership: @ownership)
@ownership.destroy!

assert_nil gem_scope(@api_key.reload)
expected_dom = <<~HTML.squish.gsub(/>\s+</, "><")
<span#{' '}
class="tooltip__text"#{' '}
style="font-size:1em"
data-tooltip="Ownership of the gem has been removed after being scoped to this key."\
>[?]</span>
HTML

assert_equal expected_dom, gem_scope(@api_key.reload)
end
end
end

0 comments on commit 803437f

Please sign in to comment.