From 50aa4bef2b7da36636e379a1310e24a941960b07 Mon Sep 17 00:00:00 2001 From: Jenny Shen Date: Fri, 6 May 2022 12:30:59 +0300 Subject: [PATCH] Display all gems if no gem scope specified on index --- app/helpers/api_keys_helper.rb | 7 +++++++ app/views/api_keys/index.html.erb | 2 +- config/locales/de.yml | 1 + config/locales/en.yml | 3 +-- config/locales/es.yml | 3 +-- config/locales/fr.yml | 3 +-- config/locales/ja.yml | 3 +-- config/locales/nl.yml | 3 +-- config/locales/pt-BR.yml | 3 +-- config/locales/zh-CN.yml | 3 +-- config/locales/zh-TW.yml | 3 +-- test/integration/api_keys_test.rb | 3 +++ test/unit/helpers/api_keys_helper_test.rb | 24 +++++++++++++++++++++++ 13 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 app/helpers/api_keys_helper.rb create mode 100644 test/unit/helpers/api_keys_helper_test.rb diff --git a/app/helpers/api_keys_helper.rb b/app/helpers/api_keys_helper.rb new file mode 100644 index 00000000000..05e4ad2b41b --- /dev/null +++ b/app/helpers/api_keys_helper.rb @@ -0,0 +1,7 @@ +module ApiKeysHelper + def gem_scope(api_key) + return if api_key.soft_deleted? + + api_key.rubygem ? api_key.rubygem.name : t("api_keys.all_gems") + end +end diff --git a/app/views/api_keys/index.html.erb b/app/views/api_keys/index.html.erb index 35a3988b164..e64fea53d2b 100644 --- a/app/views/api_keys/index.html.erb +++ b/app/views/api_keys/index.html.erb @@ -49,7 +49,7 @@ <% end %> - <%= api_key.rubygem&.name %> + <%= gem_scope(api_key) %> <%= time_ago_in_words(api_key.created_at) %> diff --git a/config/locales/de.yml b/config/locales/de.yml index fbbb730a06b..88ee22cc1f0 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -102,6 +102,7 @@ de: rubygem_scope_info: all_gems: invalid_key: + all_gems: clearance_mailer: change_password: title: diff --git a/config/locales/en.yml b/config/locales/en.yml index 71abf98fa36..f2f3d32a7b5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -94,7 +94,6 @@ en: enable_mfa: Enable MFA rubygem_scope: Gem Scope rubygem_scope_info: This scope restricts gem push/yank and owner add/remove commands to a specific gem. - all_gems: All Gems reset: success: "Deleted all API keys" update: @@ -106,8 +105,8 @@ en: enable_mfa: Enable MFA rubygem_scope: Gem Scope rubygem_scope_info: This scope restricts gem push/yank and owner add/remove commands to a specific gem. - all_gems: All Gems invalid_key: An invalid API key cannot be edited. Please delete it and create a new one. + all_gems: All Gems clearance_mailer: change_password: title: CHANGE PASSWORD diff --git a/config/locales/es.yml b/config/locales/es.yml index 0c17a6e5a0a..8b9eab0f2b7 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -99,7 +99,6 @@ es: enable_mfa: rubygem_scope: rubygem_scope_info: - all_gems: reset: success: update: @@ -111,8 +110,8 @@ es: enable_mfa: rubygem_scope: rubygem_scope_info: - all_gems: invalid_key: + all_gems: clearance_mailer: change_password: title: CAMBIAR CONTRASEÑA diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 72d977bc59d..b109e41ec36 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -90,7 +90,6 @@ fr: enable_mfa: rubygem_scope: rubygem_scope_info: - all_gems: reset: success: update: @@ -102,8 +101,8 @@ fr: enable_mfa: rubygem_scope: rubygem_scope_info: - all_gems: invalid_key: + all_gems: clearance_mailer: change_password: title: diff --git a/config/locales/ja.yml b/config/locales/ja.yml index daa234c5a0b..bd028cf63be 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -92,7 +92,6 @@ ja: enable_mfa: rubygem_scope: rubygem_scope_info: - all_gems: reset: success: update: @@ -104,8 +103,8 @@ ja: enable_mfa: rubygem_scope: rubygem_scope_info: - all_gems: invalid_key: + all_gems: clearance_mailer: change_password: title: diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 721355dd806..74f60190edc 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -91,7 +91,6 @@ nl: enable_mfa: rubygem_scope: rubygem_scope_info: - all_gems: reset: success: update: @@ -103,8 +102,8 @@ nl: enable_mfa: rubygem_scope: rubygem_scope_info: - all_gems: invalid_key: + all_gems: clearance_mailer: change_password: title: diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 7bc54441a83..dfe51067c14 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -98,7 +98,6 @@ pt-BR: enable_mfa: rubygem_scope: rubygem_scope_info: - all_gems: reset: success: update: @@ -110,8 +109,8 @@ pt-BR: enable_mfa: rubygem_scope: rubygem_scope_info: - all_gems: invalid_key: + all_gems: clearance_mailer: change_password: title: diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index 4a3d2750f96..ce40d4ff8fc 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -88,7 +88,6 @@ zh-CN: enable_mfa: rubygem_scope: rubygem_scope_info: - all_gems: reset: success: update: @@ -100,8 +99,8 @@ zh-CN: enable_mfa: rubygem_scope: rubygem_scope_info: - all_gems: invalid_key: + all_gems: clearance_mailer: change_password: title: diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index f55d42f317f..743abc4609e 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -88,7 +88,6 @@ zh-TW: enable_mfa: rubygem_scope: rubygem_scope_info: - all_gems: reset: success: update: @@ -100,8 +99,8 @@ zh-TW: enable_mfa: rubygem_scope: rubygem_scope_info: - all_gems: invalid_key: + all_gems: clearance_mailer: change_password: title: diff --git a/test/integration/api_keys_test.rb b/test/integration/api_keys_test.rb index 488125c34a7..4a8d9779d66 100644 --- a/test/integration/api_keys_test.rb +++ b/test/integration/api_keys_test.rb @@ -36,6 +36,7 @@ class ApiKeysTest < SystemTest click_button "Create" assert page.has_content? "Note that we won't be able to show the key to you again. New API key:" + assert_equal @ownership.rubygem.name, page.find('.owners__cell[data-title="Gem"]').text assert_equal @ownership.rubygem, @user.api_keys.last.rubygem end @@ -130,6 +131,7 @@ class ApiKeysTest < SystemTest page.select "All Gems" click_button "Update" + assert_equal "All Gems", page.find('.owners__cell[data-title="Gem"]').text assert_nil api_key.reload.rubygem end @@ -250,6 +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 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 diff --git a/test/unit/helpers/api_keys_helper_test.rb b/test/unit/helpers/api_keys_helper_test.rb new file mode 100644 index 00000000000..7f59369d89a --- /dev/null +++ b/test/unit/helpers/api_keys_helper_test.rb @@ -0,0 +1,24 @@ +require "test_helper" + +class ApiKeysHelperTest < ActionView::TestCase + context "gem_scope" do + should "return gem name" do + @ownership = create(:ownership) + @api_key = create(:api_key, push_rubygem: true, user: @ownership.user, ownership: @ownership) + + assert_equal @ownership.rubygem.name, gem_scope(@api_key) + end + + should "return all gems if there is no scope specified" do + assert_equal "All Gems", gem_scope(create(:api_key)) + end + + should "return 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) + end + end +end