Skip to content

Commit f9bd9fd

Browse files
committed
Merge branch '0.31-backports' of github.com:openpoke/decidim into 0.31-backports
2 parents 43d36a4 + aa18447 commit f9bd9fd

7 files changed

Lines changed: 131 additions & 1 deletion

File tree

decidim-collaborative_texts/app/views/decidim/collaborative_texts/admin/documents/edit.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<div class="item_show__header">
33
<h1 class="item_show__header-title">
44
<%= t(".title") %>
5+
<%= export_dropdown(current_component, @document.id) %>
56
</h1>
67
</div>
78
<div class="item__edit item__edit-1col">

decidim-collaborative_texts/config/locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ en:
7979
update_settings:
8080
invalid: There was a problem updating the document.
8181
success: Document successfully updated.
82+
exports:
83+
document_suggestions: Suggestions
8284
index:
8385
published: Published
8486
unpublished: Unpublished

decidim-collaborative_texts/lib/decidim/collaborative_texts.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
module Decidim
1010
# Base module for the collaborative_texts engine.
1111
module CollaborativeTexts
12+
autoload :SuggestionSerializer, "decidim/collaborative_texts/suggestion_serializer"
1213
end
1314
end

decidim-collaborative_texts/lib/decidim/collaborative_texts/component.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,18 @@
5656
resource.searchable = true
5757
end
5858

59-
# component.exports ...
59+
component.exports :document_suggestions do |exports|
60+
exports.collection do |component, _user, resource_id|
61+
documents_constraint = { decidim_component_id: component.id }
62+
documents_constraint[:id] = resource_id if resource_id.present?
63+
Decidim::CollaborativeTexts::Suggestion
64+
.joins(:document)
65+
.where(decidim_collaborative_texts_documents: documents_constraint)
66+
.includes(:document_version, document: [:component])
67+
end
68+
69+
exports.serializer Decidim::CollaborativeTexts::SuggestionSerializer
70+
end
6071

6172
component.seeds do |participatory_space|
6273
require "decidim/collaborative_texts/seeds"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
module Decidim
4+
module CollaborativeTexts
5+
class SuggestionSerializer < Decidim::Exporters::Serializer
6+
include Decidim::ApplicationHelper
7+
include Decidim::TranslationsHelper
8+
9+
def serialize
10+
{
11+
id: resource.id,
12+
document_id: resource.document.id,
13+
document_title: resource.document.title,
14+
original_text: resource.changeset["original"]&.join("\n")&.strip,
15+
replacement_text: resource.changeset["replace"]&.join("\n")&.strip,
16+
first_node: resource.changeset["firstNode"],
17+
last_node: resource.changeset["lastNode"],
18+
author: author_fields,
19+
status: resource.status,
20+
created_at: resource.created_at,
21+
updated_at: resource.updated_at
22+
}
23+
end
24+
25+
private
26+
27+
def author_fields
28+
return {} unless resource.author
29+
30+
{
31+
id: resource.author.id,
32+
name: author_name(resource.author),
33+
email: resource.author.try(:email)
34+
}
35+
end
36+
37+
def author_name(author)
38+
translated_attribute(author.name)
39+
end
40+
end
41+
end
42+
end
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
module Decidim
6+
module CollaborativeTexts
7+
describe SuggestionSerializer do
8+
subject { described_class.new(suggestion) }
9+
10+
let(:suggestion) { create(:collaborative_text_suggestion) }
11+
let(:serialized) { subject.serialize }
12+
13+
describe "#serialize" do
14+
it "serializes the id" do
15+
expect(serialized).to include(id: suggestion.id)
16+
end
17+
18+
it "serializes the document id" do
19+
expect(serialized).to include(document_id: suggestion.document.id)
20+
end
21+
22+
it "serializes the status" do
23+
expect(serialized).to include(status: suggestion.status)
24+
end
25+
26+
it "serializes the original text" do
27+
expect(serialized[:original_text]).to eq(
28+
suggestion.changeset["original"]&.join(" ")&.strip
29+
)
30+
end
31+
32+
it "serializes the replacement text" do
33+
expect(serialized[:replacement_text]).to eq(
34+
suggestion.changeset["replace"]&.join(" ")&.strip
35+
)
36+
end
37+
38+
describe "author" do
39+
let(:component) { create(:collaborative_text_component) }
40+
let(:document) { create(:collaborative_text_document, component:) }
41+
let(:version) { create(:collaborative_text_version, document:) }
42+
let(:author) { create(:user, :confirmed, name: "Jane Doe", organization: component.organization) }
43+
let(:suggestion) { create(:collaborative_text_suggestion, document_version: version, author:) }
44+
45+
it "serializes the author name" do
46+
expect(serialized[:author]).to include(name: "Jane Doe")
47+
end
48+
49+
it "serializes the author email" do
50+
expect(serialized[:author]).to include(email: author.email)
51+
end
52+
end
53+
54+
it "serializes created_at" do
55+
expect(serialized).to include(created_at: suggestion.created_at)
56+
end
57+
58+
it "serializes updated_at" do
59+
expect(serialized).to include(updated_at: suggestion.updated_at)
60+
end
61+
end
62+
end
63+
end
64+
end

decidim-collaborative_texts/spec/system/admin/admin_edits_document_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@
8888
expect(document.body).not_to eq("<p>body edited</p>")
8989
end
9090

91+
it "shows the export dropdown button" do
92+
within("tr", text: "This is my document new title") do
93+
find("button[data-controller='dropdown']").click
94+
click_on "Edit"
95+
end
96+
97+
expect(page).to have_button(I18n.t("decidim.admin.actions.export_all"))
98+
end
99+
91100
it "can discard suggestions by creating a new version" do
92101
expect(document.current_version.suggestions.count).to eq(1)
93102
within("tr", text: "This is my document new title") do

0 commit comments

Comments
 (0)