Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include external authors in proposals import process #498

Merged
merged 20 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8a44468
Include external authors in proposals import process
ivan-mr Nov 8, 2024
2e7fe26
Manage methods in external_author presenter
ivan-mr Nov 13, 2024
7e34ee5
Rubocop checks
ivan-mr Nov 13, 2024
0d7bbcd
Merge branch 'upgrade/0.28' into feat/import_authors_proposals
ivan-mr Nov 13, 2024
39c43a4
Add factory and rspecs for external_authors and test for process meth…
ivan-mr Nov 13, 2024
9be4c8a
Merge branch 'upgrade/0.28' into feat/import_authors_proposals
ivan-mr Nov 18, 2024
687b8d7
Merge branch 'upgrade/0.28' into feat/import_authors_proposals
ivan-mr Nov 19, 2024
3bb0d25
Changes in assets csv test files to pass csv parser
ivan-mr Nov 19, 2024
4aa3b1f
Add instructions on admin import proposals text to manage author names
ivan-mr Nov 19, 2024
ff160df
Modifying label for external_author/name
ivan-mr Nov 19, 2024
49197d5
Merge branch 'upgrade/0.28' into feat/import_authors_proposal
ivan-mr Nov 19, 2024
c46e989
Fix index name for external_authors table
ivan-mr Nov 19, 2024
2fa089c
Merge branch 'upgrade/0.28' into feat/import_authors_proposals
ivan-mr Nov 20, 2024
8ee2370
Merge branch 'upgrade/0.28' into feat/import_authors_proposals
ivan-mr Nov 21, 2024
7ac88ed
Add meeting_url field on import proposal
ivan-mr Nov 21, 2024
2bee32f
Merge branch 'upgrade/0.28' into feat/import_authors_proposals
ivan-mr Nov 26, 2024
7d27148
Modifications from PR review
ivan-mr Nov 26, 2024
a30c91c
Merge branch 'upgrade/0.28' into feat/import_authors_proposals
ivan-mr Nov 27, 2024
1c2ec9d
Merge branch 'master' into feat/import_authors_proposals
ivan-mr Jan 30, 2025
b0e04db
Force concurrent-ruby v.1.3.4 to Gemfile
ivan-mr Jan 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source "https://rubygems.org"
ruby RUBY_VERSION
DECIDIM_VERSION = { git: "https://github.com/CodiTramuntana/decidim", branch: "release/0.28-stable_decidim_templates" }.freeze

gem "concurrent-ruby", "1.3.4"
gem "decidim", DECIDIM_VERSION
gem "decidim-templates", DECIDIM_VERSION

Expand Down
30 changes: 16 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ GEM
activesupport (>= 2)
nokogiri (>= 1.4)
htmlentities (4.3.4)
i18n (1.14.6)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
i18n-tasks (1.0.14)
activesupport (>= 4.0.2)
Expand Down Expand Up @@ -536,9 +536,10 @@ GEM
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
launchy (3.0.1)
launchy (3.1.0)
addressable (~> 2.8)
childprocess (~> 5.0)
logger (~> 1.6)
letter_opener (1.10.0)
launchy (>= 2.2, < 4)
letter_opener_web (3.0.0)
Expand All @@ -549,7 +550,7 @@ GEM
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.4)
logger (1.6.5)
loofah (2.24.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand Down Expand Up @@ -608,8 +609,8 @@ GEM
rack-protection
omniauth-facebook (5.0.0)
omniauth-oauth2 (~> 1.2)
omniauth-google-oauth2 (1.2.0)
jwt (>= 2.9)
omniauth-google-oauth2 (1.2.1)
jwt (>= 2.9.2)
oauth2 (~> 2.0)
omniauth (~> 2.0)
omniauth-oauth2 (~> 1.8)
Expand All @@ -636,9 +637,9 @@ GEM
activerecord (>= 5.2)
request_store (~> 1.1)
parallel (1.26.3)
parallel_tests (4.8.0)
parallel_tests (4.9.0)
parallel
parser (3.3.6.0)
parser (3.3.7.0)
ast (~> 2.4.1)
racc
pg (1.4.6)
Expand All @@ -657,7 +658,7 @@ GEM
psych (4.0.6)
stringio
public_suffix (6.0.1)
puma (6.5.0)
puma (6.6.0)
nio4r (~> 2.0)
racc (1.8.1)
rack (2.2.10)
Expand Down Expand Up @@ -716,7 +717,7 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
recaptcha (5.18.0)
recaptcha (5.19.0)
redcarpet (3.6.0)
redis (4.8.1)
regexp_parser (2.10.0)
Expand Down Expand Up @@ -769,7 +770,7 @@ GEM
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.37.0)
rubocop-ast (1.38.0)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
Expand Down Expand Up @@ -800,7 +801,7 @@ GEM
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
selenium-webdriver (4.27.0)
selenium-webdriver (4.28.0)
base64 (~> 0.2)
logger (~> 1.4)
rexml (~> 3.2, >= 3.2.5)
Expand Down Expand Up @@ -845,10 +846,10 @@ GEM
sys-uname (1.0.4)
ffi (>= 1.0.0)
temple (0.10.3)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
terminal-table (4.0.0)
unicode-display_width (>= 1.1.1, < 4)
thor (1.3.2)
tilt (2.5.0)
tilt (2.6.0)
timeout (0.4.3)
trailblazer-option (0.1.2)
tzinfo (2.0.6)
Expand Down Expand Up @@ -908,6 +909,7 @@ DEPENDENCIES
bootsnap
byebug
capybara-screenshot
concurrent-ruby (= 1.3.4)
daemons
database_cleaner
decidim!
Expand Down
38 changes: 38 additions & 0 deletions app/decorators/decidim/coauthorable_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

