Skip to content

Commit

Permalink
WIP: Add ability for (super)admins to give themselves access to apps
Browse files Browse the repository at this point in the history
TODO:

- Style the button - should it look like a link?
- I feel like I should include the name of the app in the button for
  accessibility reasons but it'll become repetitive. Is this a real
concern?
- Should there be a special route for granting access to an app?
  Although signin is modelled like all other permissions it feels as
though it's treated as a special case nearly everywhere within the app
  • Loading branch information
chrisroos committed Sep 7, 2023
1 parent 9218913 commit acabe91
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/controllers/account/permissions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Account::PermissionsController < ApplicationController
# before_action :authenticate_user!
def create

Check failure on line 3 in app/controllers/account/permissions_controller.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/EmptyMethod: Put empty method definitions on a single line. (https://rubystyle.guide#no-single-line-methods)
end
end
4 changes: 3 additions & 1 deletion app/views/account/applications/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header govuk-!-width-one-quarter">Name</th>
<th scope="col" class="govuk-table__header govuk-!-width-three-quarters">Description</th>
<th scope="col" class="govuk-table__header govuk-!-width-two-quarters">Description</th>
<th scope="col" class="govuk-table__header govuk-!-width-one-quarter"></th>
</tr>
</thead>
<tbody class="govuk-table__body">
<% @applications_without_signin.each do |application| %>
<tr class="govuk-table__row">
<td class="govuk-table__cell"><%= application.name %></td>
<td class="govuk-table__cell"><%= application.description %></td>
<td class="govuk-table__cell"><%= button_to "Grant access to #{application.name}", account_application_permissions_path(application) %></td>
</tr>
<% end %>
</tbody>
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@

resource :account, only: [:show]
namespace :account do
resources :applications, only: [:index]
resources :applications, only: [:index] do
resource :permissions, only: [:create]
end
end

resources :batch_invitations, only: %i[new create show]
Expand Down
20 changes: 20 additions & 0 deletions test/integration/account_applications_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,24 @@ class AccountApplicationsTest < ActionDispatch::IntegrationTest
assert_not page.has_content?("retired-app-name")
end
end

context "granting access to apps" do
setup do
@application = create(:application, name: "app-name", description: "app-description")
@retired_application = create(:application, retired: true, name: "retired-app-name")
@user = FactoryBot.create(:admin_user)
end

should "foo" do
visit new_user_session_path
signin_with @user

visit account_applications_path

click_on "Grant access to app-name"

table = find("table caption[text()='Apps you have access to']").ancestor("table")
assert table.has_content?("app-name")
end
end
end

0 comments on commit acabe91

Please sign in to comment.