Skip to content

Commit

Permalink
[#55581] user generic error message for missing users
Browse files Browse the repository at this point in the history
  • Loading branch information
EinLama committed Nov 28, 2024
1 parent 38eefd2 commit 6f31a31
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/components/users/hover_card_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ See COPYRIGHT and LICENSE files for more details.
else
render Primer::Beta::Blankslate.new(border: false, narrow: true) do |component|
component.with_visual_icon(icon: "x-circle")
component.with_heading(tag: :h3).with_content(I18n.t("api_v3.errors.not_found.user"))
# Show a generic error message to avoid leaking information
component.with_heading(tag: :h3).with_content(I18n.t("http.response.unexpected"))
end
end
%>
2 changes: 1 addition & 1 deletion app/components/users/hover_card_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def initialize(id:)
super

@id = id
@user = User.find(@id)
@user = User.find_by(id: @id)
end

def show_email?
Expand Down
1 change: 0 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4136,7 +4136,6 @@ en:
code_500_missing_enterprise_token: "The request can not be handled due to invalid or missing Enterprise token."
not_found:
work_package: "The work package you are looking for cannot be found or has been deleted."
user: "The user you are looking for cannot be found or has been deleted."
expected:
date: "YYYY-MM-DD (ISO 8601 date only)"
datetime: "YYYY-MM-DDThh:mm:ss[.lll][+hh:mm] (any compatible ISO 8601 datetime)"
Expand Down
8 changes: 8 additions & 0 deletions spec/components/users/hover_card_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
page.find_test_selector("user-hover-card-name", text: user.name)
end

context "when the user does not exist" do
let(:user) { instance_double(User, id: 9000) }

it "renders a generic error message" do
expect(page).to have_text(I18n.t("http.response.unexpected"))
end
end

context "when displaying email addresses" do
it "hides the email address of a user" do
expect(page).not_to have_test_selector("user-hover-card-email")
Expand Down

0 comments on commit 6f31a31

Please sign in to comment.