module Decidim::CoauthorableDecorator
def add_external_author(external_author_name, organization)
external_author = Decidim::ExternalAuthor.find_or_create_by(name: external_author_name, organization: organization)

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

generate_coauthorship(external_author)

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)

generate_coauthorship(location)

authors << location
end

private

def generate_coauthorship(new_author)
coauthorship_attributes = { author: new_author }
if persisted?
coauthorships.create!(coauthorship_attributes)
else
coauthorships.build(coauthorship_attributes)
end
end
end

::Decidim::Coauthorable.prepend ::Decidim::CoauthorableDecorator
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ def finish_without_notif!
end
resource
end

def produce
laurajaime marked this conversation as resolved.
Show resolved Hide resolved
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
end
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions app/models/decidim/external_author.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Decidim
class ExternalAuthor < ApplicationRecord
include Decidim::ActsAsAuthor
include Decidim::Followable

belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization"

validates :name, presence: true, uniqueness: { scope: :organization }

def presenter
Decidim::ExternalAuthorPresenter.new(self)
end
end
end
27 changes: 27 additions & 0 deletions app/presenters/decidim/external_author_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Decidim
class ExternalAuthorPresenter < SimpleDelegator
include ActionView::Helpers::UrlHelper

delegate :name, to: :__getobj__

def avatar_url(_something)
ActionController::Base.helpers.asset_pack_path("media/images/default-avatar.svg")
end

def respond_to_missing?(*)
true
end

def method_missing(method, *args)
if method.to_s.ends_with?("?")
false
elsif [:profile_path, :badge, :followers, :followers_count, :cache_key_with_version].include?(method)
""
else
super
end
end
end
end
14 changes: 14 additions & 0 deletions config/locales/ca_proposals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,22 @@ ca:
application_helper:
filter_type_values:
amendments: Esmenes
admin:
imports:
help:
proposals: |
El document ha d'incloure els següents noms de columna en cas d'arxius CSV o Excel o noms de claus en el cas d'arxius JSON:
<ul>
<li><b>title/ca:</b> Títol en català. Això dependrà de la configuració d'idioma predeterminat a la teva plataforma.</li>
<li><b>body/ca:</b> Descripció en català. Això dependrà de la configuració d'idioma predeterminat a la teva plataforma.</li>
<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:
amendment_type: Tipus
show:
proposal_in_evaluation_reason: 'Aquesta proposta està en avaluació perquè:'

13 changes: 13 additions & 0 deletions config/locales/en_proposals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ en:
email_outro: You have received this notification because you are following "%{participatory_space_title}". You can unfollow it from the previous link.
email_subject: New proposals added to %{participatory_space_title}
proposals:
admin:
imports:
help:
proposals: |
The file must have the following column names in case of CSV or Excel files, or key names in case of JSON files:
<ul>
<li><b>title/en:</b> Title on English language. This will depend on your platform language configuration.</li>
<li><b>body/en:</b> Body on English language. This will depend on your platform language configuration.</li>
<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:
proposal_in_evaluation_reason: 'This proposal is under evaluation because:'
13 changes: 13 additions & 0 deletions config/locales/es_proposals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ es:
email_outro: Has recibido esta notificación porque estas siguiendo el espacio "%{participatory_space_title}". Puedes dejar de recibir notificaciones siguiendo el enlace anterior.
email_subject: Nuevas propuestas añadidas a %{participatory_space_title}
proposals:
admin:
imports:
help:
proposals: |
El documento de importación debe contener los siguientes nombres de columna en caso de archivos CSV o Excel o nombres de claves en caso de archivos JSON:
<ul>
<li><b>title/es:</b> Título en castellano. Esto dependerá de la configuración de idioma predeterminado de tu plataforma.</li>
<li><b>body/en:</b> Descripción en castellano. Esto dependerá de la configuración de idioma predeterminado de tu plataforma.</li>
<li><b>scope/id:</b> ID del ámbito</li>
<li><b>category/id:</b> ID de la Categoría</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:
proposal_in_evaluation_reason: 'Esta propuesta está en evaluación porque:'
12 changes: 12 additions & 0 deletions config/locales/oc_proposals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,18 @@ oc:
exports:
comments: Comentaris
proposals: Propostes
imports:
help:
proposals: |
Eth document li cau includir es següents nòms de colomna en cas d'archius CSV o Excel o nòms de claus en cas d'archius JSON:
<ul>
<li><b>title/ca:</b> Títol en catalan. Açò depenerà dera configuracion d'idiòma predeterminat ara tua plataforma.</li>
<li><b>body/ca:</b> Descripcion en catalan. Açò depenerà dera configuracion d'idiòma predeterminat ara tua plataforma.</li>
<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:
name: Proposta
Expand Down
19 changes: 19 additions & 0 deletions db/migrate/20241105163000_create_decidim_external_authors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true
# This migration comes from decidim (originally 20220629194812)

class CreateDecidimExternalAuthors < ActiveRecord::Migration[6.1]
def change
create_table :decidim_external_authors do |t|
t.string :name, null: false
t.integer :decidim_organization_id, index: true, foreign_key: true

t.timestamps

t.index [:decidim_organization_id, :name],
name: "index_unique_name_and_organization",
unique: true
end

add_index :decidim_external_authors, :name, unique: true
end
end
12 changes: 12 additions & 0 deletions lib/decidim/core/test/gencat_factories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

FactoryBot.define do
factory :external_author, class: "Decidim::ExternalAuthor" do
transient do
skip_injection { false }
end

name { generate(:name) }
organization
end
end
Loading
Loading