-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2334 from alphagov/add-my-apps-page
Add a page listing the current user's applications
- Loading branch information
Showing
18 changed files
with
326 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Account::ApplicationsController < ApplicationController | ||
layout "admin_layout" | ||
|
||
before_action :authenticate_user! | ||
|
||
def index | ||
authorize :account_applications | ||
|
||
@applications_with_signin = Doorkeeper::Application.can_signin(current_user) | ||
@applications_without_signin = Doorkeeper::Application.not_retired.without_signin_permission_for(current_user) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class AccountsController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def show | ||
authorize :account_page | ||
|
||
if policy(current_user).edit? | ||
redirect_to edit_user_path(current_user) | ||
else | ||
redirect_to edit_email_or_password_user_path(current_user) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AccountApplicationsPolicy < BasePolicy | ||
def index? | ||
current_user.govuk_admin? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AccountPagePolicy < BasePolicy | ||
def show? | ||
current_user.present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<% content_for :title, "GOV.UK apps" %> | ||
|
||
<% content_for :breadcrumbs, | ||
render("govuk_publishing_components/components/breadcrumbs", { | ||
collapse_on_mobile: true, | ||
breadcrumbs: [ | ||
{ | ||
title: "Dashboard", | ||
url: root_path, | ||
}, | ||
{ | ||
title: "GOV.UK apps", | ||
} | ||
] | ||
}) | ||
%> | ||
|
||
<table class="govuk-table"> | ||
<caption class="govuk-table__caption govuk-table__caption--m">Apps you have access to</caption> | ||
<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> | ||
</tr> | ||
</thead> | ||
<tbody class="govuk-table__body"> | ||
<% @applications_with_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> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
<h2 class="govuk-heading-m" id="other-apps-table-heading">Apps you don't have access to</h2> | ||
|
||
<table class="govuk-table" aria-labelledby="other-apps-table-heading"> | ||
<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> | ||
</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> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require "test_helper" | ||
|
||
class AccountApplicationsTest < ActionDispatch::IntegrationTest | ||
context "#index" 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 "not be accessible to signed out users" do | ||
visit account_applications_path | ||
|
||
assert_current_url new_user_session_path | ||
end | ||
|
||
should "list the applications the user has access to" do | ||
@user.grant_application_signin_permission(@application) | ||
|
||
visit new_user_session_path | ||
signin_with @user | ||
|
||
visit account_applications_path | ||
|
||
table = find("table caption[text()='Apps you have access to']").ancestor("table") | ||
assert table.has_content?("app-name") | ||
assert table.has_content?("app-description") | ||
end | ||
|
||
should "not list retired applications the user has access to" do | ||
@user.grant_application_signin_permission(@retired_application) | ||
|
||
visit new_user_session_path | ||
signin_with @user | ||
|
||
visit account_applications_path | ||
|
||
assert_not page.has_content?("retired-app-name") | ||
end | ||
|
||
should "list the applications the user does not have access to" do | ||
visit new_user_session_path | ||
signin_with @user | ||
|
||
visit account_applications_path | ||
|
||
heading = find("h2", text: "Apps you don't have access to") | ||
table = find("table[aria-labelledby='#{heading['id']}']") | ||
|
||
assert table.has_content?("app-name") | ||
assert table.has_content?("app-description") | ||
end | ||
|
||
should "not list retired applications the user does not have access to" do | ||
visit new_user_session_path | ||
signin_with @user | ||
|
||
visit account_applications_path | ||
|
||
assert_not page.has_content?("retired-app-name") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "test_helper" | ||
|
||
class AccountTest < ActionDispatch::IntegrationTest | ||
context "#show" do | ||
should "not be accessible to signed out users" do | ||
visit account_path | ||
|
||
assert_current_url new_user_session_path | ||
end | ||
|
||
should "redirect to user's edit page for admin users" do | ||
user = FactoryBot.create(:admin_user) | ||
|
||
visit new_user_session_path | ||
signin_with user | ||
|
||
visit account_path | ||
|
||
assert_current_url edit_user_path(user) | ||
end | ||
|
||
should "redirect to edit email or password page for normal users" do | ||
user = FactoryBot.create(:user) | ||
|
||
visit new_user_session_path | ||
signin_with user | ||
|
||
visit account_path | ||
|
||
assert_current_url edit_email_or_password_user_path(user) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.