-
Notifications
You must be signed in to change notification settings - Fork 193
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 #9812 from alphagov/content-modelling/774-user-page
content modelling/774 user page
- Loading branch information
Showing
22 changed files
with
210 additions
and
54 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
3 changes: 3 additions & 0 deletions
3
...ger/app/components/content_block_manager/signon_user/show/summary_list_component.html.erb
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,3 @@ | ||
<%= render "govuk_publishing_components/components/summary_list", { | ||
items:, | ||
} %> |
36 changes: 36 additions & 0 deletions
36
...k_manager/app/components/content_block_manager/signon_user/show/summary_list_component.rb
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,36 @@ | ||
class ContentBlockManager::SignonUser::Show::SummaryListComponent < ViewComponent::Base | ||
def initialize(user:) | ||
@user = user | ||
end | ||
|
||
private | ||
|
||
def items | ||
[ | ||
name_item, | ||
email_item, | ||
organisation_item, | ||
].compact | ||
end | ||
|
||
def name_item | ||
{ | ||
field: "Name", | ||
value: @user.name, | ||
} | ||
end | ||
|
||
def email_item | ||
{ | ||
field: "Email", | ||
value: @user.email, | ||
} | ||
end | ||
|
||
def organisation_item | ||
{ | ||
field: "Organisation", | ||
value: @user.organisation.name, | ||
} | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
lib/engines/content_block_manager/app/controllers/content_block_manager/users_controller.rb
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,7 @@ | ||
class ContentBlockManager::UsersController < ContentBlockManager::BaseController | ||
def show | ||
@user = ContentBlockManager::SignonUser.with_uuids([params[:id]]).first | ||
|
||
raise ActiveRecord::RecordNotFound, "Could not find User with ID #{params[:id]}" if @user.blank? | ||
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
16 changes: 0 additions & 16 deletions
16
...ngines/content_block_manager/app/models/content_block_manager/host_content_item/editor.rb
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
...t_block_manager/app/models/content_block_manager/host_content_item/editor/organisation.rb
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
lib/engines/content_block_manager/app/models/content_block_manager/signon_user.rb
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 @@ | ||
module ContentBlockManager | ||
class SignonUser < Data.define(:uid, :name, :email, :organisation) | ||
def self.with_uuids(uuids) | ||
Services.signon_api_client.get_users(uuids:).map do |user| | ||
new( | ||
uid: user["uid"], | ||
name: user["name"], | ||
email: user["email"], | ||
organisation: ContentBlockManager::SignonUser::Organisation.from_user_hash(user), | ||
) | ||
end | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
...ngines/content_block_manager/app/models/content_block_manager/signon_user/organisation.rb
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,15 @@ | ||
module ContentBlockManager | ||
class SignonUser | ||
class Organisation < Data.define(:content_id, :name, :slug) | ||
def self.from_user_hash(user) | ||
if user["organisation"].present? | ||
new( | ||
content_id: user["organisation"]["content_id"], | ||
name: user["organisation"]["name"], | ||
slug: user["organisation"]["slug"], | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
lib/engines/content_block_manager/app/views/content_block_manager/users/show.html.erb
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,11 @@ | ||
<% content_for :title, @user.name %> | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= render( | ||
ContentBlockManager::SignonUser::Show::SummaryListComponent.new( | ||
user: @user, | ||
), | ||
) %> | ||
</div> | ||
</div> |
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 |
---|---|---|
|
@@ -513,13 +513,14 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_ | |
end | ||
|
||
When(/^dependent content exists for a content block$/) do | ||
host_editor_id = SecureRandom.uuid | ||
@dependent_content = 10.times.map do |i| | ||
{ | ||
"title" => "Content #{i}", | ||
"document_type" => "document", | ||
"base_path" => "/host-content-path-#{i}", | ||
"content_id" => SecureRandom.uuid, | ||
"last_edited_by_editor_id" => SecureRandom.uuid, | ||
"last_edited_by_editor_id" => host_editor_id, | ||
"last_edited_at" => 2.days.ago.to_s, | ||
"host_content_id" => "abc12345", | ||
"instances" => 1, | ||
|
@@ -542,9 +543,11 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_ | |
|
||
stub_publishing_api_has_embedded_content_details(@dependent_content.first) | ||
|
||
@host_content_editor = build(:signon_user, uid: host_editor_id) | ||
|
||
stub_request(:get, "#{Plek.find('signon', external: true)}/api/users") | ||
.with(query: { uuids: @dependent_content.map { |item| item["last_edited_by_editor_id"] } }) | ||
.to_return(body: [].to_json) | ||
.with(query: { uuids: [host_editor_id] }) | ||
.to_return(body: [@host_content_editor].to_json) | ||
end | ||
|
||
Then(/^I should see the dependent content listed$/) do | ||
|
@@ -554,6 +557,8 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_ | |
assert_text item["title"] | ||
break if item == @dependent_content.last | ||
end | ||
|
||
expect(page).to have_link(@host_content_editor.name, href: content_block_manager.content_block_manager_user_path(@host_content_editor.uid)) | ||
end | ||
|
||
Then(/^I (should )?see the rollup data for the dependent content$/) do |_should| | ||
|
@@ -851,3 +856,28 @@ def click_save_and_continue | |
jobs = Sidekiq::ScheduledSet.new.select { |job| job.item["class"] == ContentBlockManager::SchedulePublishingWorker.to_s } | ||
expect(jobs.count).to eq(0) | ||
end | ||
|
||
Given("A user exists with uuid {string}") do |uuid| | ||
@user_from_signon = build( | ||
:signon_user, | ||
uid: uuid, | ||
name: "John Doe", | ||
email: "[email protected]", | ||
organisation: build(:signon_user_organisation, content_id: "456", name: "User's Org", slug: "users-org"), | ||
) | ||
|
||
stub_request(:get, "#{Plek.find('signon', external: true)}/api/users") | ||
.with(query: { uuids: [uuid] }) | ||
.to_return(body: [@user_from_signon].to_json) | ||
end | ||
|
||
When("I visit the user page for uuid {string}") do |uuid| | ||
visit content_block_manager.content_block_manager_user_path(uuid) | ||
end | ||
|
||
Then("I should see the details for that user") do | ||
expect(page).to have_selector("h1", text: @user_from_signon.name) | ||
expect(page).to have_selector(".govuk-summary-list__value", text: @user_from_signon.name) | ||
expect(page).to have_selector(".govuk-summary-list__value", text: @user_from_signon.email) | ||
expect(page).to have_selector(".govuk-summary-list__value", text: @user_from_signon.organisation.name) | ||
end |
8 changes: 8 additions & 0 deletions
8
lib/engines/content_block_manager/features/view_users.feature
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,8 @@ | ||
Feature: View users | ||
Background: | ||
Given I am a GDS admin | ||
And A user exists with uuid "123" | ||
|
||
Scenario: GDS Editor views a user | ||
When I visit the user page for uuid "123" | ||
Then I should see the details for that user |
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
31 changes: 31 additions & 0 deletions
31
...nes/content_block_manager/test/components/signon_user/show/summary_list_component_test.rb
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,31 @@ | ||
require "test_helper" | ||
|
||
class ContentBlockManager::SignonUser::Show::SummaryListComponentTest < ViewComponent::TestCase | ||
extend Minitest::Spec::DSL | ||
include ContentBlockManager::Engine.routes.url_helpers | ||
|
||
let(:organisation) { build(:signon_user_organisation, name: "Department for Example") } | ||
let(:user) do | ||
build( | ||
:signon_user, | ||
name: "John Smith", | ||
email: "[email protected]", | ||
organisation:, | ||
) | ||
end | ||
|
||
it "renders a Govuk User correctly" do | ||
render_inline(ContentBlockManager::SignonUser::Show::SummaryListComponent.new(user:)) | ||
|
||
assert_selector ".govuk-summary-list__row", count: 3 | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Name" | ||
assert_selector ".govuk-summary-list__value", text: user.name | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Email" | ||
assert_selector ".govuk-summary-list__value", text: user.email | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Organisation" | ||
assert_selector ".govuk-summary-list__value", text: user.organisation.name | ||
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
4 changes: 2 additions & 2 deletions
4
...est/factories/host_content_item_editor.rb → ...ock_manager/test/factories/signon_user.rb
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
2 changes: 1 addition & 1 deletion
2
.../host_content_item_editor_organisation.rb → ...est/factories/signon_user_organisation.rb
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
25 changes: 25 additions & 0 deletions
25
lib/engines/content_block_manager/test/integration/users_test.rb
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,25 @@ | ||
require "test_helper" | ||
require "capybara/rails" | ||
|
||
class ContentBlockManager::ContentBlock::UsersTest < ActionDispatch::IntegrationTest | ||
include Capybara::DSL | ||
extend Minitest::Spec::DSL | ||
include ContentBlockManager::Engine.routes.url_helpers | ||
|
||
setup do | ||
logout | ||
@organisation = create(:organisation) | ||
user = create(:gds_admin, organisation: @organisation) | ||
login_as(user) | ||
end | ||
|
||
describe "#show" do | ||
let(:user_uuid) { SecureRandom.uuid } | ||
|
||
it "returns 404 if the user doesn't exist" do | ||
ContentBlockManager::SignonUser.expects(:with_uuids).with([user_uuid]).returns([]) | ||
visit content_block_manager_user_path(user_uuid) | ||
assert_text "Could not find User with ID #{user_uuid}" | ||
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.