-
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 #9789 from alphagov/content-modelling/782-pull-use…
…r-details-from-signon (782) Pull user details from Signon
- Loading branch information
Showing
15 changed files
with
222 additions
and
84 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
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
16 changes: 16 additions & 0 deletions
16
...ngines/content_block_manager/app/models/content_block_manager/host_content_item/editor.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,16 @@ | ||
module ContentBlockManager | ||
class HostContentItem | ||
class Editor < 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::HostContentItem::Editor::Organisation.from_user_hash(user), | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
...t_block_manager/app/models/content_block_manager/host_content_item/editor/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,17 @@ | ||
module ContentBlockManager | ||
class HostContentItem | ||
class Editor | ||
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 | ||
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
17 changes: 17 additions & 0 deletions
17
lib/engines/content_block_manager/test/factories/host_content_item_editor.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,17 @@ | ||
FactoryBot.define do | ||
factory :host_content_item_editor, class: "ContentBlockManager::HostContentItem::Editor" do | ||
uid { SecureRandom.uuid } | ||
sequence(:name) { |i| "Someone #{i}" } | ||
sequence(:email) { |i| "someone-#{i}@example.com" } | ||
organisation { build(:host_content_item_editor_organisation) } | ||
|
||
initialize_with do | ||
new( | ||
uid:, | ||
name:, | ||
email:, | ||
organisation:, | ||
) | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
lib/engines/content_block_manager/test/factories/host_content_item_editor_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 @@ | ||
FactoryBot.define do | ||
factory :host_content_item_editor_organisation, class: "ContentBlockManager::HostContentItem::Editor::Organisation" do | ||
content_id { SecureRandom.uuid } | ||
sequence(:name) { |i| "organisation #{i}" } | ||
sequence(:slug) { |i| "organisation-#{i}" } | ||
|
||
initialize_with do | ||
new( | ||
content_id:, | ||
name:, | ||
slug:, | ||
) | ||
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
57 changes: 57 additions & 0 deletions
57
lib/engines/content_block_manager/test/unit/app/models/host_content_item/editor_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,57 @@ | ||
require "test_helper" | ||
|
||
class ContentBlockManager::HostContentItem::EditorTest < ActiveSupport::TestCase | ||
extend Minitest::Spec::DSL | ||
|
||
describe ".with_uuids" do | ||
let(:signon_api_stub) { stub } | ||
|
||
before do | ||
Services.expects(:signon_api_client).returns(signon_api_stub) | ||
end | ||
|
||
it "returns an empty array when no UUIDs are provided" do | ||
signon_api_stub.expects(:get_users).with(uuids: []).returns([]) | ||
|
||
result = ContentBlockManager::HostContentItem::Editor.with_uuids([]) | ||
|
||
assert_equal [], result | ||
end | ||
|
||
it "fetches users for a given list of UUIDs" do | ||
uuids = [SecureRandom.uuid, SecureRandom.uuid] | ||
api_response = [ | ||
{ | ||
"uid" => uuids[0], | ||
"name" => "Someone", | ||
"email" => "[email protected]", | ||
}, | ||
{ | ||
"uid" => uuids[1], | ||
"name" => "Someone else", | ||
"email" => "[email protected]", | ||
"organisation" => { | ||
"content_id" => SecureRandom.uuid, | ||
"name" => "Organisation", | ||
"slug" => "organisation", | ||
}, | ||
}, | ||
] | ||
signon_api_stub.expects(:get_users).with(uuids:).returns(api_response) | ||
|
||
result = ContentBlockManager::HostContentItem::Editor.with_uuids(uuids) | ||
|
||
assert_equal result[0].uid, api_response[0]["uid"] | ||
assert_equal result[0].name, api_response[0]["name"] | ||
assert_equal result[0].email, api_response[0]["email"] | ||
assert_nil result[0].organisation | ||
|
||
assert_equal result[1].uid, api_response[1]["uid"] | ||
assert_equal result[1].name, api_response[1]["name"] | ||
assert_equal result[1].email, api_response[1]["email"] | ||
assert_equal result[1].organisation.content_id, api_response[1]["organisation"]["content_id"] | ||
assert_equal result[1].organisation.name, api_response[1]["organisation"]["name"] | ||
assert_equal result[1].organisation.slug, api_response[1]["organisation"]["slug"] | ||
end | ||
end | ||
end |
Oops, something went wrong.