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

Show owner list with full names, add an asterisk for mfa disable when you are owner #4905

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/stylesheets/tailwind.deprecated.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions app/helpers/rubygems_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ def links_to_owners_without_mfa(rubygem)
rubygem.owners.without_mfa.sort_by(&:id).inject("") { |link, owner| link << link_to_user(owner) }.html_safe
end

def link_to_owner(owner, show_mfa_status: false)
link_text = avatar(32, "gravatar-#{owner.id}", owner, class: "tw-rounded-full tw-mr-1")
link_text << " #{owner.display_handle}"
link_text << " *" if show_mfa_status && owner.mfa_disabled?
link_to(link_text.html_safe, profile_path(owner.display_id), class: "t-link tw-flex tw-items-center")
end

def link_to_user(user)
link_to avatar(48, "gravatar-#{user.id}", user), profile_path(user.display_id),
alt: user.display_handle, title: user.display_handle
Expand Down
10 changes: 0 additions & 10 deletions app/javascript/src/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,3 @@ $(function() {
$(this).animate({ width: $(this).data("bar-width") + '%' }, 700).removeClass('t-item--hidden').css("display", "block");
});
});

//gem page
$(function() {
$('.gem__users__mfa-text.mfa-warn').on('click', function() {
$('.gem__users__mfa-text.mfa-warn').toggleClass('t-item--hidden');

$owners = $('.gem__users__mfa-disabled');
$owners.toggleClass('t-item--hidden');
});
});
4 changes: 4 additions & 0 deletions app/policies/rubygem_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ def show_events?
def show_unconfirmed_ownerships?
rubygem_owned_by?(user)
end

def show_owner_mfa_status?
rubygem_owned_by?(user)
end
end
31 changes: 12 additions & 19 deletions app/views/rubygems/_gem_members.html.erb
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
<div class="gem__members">
<% if rubygem.owners.present? %>
<% show_mfa_status = policy(rubygem).show_owner_mfa_status? %>

<h3 class="t-list__heading"><%= t '.owners_header' %>:</h3>
<div class="gem__users">
<%= links_to_owners(rubygem) %>
</div>
<ul class="tw-my-3">
<% rubygem.owners.sort_by(&:id).each do |owner| %>
martinemde marked this conversation as resolved.
Show resolved Hide resolved
<li><%= link_to_owner(owner, show_mfa_status:) %></li>
<% end %>
</ul>

<% if rubygem.owned_by?(current_user) %>
<% if show_mfa_status %>
<% if rubygem.owners.without_mfa.present? %>
<% if current_user.mfa_disabled? %>
<span class="gem__users__mfa-text mfa-warn">
<%= t '.self_no_mfa_warning_html' %>
</span>
<% else %>
<span class="gem__users__mfa-text mfa-warn"><%= t '.not_using_mfa_warning_show' %></span>
<% end %>

