Skip to content

Commit

Permalink
Add meeting_url field on import proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mr committed Nov 21, 2024
1 parent 8ee2370 commit 7ac88ed
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 4 deletions.
18 changes: 18 additions & 0 deletions app/decorators/decidim/coauthorable_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ def add_external_author(external_author_name, organization)

authors << external_author
end

def add_location(meeting_url)
segment_id = meeting_url.split("/").last.to_i

location = Decidim::Meetings::Meeting.find(segment_id)

return if coauthorships.exists?(decidim_author_id: location.id, decidim_author_type: location.class.base_class.name)

coauthorship_attributes = { author: location }

if persisted?
coauthorships.create!(coauthorship_attributes)
else
coauthorships.build(coauthorship_attributes)
end

authors << location
end
end

::Decidim::Coauthorable.prepend ::Decidim::CoauthorableDecorator
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ def finish_without_notif!
end

def produce
resource.add_coauthor(context[:current_user], user_group: context[:user_group]) unless data.dig(:external_author,
"name").present? || data[:"external_author/name"].present?

if data.dig(:external_author, "name").present? || data[:"external_author/name"].present?
if data[:meeting_url].present?
resource.add_location(data[:meeting_url])
elsif data.dig(:external_author, "name").present? || data[:"external_author/name"].present?
resource.add_external_author((data.dig(:external_author, "name") || data[:'external_author/name']),
context[:current_organization])
else
resource.add_coauthor(context[:current_user], user_group: context[:user_group])
end

resource
Expand Down
1 change: 1 addition & 0 deletions config/locales/ca_proposals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ca:
<li><b>scope/id:</b> ID de l'Àmbit</li>
<li><b>category/id:</b> ID de la Categoria</li>
<li><b>external_author/name:</b> Nom de l'autor de la proposta extern a la plataforma Decidim</li>
<li><b>meeting_url:</b> Url de la trobada a la plataforma Decidim</li>
</ul>
proposals:
filters:
Expand Down
1 change: 1 addition & 0 deletions config/locales/en_proposals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ en:
<li><b>scope/id:</b> ID for the Scope</li>
<li><b>category/id:</b> ID for the Category</li>
<li><b>external_author/name:</b> Proposal author name outside of the Decidim platform</li>
<li><b>meeting_url:</b> Meeting url on the Decidim platform</li>
</ul>
proposals:
show:
Expand Down
1 change: 1 addition & 0 deletions config/locales/es_proposals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ es:
<li><b>scope/id:</b> ID de l'Ámbito</li>
<li><b>category/id:</b> ID de la Categoria</li>
<li><b>external_author/name:</b> Nombre del autor de la propuesta externo a la plataforma Decidim</li>
<li><b>meeting_url:</b> Url del encuentro en la plataforma Decidim</li>
</ul>
proposals:
show:
Expand Down
1 change: 1 addition & 0 deletions config/locales/oc_proposals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ oc:
<li><b>scope/id:</b> ID der encastre</li>
<li><b>category/id:</b> ID dera Categoria</li>
<li><b>external_author/name:</b> Nòm der autor dera prepausa extèrna ara plataforma Decidim</li>
<li><b>meeting_url:</b> Url dera trobada ara plataforma Decidim</li>
</ul>
models:
proposal:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
end
let(:organization) { create(:organization, available_locales: [:en]) }
let(:user) { create(:user, organization: organization) }
let(:meeting) { create(:meeting) }
let(:context) do
{
current_organization: organization,
Expand Down Expand Up @@ -71,4 +72,37 @@
expect(record.coauthorships.first.author.name).to eq(data["external_author/name".to_sym])
end
end

describe "#produce with meeting_url" do
let(:data) do
{
id: 1337,
category: category,
scope: scope,
"title/en": Faker::Lorem.sentence,
"body/en": Faker::Lorem.paragraph(sentence_count: 3),
address: "#{Faker::Address.street_name}, #{Faker::Address.city}",
latitude: Faker::Address.latitude,
longitude: Faker::Address.longitude,
component: component,
published_at: moment,
"meeting_url": "url_meeting/#{meeting.id}"
}
end

it "makes a new proposal with location" do
record = subject.produce

expect(record).to be_a(Decidim::Proposals::Proposal)
expect(record.category).to eq(category)
expect(record.scope).to eq(scope)
expect(record.title["en"]).to eq(data[:"title/en"])
expect(record.body["en"]).to eq(data[:"body/en"])
expect(record.address).to eq(data[:address])
expect(record.latitude).to eq(data[:latitude])
expect(record.longitude).to eq(data[:longitude])
expect(record.published_at).to be >= (moment)
expect(record.coauthorships.first.author.id).to eq(meeting.id)
end
end
end

0 comments on commit 7ac88ed

Please sign in to comment.