Skip to content

Commit

Permalink
Hide ID for non admins
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjaustin committed Dec 23, 2024
1 parent f62cf60 commit 6c11025
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
5 changes: 3 additions & 2 deletions app/helpers/invitations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def creator_link(invitation)

def invitee_link(invitation)
return unless invitation.invitee_type == "User"
return t("invitations.invitation.deleted_user", user_id: invitation.invitee_id) if invitation.invitee.blank?
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)

link_to(invitation.invitee.login, invitation.invitee)
t("invitations.invitation.deleted_user")
end
end
3 changes: 2 additions & 1 deletion config/locales/views/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,8 @@ en:
copy_and_use: copy and use
copy_link: Copy link
created_at: Created at
deleted_user: deleted user (%{user_id})
deleted_user: deleted user
deleted_user_with_id: deleted user (%{user_id})
email_address_label: Enter an email address
invitation_token: Invitation token
queue: queue
Expand Down
16 changes: 14 additions & 2 deletions spec/helpers/invitations_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

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

before do
invitation.update!(invitee: user)
Expand All @@ -29,7 +28,20 @@
end

it "returns a placeholder with the user ID" do
expect(helper.invitee_link(invitation)).to eq("deleted user (#{user_id})")
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
Expand Down

0 comments on commit 6c11025

Please sign in to comment.