-
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.
Introduce Your account access log Account sub-page
This provides another bit of functionality that was lost in the switch from Users#edit to the new Account page. It's pretty much identical to the Users#event_logs page except for living under /account
- Loading branch information
Showing
8 changed files
with
83 additions
and
0 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,16 @@ | ||
class Account::ActivitiesController < ApplicationController | ||
layout "admin_layout" | ||
|
||
before_action :authenticate_user! | ||
before_action :authorise_user | ||
|
||
def show | ||
@logs = current_user.event_logs.page(params[:page]).per(100) | ||
end | ||
|
||
private | ||
|
||
def authorise_user | ||
authorize %i[account activities] | ||
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 Account::ActivitiesPolicy < 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,22 @@ | ||
<% content_for :title, "Account access log" %> | ||
|
||
<% content_for :breadcrumbs, | ||
render("govuk_publishing_components/components/breadcrumbs", { | ||
collapse_on_mobile: true, | ||
breadcrumbs: [ | ||
{ | ||
title: "Dashboard", | ||
url: root_path, | ||
}, | ||
{ | ||
title: "Settings", | ||
url: account_path, | ||
}, | ||
{ | ||
title: "Account access log", | ||
}, | ||
] | ||
}) | ||
%> | ||
|
||
<%= render "shared/event_logs_table", logs: @logs %> |
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,16 @@ | ||
require "test_helper" | ||
|
||
class AccountActivitiesTest < ActionDispatch::IntegrationTest | ||
context "#show" do | ||
should "list user's EventLogs in table" do | ||
user = create(:user) | ||
|
||
visit new_user_session_path | ||
signin_with user | ||
|
||
visit account_activity_path | ||
|
||
assert page.has_selector? "td", text: "Successful login" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require "test_helper" | ||
require "support/policy_helpers" | ||
|
||
class Account::ActivitiesPolicyTest < ActiveSupport::TestCase | ||
include PolicyHelpers | ||
|
||
should "allow logged in users to see show irrespective of their role" do | ||
assert permit?(build(:user), nil, :show) | ||
end | ||
|
||
should "not allow anonymous visitors to see show" do | ||
assert forbid?(nil, nil, :show) | ||
end | ||
end |