Skip to content

Commit 05dbdd9

Browse files
committed
Add entry endpoint to handle users from Signon
We've got a bit of a problem at the moment with users arriving to Chat from Signon. Consider the following user groups: - GOV.UK AI Team users who have access to the Admin Interface and want to use it for monitoring and evaluation purposes. Generally, these users will not have the 'web-chat' permission and will be unable to access the Chat Interface. - Departmental users who don't have access to the Admin Interface, but do have the 'web-chat' permission and want to test Chat. Both of these users will often, particularly the first time they arrive, use the link to the application in Signon[1]. The link currently points to the Admin UI, which is confusing for departmental users who may not know how to amend the url to get to the Chat Interface. Ideally, we shouldn't have to either: - Update it to point to the Chat Interface and have to let internal users know how to get to the Admin Interface, or - Point it to the Admin Interface and have to let departmental users know how to get to the Chat Interface. To get round this, we're going to add a new endpoint that we will link to from Signon. This endpoint will check the current_users permissisions and: - Redirect them to the Admin Interface if the have the 'admin-area' permission - Redirect them to the Chat Interface if they have the 'web-chat' permission - Prioritise the Admin Interface if they have both permissions - Render the forbidden page if they have neither permission The EntryController inherits from the BaseController which already handles user authentication, so we can be sure that the user is signed in when they hit this endpoint. I've skipped the authorise_web_user! and check_chat_web_access before actions. The reason for this is: - authorise_web_user!: We don't want this to run before the action as it would return a 403 for a user who has the 'admin-area' permission but doesn't have the 'web-chat' permission. As mentioned above, if a user doesn't have either permission then this endpoint will return a 403 forbidden response after checking permissions. - check_chat_web_access: We only want to check that the Settings web chat access is enabled and render the downtime page if the user has the 'web-chat' permission and doesn't have the 'admin-area' permission. Due to this, i've called it within the conditional that is only reached after we've established that the user doesn't have the 'admin-area' permission but does have the 'web-chat' permission. [1]: https://signon.publishing.service.gov.uk/doorkeeper_applications/9615/edit
1 parent 3587385 commit 05dbdd9

3 files changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class EntryController < BaseController
2+
skip_before_action :authorise_web_user
3+
skip_before_action :check_chat_web_access
4+
5+
def index
6+
if current_user.has_permission?(SignonUser::Permissions::ADMIN_AREA)
7+
redirect_to admin_homepage_path
8+
elsif current_user.has_permission?(SignonUser::Permissions::WEB_CHAT)
9+
unless check_chat_web_access
10+
redirect_to homepage_path
11+
end
12+
else
13+
render "errors/forbidden", status: :forbidden
14+
end
15+
end
16+
end

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
scope :chat, format: false, defaults: { format: "html" }, constraints: html_constraint do
2424
get "", to: "homepage#index", as: :homepage
25+
get "/entry", to: "entry#index", as: :entry
2526

2627
scope :conversation do
2728
get "", to: "conversations#show", as: :show_conversation

spec/requests/entry_spec.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
RSpec.describe "EntryController" do
2+
describe "GET :index" do
3+
it "redirects users with the 'admin-area' permission to the Admin UI" do
4+
login_as(create(:signon_user, :admin))
5+
get entry_path
6+
7+
expect(response).to have_http_status(:redirect)
8+
expect(response).to redirect_to(admin_homepage_path)
9+
end
10+
11+
it "redirects users with the 'web-chat' permission to the homepage" do
12+
login_as(create(:signon_user, :web_chat))
13+
get entry_path
14+
15+
expect(response).to have_http_status(:redirect)
16+
expect(response).to redirect_to(homepage_path)
17+
end
18+
19+
it "redirects users with both 'admin-area' and 'web-chat' permissions to the Admin UI" do
20+
login_as(create(:signon_user, permissions: %w[admin-area web-chat]))
21+
22+
get entry_path
23+
24+
expect(response).to have_http_status(:redirect)
25+
expect(response).to redirect_to(admin_homepage_path)
26+
end
27+
28+
it "renders forbidden for users without the 'admin-area' or 'web-chat' permissions" do
29+
login_as(create(:signon_user))
30+
get entry_path
31+
expect(response).to have_http_status(:forbidden)
32+
end
33+
34+
context "when web access is disabled" do
35+
before { create(:settings, web_access_enabled: false) }
36+
37+
it "redirects users with the 'admin-area' permission to the Admin UI" do
38+
login_as(create(:signon_user, :admin))
39+
40+
get entry_path
41+
42+
expect(response).to have_http_status(:redirect)
43+
expect(response).to redirect_to(admin_homepage_path)
44+
end
45+
46+
it "renders the downtime page for non-admin users with the 'web-chat' permission" do
47+
login_as(create(:signon_user, :web_chat))
48+
49+
get entry_path
50+
51+
expect(response).to have_http_status(:service_unavailable)
52+
expect(response.body)
53+
.to have_content("GOV.UK Chat is not currently available")
54+
end
55+
end
56+
end
57+
end

0 commit comments

Comments
 (0)