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-5498 AO3-931 Show placeholder for deleted invitee #5000

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
20 changes: 14 additions & 6 deletions app/helpers/invitations_helper.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
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
sarken marked this conversation as resolved.
Show resolved Hide resolved
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)
return unless invitation.invitee_type == "User"

if User.current_user.is_a?(Admin) && policy(invitation).access_invitee_details?
return t("invitations.invitation.user_id_deleted", user_id: invitation.invitee_id) if invitation.invitee.blank?

return link_to(invitation.invitee.login, admin_user_path(invitation.invitee))
end

return t("invitations.invitation.deleted_user") if invitation.invitee.blank?

link_to(invitation.invitee.login, invitation.invitee) if invitation.invitee.present?
end
end
7 changes: 7 additions & 0 deletions app/policies/invitation_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class InvitationPolicy < ApplicationPolicy
EXTRA_INFO_ROLES = %w[superadmin open_doors policy_and_abuse support tag_wrangling].freeze

def access_invitee_details?
user_has_roles?(EXTRA_INFO_ROLES)
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
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
user_id_deleted: User %{user_id} (Deleted)
invite_requests:
index_open:
add_to_list: Add me to the list
Expand Down
30 changes: 30 additions & 0 deletions features/admins/admin_invitations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,33 @@ Feature: Admin Actions to Manage Invitations
| position | email |
| 1 | [email protected] |
| 5 | [email protected] |

Scenario Outline: Viewing a user's invitation details
Given the user "creator" exists and is activated
And the user "invitee" exists and is activated
And an invitation created by "creator" and used by "invitee"
And I am logged in as a "<role>" admin
When I manage invitations belonging to "creator"
Then I should see "invitee"
When I view the most recent invitation for "creator"
Then I should see "invitee"
When I follow "invitee"
Then I should see "User: invitee"
When I am logged in as "invitee"
And "invitee" deletes their account
And I am logged in as a "<role>" admin
And I manage invitations belonging to "creator"
Then I should see "(Deleted)"
But I should not see "invitee"
When I view the most recent invitation for "creator"
Then I should see "User"
And I should see "(Deleted)"
But I should not see "invitee"

Examples:
| role |
| superadmin |
| tag_wrangling |
| support |
| policy_and_abuse |
| open_doors |
19 changes: 19 additions & 0 deletions features/other_a/invite_use.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,22 @@ I want to use an invitation to create an account
And I go to SOME_USER2's invitations page
Then I should be on Scott's user page
And I should see "Sorry, you don't have permission to access the page you were trying to reach."

Scenario: Viewing invitation details when the invitee has deleted their account
Given the user "creator" exists and is activated
And the user "invitee" exists and is activated
And an invitation created by "creator" and used by "invitee"
And I am logged in as "creator"
When I manage invitations belonging to "creator"
brianjaustin marked this conversation as resolved.
Show resolved Hide resolved
Then I should see "invitee"
When I view the most recent invitation for "creator"
Then I should see "invitee"
When I am logged in as "invitee"
And "invitee" deletes their account
And I am logged in as "creator"
And I manage invitations belonging to "creator"
Then I should see "Deleted User"
But I should not see "invitee"
When I view the most recent invitation for "creator"
Then I should see "Deleted User"
But I should not see "invitee"
brianjaustin marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions features/step_definitions/invite_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def invite(attributes = {})
allow(InviteRequest).to receive(:per_page).and_return(amount)
end

Given "an invitation created by {string} and used by {string}" do |creator, invitee|
creator = User.find_by(login: creator)
invitee = User.find_by(login: invitee)
FactoryBot.create(:invitation, creator: creator, invitee: invitee)
end

### WHEN

When /^I use an invitation to sign up$/ do
Expand Down Expand Up @@ -156,6 +162,16 @@ def invite(attributes = {})
click_button("Look me up")
end

When "I manage invitations belonging to {string}" do |creator|
visit manage_user_invitations_path(creator)
end

When "I view the most recent invitation for {string}" do |creator|
user = User.find_by(login: creator)
invitation = user.invitations.last
visit user_invitation_path(creator, invitation)
end

### Then

Then /^I should see how long I have to activate my account$/ do
Expand Down
Loading