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 1 commit
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
15 changes: 8 additions & 7 deletions app/helpers/invitations_helper.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
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 t("invitations.invitation.deleted_user", user_id: invitation.invitee_id) if invitation.invitee.blank?

link_to(invitation.invitee.login, invitation.invitee)
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>
11 changes: 11 additions & 0 deletions config/locales/views/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,18 @@ 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 (%{user_id})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you capitalize "Deleted" here so the invitee and sender will match when we do AO3-6095? I was going to say I'd add the user ID to that issue, but I think it would show the ID to users, not just admins, so we probably don't want that.

Relatedly, are we sure this only shows the user ID if you're an admin?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh at the moment it definitely shows to both, my thought was it's not a big concern because user ID isn't PII. But it's also not particularly useful to a non-admin so I am also not opposed to adding another check in the helper

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's go with an additional check, then! I'll update AO3-6095 to request the same behavior.

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
36 changes: 36 additions & 0 deletions spec/helpers/invitations_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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) }
let!(:user_id) { user.id }

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 (#{user_id})")
end
end
end
end
Loading