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

AO3-931 Show placeholder for deleted invitee #5000

Open
wants to merge 2 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
16 changes: 9 additions & 7 deletions app/helpers/invitations_helper.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
module InvitationsHelper

def creator_link(invitation)
if invitation.creator.is_a?(User)
case invitation.creator
when User
link_to(invitation.creator.login, invitation.creator)
elsif invitation.creator.is_a?(Admin)
when Admin
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wandering out of scope here, but while I was updating AO3-6095, I noticed it specifies using Deleted admin when the admin is deleted. We don't cover that case here, so is it possible this page would either 500 or incorrectly specify the queue if the admin who issued an invitation was now deleted?

invitation.creator.login
else
"queue"
t("invitations.invitation.queue")
end
end

def invitee_link(invitation)
if invitation.invitee && invitation.invitee.is_a?(User)
link_to(invitation.invitee.login, invitation.invitee)
end
return unless invitation.invitee_type == "User"
return link_to(invitation.invitee.login, invitation.invitee) if invitation.invitee.present?
return t("invitations.invitation.deleted_user_with_id", user_id: invitation.invitee_id) if User.current_user.is_a?(Admin)

t("invitations.invitation.deleted_user")
end
end
40 changes: 22 additions & 18 deletions app/views/invitations/_invitation.html.erb
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
<dl>
<dt>Sender</dt>
<dd><%= creator_link(invitation) %></dd>
<dt>Invitation token</dt>
<dd><%= invitation.token %></dd>
<dt>Copy link</dt>
<dd><% unless invitation.redeemed_at %><%= link_to "copy and use", signup_path(:invitation_token => invitation.token) %><% end %></dd>
<dt>Sent to</dt>
<dt><%= t(".sender") %></dt>
<dd><%= creator_link(invitation) %></dd>
<dt><%= t(".invitation_token") %></dt>
<dd><%= invitation.token %></dd>
<dt><%= t(".copy_link") %></dt>
<dd>
<% unless invitation.redeemed_at %>
<%= link_to t(".copy_and_use"), signup_path(invitation_token: invitation.token) %>
<% end %>
</dd>
<dt><%= t(".sent_to") %></dt>
<dd>
<% if invitation.redeemed_at %>
<dd><%= invitation.invitee_email %></dd>
<%= invitation.invitee_email %>
<% else %>
<dd>
<%= form_for(invitation) do |f| %>
<%= error_messages_for invitation %>
<p><%= f.label :invitee_email, t(".email_address_label") %> <%= f.text_field :invitee_email %></p>
<p><%= hidden_field_tag :user_id, @user.try(:login) %></p>
<p class="submit actions"><%= f.submit %></p>
<% end %>
</dd>
<% end %>
<dt>Redeemed by</dt>
<dd><%= invitee_link(invitation) %></dd>
<dt>Created at</dt>
<dd><%= invitation.created_at %></dd>
<dt>Sent at</dt>
<dd><%= invitation.sent_at %></dd>
<dt>Redeemed at</dt>
<dd><%= invitation.redeemed_at %></dd>
</dd>
<dt><%= t(".redeemed_by") %></dt>
<dd><%= invitee_link(invitation) %></dd>
<dt><%= t(".created_at") %></dt>
<dd><%= invitation.created_at %></dd>
<dt><%= t(".sent_at") %></dt>
<dd><%= invitation.sent_at %></dd>
<dt><%= t(".redeemed_at") %></dt>
<dd><%= invitation.redeemed_at %></dd>
</dl>
12 changes: 12 additions & 0 deletions config/locales/views/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,19 @@ en:
what_you_cant_do: What you can't do
invitations:
invitation:
copy_and_use: copy and use
copy_link: Copy link
created_at: Created at
deleted_user: deleted user
deleted_user_with_id: deleted user (%{user_id})
Comment on lines +1364 to +1365
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you fix the capitalization here? shakes fist at lowercase

email_address_label: Enter an email address
invitation_token: Invitation token
queue: queue
redeemed_at: Redeemed at
redeemed_by: Redeemed by
sender: Sender
sent_at: Sent at
sent_to: Sent to
invite_requests:
index_open:
add_to_list: Add me to the list
Expand Down
48 changes: 48 additions & 0 deletions spec/helpers/invitations_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

require "spec_helper"

describe InvitationsHelper do
describe "#invitee_link" do
let(:invitation) { create(:invitation) }

context "when the invitee is an existing user" do
let(:user) { create(:user) }

before do
invitation.update!(invitee: user)
end

it "returns a link to the user" do
expect(helper.invitee_link(invitation)).to eq(link_to(user.login, user_path(user)))
end
end

context "when the invitee is a deleted user" do
let(:user) { create(:user) }

before do
invitation.update!(invitee: user)
user.destroy!
invitation.reload
end

it "returns a placeholder with the user ID" do
expect(helper.invitee_link(invitation)).to eq("deleted user")
end

context "when logged in as an admin" do
let(:admin) { build(:admin) }
let!(:user_id) { user.id }

before do
User.current_user = admin
end

it "returns a placeholder with the user ID" do
expect(helper.invitee_link(invitation)).to eq("deleted user (#{user_id})")
end
end
end
end
end
Loading