GRN2-174: Added 404 if user does not exist (#609)

* Added 404 if user does not exist

* Differentiated between 404 and 500

* Rspec fixes
This commit is contained in:
farhatahmad 2019-07-09 11:00:33 -04:00 committed by Jesus Federico
parent e4f50026f1
commit 5d4bd1b851
4 changed files with 54 additions and 8 deletions

View File

@ -131,10 +131,21 @@ class ApplicationController < ActionController::Base
end
def set_user_domain
@user_domain = if Rails.env.test? || !Rails.configuration.loadbalanced_configuration
"greenlight"
if Rails.env.test? || !Rails.configuration.loadbalanced_configuration
@user_domain = "greenlight"
else
parse_user_domain(request.host)
@user_domain = parse_user_domain(request.host)
# Checks to see if the user exists
begin
retrieve_provider_info(@user_domain, 'api2', 'getUserGreenlightCredentials')
rescue => e
if e.message.eql? "No user with that id exists"
render "errors/not_found", locals: { user_not_found: true }
else
render "errors/internal_error"
end
end
end
end
helper_method :set_user_domain

View File

@ -15,9 +15,14 @@
<div class="container text-center pt-9">
<div class="display-1 text-muted mb-5">404</div>
<% if defined?(user_not_found) %>
<h1 class="h2 mb-3"><%= t("errors.not_found.user_message") %></h1>
<p class="h4 text-muted font-weight-normal mb-7"><%= t("errors.not_found.user_help") %></p>
<% else %>
<h1 class="h2 mb-3"><%= t("errors.not_found.message") %></h1>
<p class="h4 text-muted font-weight-normal mb-7"><%= t("errors.not_found.help") %></p>
<a class="btn btn-primary" href="javascript:history.back()">
<i class="fas fa-arrow-left mr-2"></i><%= t("go_back") %>
</a>
<% end %>
</div>

View File

@ -140,6 +140,8 @@ en:
not_found:
message: Whoops! Looks like we can't find that.
help: Is it possible its been removed?
user_message: User Not Found.
user_help: Sorry, this user is not registered.
title: Errors
unauthorized:
message: You do not have access to this application

View File

@ -31,6 +31,10 @@ describe ApplicationController do
def error
raise BigBlueButton::BigBlueButtonException
end
def user_not_found
set_user_domain
end
end
context "roles" do
@ -66,5 +70,29 @@ describe ApplicationController do
get :error
expect(response).to render_template("errors/bigbluebutton_error")
end
it "renders a 404 error if user is not found" do
allow(Rails.configuration).to receive(:loadbalanced_configuration).and_return(true)
allow(Rails.env).to receive(:test?).and_return(false)
allow_any_instance_of(SessionsHelper).to receive(:parse_user_domain).and_return("")
allow_any_instance_of(BbbApi).to receive(:retrieve_provider_info).and_raise("No user with that id exists")
routes.draw { get "user_not_found" => "anonymous#user_not_found" }
get :user_not_found
expect(response).to render_template("errors/not_found")
end
it "renders a 500 error if any other error is not found" do
allow(Rails.configuration).to receive(:loadbalanced_configuration).and_return(true)
allow(Rails.env).to receive(:test?).and_return(false)
allow_any_instance_of(SessionsHelper).to receive(:parse_user_domain).and_return("")
allow_any_instance_of(BbbApi).to receive(:retrieve_provider_info).and_raise("Other error")
routes.draw { get "user_not_found" => "anonymous#user_not_found" }
get :user_not_found
expect(response).to render_template("errors/internal_error")
end
end
end