<div class="gem__users__mfa-disabled t-item--hidden">
<span class="gem__users__mfa-text mfa-warn t-item--hidden"><%= t '.not_using_mfa_warning_hide' %></span>
<div class="gem__users">
<%= links_to_owners_without_mfa(rubygem) %>
</div>
</div>
<span class="tw-my-2 gem__users__mfa-text mfa-warn">
<%= current_user.mfa_disabled? ? t(".self_no_mfa_warning_html") : t(".not_using_mfa_warning") %>
</span>
<% else %>
<span class="gem__users__mfa-text mfa-info"><%= t '.using_mfa_info' %></span>
<span class="gem__users__mfa-text mfa-info"><%= t '.using_mfa_info' %></span>
<% end %>
<% end %>
<% end %>
Expand Down
3 changes: 1 addition & 2 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,7 @@ de:
gem_members:
authors_header: Autoren
self_no_mfa_warning_html:
not_using_mfa_warning_show:
not_using_mfa_warning_hide:
not_using_mfa_warning:
owners_header: Besitzer
pushed_by:
using_mfa_info:
Expand Down
5 changes: 2 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,10 @@ en:
gem_members:
authors_header: Authors
self_no_mfa_warning_html: Please consider <a href="/settings/edit">enabling multi-factor authentication (MFA)</a> to keep your account secure.
not_using_mfa_warning_show: "* Some owners are not using multi-factor authentication (MFA). Click for the complete list."
not_using_mfa_warning_hide: "* The following owners are not using multi-factor authentication (MFA). Click to hide."
not_using_mfa_warning: "* Some owners are not using multi-factor authentication (MFA)."
owners_header: Owners
pushed_by: Pushed by
using_mfa_info: "* All owners are using multi-factor authentication (MFA)."
using_mfa_info: "All owners are using multi-factor authentication (MFA)."
yanked_by: Yanked by
sha_256_checksum: SHA 256 checksum
signature_period: Signature validity period
Expand Down
5 changes: 1 addition & 4 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,7 @@ es:
authors_header: Autores
self_no_mfa_warning_html: Considera por favor <a href="/settings/edit">activar
la autenticación de múltiples factores (AMF)</a> para mantener tu cuenta segura.
not_using_mfa_warning_show: "* Algunos propietarios no están usando AMF. Haga
click para ver la lista completa."
not_using_mfa_warning_hide: "* Los siguientes propietarios no están usando AMF.
Haga click para ocultar."
not_using_mfa_warning: "* Algunos propietarios no están usando AMF."
owners_header: Propietarios
pushed_by: Subida por
using_mfa_info: "* Todos los propietarios están usando AMF."
Expand Down
3 changes: 1 addition & 2 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,7 @@ fr:
gem_members:
authors_header: Auteurs
self_no_mfa_warning_html:
not_using_mfa_warning_show:
not_using_mfa_warning_hide:
not_using_mfa_warning:
owners_header: Propriétaires
pushed_by:
using_mfa_info:
Expand Down
3 changes: 1 addition & 2 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,7 @@ ja:
authors_header: 作者
self_no_mfa_warning_html: アカウントをセキュアに保つため、<a href="/settings/edit">多要素認証 (MFA)
の有効化</a>をご検討ください。
not_using_mfa_warning_show: 多要素認証 (MFA) を使っていない所有者がいます。完全な一覧を見るにはクリックしてください。
not_using_mfa_warning_hide: "* 以下の所有者は多要素認証 (MFA) を使っていません。クリックして隠します。"
not_using_mfa_warning: 多要素認証 (MFA) を使っていない所有者がいます。
owners_header: 所有者
pushed_by: プッシュ者
using_mfa_info: "* 全ての所有者が多要素認証 (MFA) を使っています。"
Expand Down
3 changes: 1 addition & 2 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,7 @@ nl:
gem_members:
authors_header:
self_no_mfa_warning_html:
not_using_mfa_warning_show:
not_using_mfa_warning_hide:
not_using_mfa_warning:
owners_header: Eigenaren
pushed_by:
using_mfa_info:
Expand Down
5 changes: 1 addition & 4 deletions config/locales/pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,7 @@ pt-BR:
gem_members:
authors_header: Autores
self_no_mfa_warning_html:
not_using_mfa_warning_show: "* Alguns donos não estão usando MFA. Clique para
a lista completa."
not_using_mfa_warning_hide: "* Os seguintes donos não estão usando MFA. Clique
para esconder."
not_using_mfa_warning: "* Alguns donos não estão usando MFA."
owners_header: Donos
pushed_by:
using_mfa_info: "* Todos os donos estão usando MFA."
Expand Down
3 changes: 1 addition & 2 deletions config/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,7 @@ zh-CN:
gem_members:
authors_header: 作者
self_no_mfa_warning_html: 请考虑 <a href="/settings/edit">启用多因素身份验证(MFA)</a> 来保障您的帐户安全。
not_using_mfa_warning_show: "* 一些业主当前还没有使用多因素验证(MFA)。请点击查看完整列表。"
not_using_mfa_warning_hide: "* 以下业主还未使用多因素验证(MFA)。点击隐藏。"
not_using_mfa_warning: "* 一些业主当前还没有使用多因素验证(MFA)。"
owners_header: 业主
pushed_by: 推送
using_mfa_info: "* 所有业主都已使用多因素验证(MFA)。"
Expand Down
3 changes: 1 addition & 2 deletions config/locales/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,7 @@ zh-TW:
gem_members:
authors_header: 作者
self_no_mfa_warning_html:
not_using_mfa_warning_show: "* 某些擁有者未使用多重要素驗證 (MFA)。點擊此處以顯示完整名單。"
not_using_mfa_warning_hide: "* 下列擁有者未使用多重要素驗證 (MFA)。點擊此處以隱藏。"
not_using_mfa_warning: "* 某些擁有者未使用多重要素驗證 (MFA)。"
owners_header: 擁有者
pushed_by: 推送者
using_mfa_info: "* 擁有者皆使用多重要素驗證 (MFA)。"
Expand Down
12 changes: 6 additions & 6 deletions test/integration/api/v1/owner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class Api::V1::OwnerTest < ActionDispatch::IntegrationTest

