Skip to content

Commit

Permalink
Merge pull request #2025 from alphagov/content-modelling/632-send-las…
Browse files Browse the repository at this point in the history
…t_edited_by_editor_id-to-publishing-api

Send last_edited_by_editor_id to publishing api
  • Loading branch information
pezholio authored Oct 21, 2024
2 parents 90aeecc + 7bf92f3 commit 763682d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/models/travel_advice_edition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ def has_valid_change_description_for_scheduling?
false
end

def created_by
creation = actions.detect do |a|
a.request_type == Action::CREATE || a.request_type == Action::NEW_VERSION
end
creation.requester if creation
end

private

def state_for_slug_unique
Expand Down
3 changes: 2 additions & 1 deletion app/presenters/edition_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ def render_for_publishing_api
"rendering_app" => "government-frontend",
"routes" => routes,
"public_updated_at" => public_updated_at.iso8601,
"last_edited_by_editor_id" => edition.created_by&.uid,
"update_type" => update_type,
"details" => details,
"change_note" => change_description,
}
}.compact
end

private
Expand Down
19 changes: 19 additions & 0 deletions spec/models/travel_advice_edition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -861,4 +861,23 @@
end
end
end

describe "#created_by" do
let!(:user) { create(:user) }
let!(:edition) { create(:draft_travel_advice_edition, country_slug: "foo") }

it "returns nil by default" do
expect(edition.created_by).to eq(nil)
end

it "returns the requester of the first CREATE action when present" do
edition.build_action_as(user, Action::CREATE)
expect(edition.created_by).to eq(user)
end

it "returns the requester of the first NEW_VERSION action when present" do
edition.build_action_as(user, Action::NEW_VERSION, "a comment for the new version")
expect(edition.created_by).to eq(user)
end
end
end
28 changes: 28 additions & 0 deletions spec/presenters/edition_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,33 @@
expect(presented_data["update_type"]).to eq("republish")
end
end

describe "when there is an associated CREATE action" do
before do
edition.actions.build(
request_type: Action::CREATE,
requester: user,
comment: "Some comment",
)
end

it "includes the requester's uid" do
expect(presented_data["last_edited_by_editor_id"]).to eq(user.uid)
end
end

describe "when there is an associated NEW_VERSION action" do
before do
edition.actions.build(
request_type: Action::NEW_VERSION,
requester: user,
comment: "Some comment",
)
end

it "includes the requester's uid" do
expect(presented_data["last_edited_by_editor_id"]).to eq(user.uid)
end
end
end
end

0 comments on commit 763682d

Please sign in to comment.