Skip to content

Commit

Permalink
Expand owner list, show mfa status as an asterisk
Browse files Browse the repository at this point in the history
  • Loading branch information
martinemde committed Jul 19, 2024
1 parent 0758160 commit 1407f6d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
13 changes: 13 additions & 0 deletions app/helpers/rubygems_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ 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),
alt: owner.display_handle,
title: owner.display_handle,
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 @@ -67,13 +67,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 @@ -57,4 +57,8 @@ def add_owner?
def remove_owner?
rubygem_owned_by?(user)
end

def show_owner_mfa_status?
rubygem_owned_by?(user)
end
end
32 changes: 13 additions & 19 deletions app/views/rubygems/_gem_members.html.erb
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
<div class="gem__members">
<% if rubygem.owners.present? %>
<h3 class="t-list__heading"><%= t '.owners_header' %>:</h3>
<div class="gem__users">
<%= links_to_owners(rubygem) %>
</div>
<ul class="tw-my-3">
<% show_mfa_status = policy(rubygem).show_owner_mfa_status? %>
<% rubygem.owners.sort_by(&:id).each do |owner| %>
<li>
<%= link_to_owner(owner, show_mfa_status:) %>
</li>
<% end %>
</ul>

<% if rubygem.owned_by?(current_user) %>
<% if rubygem.owned_by?(current_user) %>
<% 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_show") %>
</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

0 comments on commit 1407f6d

Please sign in to comment.