get rubygem_path(@rubygem.slug)

assert page.has_selector?("a[alt='#{@user.handle}']")
assert page.has_selector?("a[alt='#{@other_user.handle}']")
page.assert_selector("div.gem__members a", text: @user.handle)
page.assert_selector("div.gem__members a", text: @other_user.handle)
end

test "removing an owner" do
Expand All @@ -41,8 +41,8 @@ class Api::V1::OwnerTest < ActionDispatch::IntegrationTest

get rubygem_path(@rubygem.slug)

assert page.has_selector?("a[alt='#{@user.handle}']")
refute page.has_selector?("a[alt='#{@other_user.handle}']")
page.assert_selector("div.gem__members a", text: @user.handle)
page.assert_no_selector("div.gem__members a", text: @other_user.handle)
end

test "transferring ownership" do
Expand All @@ -54,8 +54,8 @@ class Api::V1::OwnerTest < ActionDispatch::IntegrationTest

get rubygem_path(@rubygem.slug)

refute page.has_selector?("a[alt='#{@user.handle}']")
assert page.has_selector?("a[alt='#{@other_user.handle}']")
page.assert_no_selector("div.gem__members a", text: @user.handle)
page.assert_selector("div.gem__members a", text: @other_user.handle)
end

test "adding ownership without permission" do
Expand Down
2 changes: 0 additions & 2 deletions test/integration/gems_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class GemsSystemTest < SystemTest

visit rubygem_path(@rubygem.slug, as: @user.id)

assert page.has_selector?(".gem__users__mfa-disabled .gem__users a")
assert page.has_content? "Please consider enabling multi-factor"
end

Expand All @@ -127,7 +126,6 @@ class GemsSystemTest < SystemTest

visit rubygem_path(@rubygem.slug, as: @user.id)

assert page.has_selector?(".gem__users__mfa-disabled .gem__users a")
assert page.has_selector?(".gem__users__mfa-text.mfa-warn")
end

Expand Down
4 changes: 1 addition & 3 deletions test/integration/push_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class PushTest < ActionDispatch::IntegrationTest
assert page.has_content?("1.0.0")
assert page.has_content?("Pushed by")

css = %(div.gem__users a[alt=#{@user.handle}])

assert page.has_css?(css, count: 2)
assert_selector("div.gem__members a", text: @user.handle)

assert_equal Digest::MD5.hexdigest(<<~INFO), Rubygem.find_by!(name: "sandworm").versions.sole.info_checksum
---
Expand Down
4 changes: 1 addition & 3 deletions test/integration/yank_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ class YankTest < SystemTest

assert page.has_content?("Yanked by")

css = %(div.gem__users a[alt=#{@user.handle}])

assert page.has_css?(css, count: 3)
assert_selector("div.gem__members a", text: @user.handle)

assert_event Events::RubygemEvent::VERSION_YANKED, {
number: "2.2.2",
Expand Down
8 changes: 8 additions & 0 deletions test/policies/rubygem_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,12 @@ def policy!(user)
refute_authorized nil, :show_unconfirmed_ownerships?
end
end

context "#show_owner_mfa_status?" do
should "only allow the owner" do
assert_authorized @owner, :show_owner_mfa_status?
refute_authorized @user, :show_owner_mfa_status?
refute_authorized nil, :show_owner_mfa_status?
end
end
end
Loading