decidim-proposals 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/app/commands/decidim/proposals/unvote_proposal.rb +34 -0
  3. data/app/commands/decidim/proposals/vote_proposal.rb +39 -0
  4. data/app/controllers/concerns/decidim/proposals/orderable.rb +7 -3
  5. data/app/controllers/decidim/proposals/proposal_votes_controller.rb +18 -8
  6. data/app/models/decidim/proposals/proposal.rb +3 -3
  7. data/app/models/decidim/proposals/proposal_vote.rb +0 -1
  8. data/app/views/decidim/proposals/proposals/_author.html.erb +23 -0
  9. data/app/views/decidim/proposals/proposals/_linked_proposals.html.erb +2 -2
  10. data/app/views/decidim/proposals/proposals/_proposal.html.erb +1 -9
  11. data/app/views/decidim/proposals/proposals/_vote_button.html.erb +2 -6
  12. data/app/views/decidim/proposals/proposals/new.html.erb +1 -1
  13. data/app/views/decidim/proposals/proposals/show.html.erb +1 -11
  14. data/config/locales/ca.yml +6 -0
  15. data/config/locales/en.yml +6 -0
  16. data/config/locales/es.yml +6 -0
  17. data/config/locales/eu.yml +0 -2
  18. data/config/locales/fi.yml +0 -2
  19. data/config/locales/fr.yml +0 -2
  20. data/config/locales/it.yml +147 -0
  21. data/db/migrate/20161212110850_create_decidim_proposals.rb +2 -0
  22. data/db/migrate/20170112115253_create_proposal_votes.rb +3 -1
  23. data/db/migrate/20170113114245_add_text_search_indexes.rb +2 -0
  24. data/db/migrate/20170118120151_add_counter_cache_votes_to_proposals.rb +2 -0
  25. data/db/migrate/20170120151202_add_user_group_id_to_proposals.rb +2 -0
  26. data/db/migrate/20170131092413_add_answers_to_proposals.rb +2 -0
  27. data/db/migrate/20170205082832_add_index_to_decidim_proposals_proposals_proposal_votes_count.rb +2 -0
  28. data/db/migrate/20170215113152_create_proposal_reports.rb +2 -0
  29. data/db/migrate/20170215131720_add_report_count_to_proposals.rb +2 -0
  30. data/db/migrate/20170215132030_add_reference_to_proposals.rb +2 -0
  31. data/db/migrate/20170220152416_add_hidden_at_to_proposals.rb +2 -0
  32. data/db/migrate/20170228105156_add_geolocalization_fields_to_proposals.rb +2 -0
  33. data/db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb +8 -10
  34. data/db/migrate/20170410073742_remove_not_null_reference_proposals.rb +2 -0
  35. data/db/migrate/20170612101809_migrate_proposals_category.rb +15 -0
  36. data/lib/decidim/proposals/feature.rb +5 -1
  37. data/lib/decidim/proposals/proposal_serializer.rb +1 -6
  38. metadata +19 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 656619a854b4e23c556abee9a2641287a8b0b9e4
4
- data.tar.gz: fe25ef91ada0e02ce0c8a41b4155843b70de8049
3
+ metadata.gz: 4862d42b8a29f90463ba8384ac679cabdf2c3cd7
4
+ data.tar.gz: c29a9302b9eb23d34fd9d28ae7f2eef891b89f7d
5
5
  SHA512:
6
- metadata.gz: efdb25720d97e47ce218640b118012b790755a30c13b8e1193a017e53763c8c261f5af140355c5a44864c1cf2b68dfe9ed8dc16e361e4409bea88cbc3a7d583a
7
- data.tar.gz: 5b72de0eb3baba3c6430706cf7157ae7cdb459d3a2955af0fd5678dc42b58ca1a5ebc9b38e8b5a727473cd5300b3d4315704844fc12ce5de8221c8fabed46478
6
+ metadata.gz: 96bf31e33f24cb569e111789bbcd6d88a605f61b9ceaf050cc45f12e9af5595d967ccf66b97d62930b1a739c2bbea3b2de207db0e72ba437fb2a2b10e0cf652f
7
+ data.tar.gz: 96917d9a39b9b26301669f5b41583b1a884e02f63321552903bf62e6ffab32932da765e966bd678dfea1c41ccbc8840c49a6d4a2b71016b45fa8519a364d8ea2
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ # A command with all the business logic when a user unvotes a proposal.
6
+ class UnvoteProposal < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # proposal - A Decidim::Proposals::Proposal object.
10
+ # current_user - The current user.
11
+ def initialize(proposal, current_user)
12
+ @proposal = proposal
13
+ @current_user = current_user
14
+ end
15
+
16
+ # Executes the command. Broadcasts these events:
17
+ #
18
+ # - :ok when everything is valid, together with the proposal.
19
+ # - :invalid if the form wasn't valid and we couldn't proceed.
20
+ #
21
+ # Returns nothing.
22
+ def call
23
+ destroy_proposal_vote
24
+ broadcast(:ok, @proposal)
25
+ end
26
+
27
+ private
28
+
29
+ def destroy_proposal_vote
30
+ @proposal.votes.where(author: @current_user).destroy_all
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ # A command with all the business logic when a user votes a proposal.
6
+ class VoteProposal < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # proposal - A Decidim::Proposals::Proposal object.
10
+ # current_user - The current user.
11
+ def initialize(proposal, current_user)
12
+ @proposal = proposal
13
+ @current_user = current_user
14
+ end
15
+
16
+ # Executes the command. Broadcasts these events:
17
+ #
18
+ # - :ok when everything is valid, together with the proposal vote.
19
+ # - :invalid if the form wasn't valid and we couldn't proceed.
20
+ #
21
+ # Returns nothing.
22
+ def call
23
+ build_proposal_vote
24
+ return broadcast(:invalid) unless vote.valid?
25
+
26
+ vote.save!
27
+ broadcast(:ok, vote)
28
+ end
29
+
30
+ attr_reader :vote
31
+
32
+ private
33
+
34
+ def build_proposal_vote
35
+ @vote = @proposal.votes.build(author: @current_user)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -22,23 +22,27 @@ module Decidim
22
22
  def available_orders
23
23
  @available_orders ||= begin
24
24
  available_orders = %w(random recent)
25
- available_orders << "most_voted" if votes_visible?
25
+ available_orders << "most_voted" if most_voted_order_available?
26
26
  available_orders
27
27
  end
28
28
  end
29
29
 
30
30
  def default_order
31
- if current_settings.votes_blocked?
31
+ if order_by_votes?
32
32
  detect_order("most_voted")
33
33
  else
34
34
  "random"
35
35
  end
36
36
  end
37
37
 
38
- def votes_visible?
38
+ def most_voted_order_available?
39
39
  current_settings.votes_enabled? && !current_settings.votes_hidden?
40
40
  end
41
41
 
42
+ def order_by_votes?
43
+ most_voted_order_available? && current_settings.votes_blocked?
44
+ end
45
+
42
46
  # Returns: A random float number between -1 and 1 to be used as a random seed at the database.
43
47
  def random_seed
44
48
  @random_seed ||= (params[:random_seed] ? params[:random_seed].to_f : (rand * 2 - 1))
@@ -12,20 +12,30 @@ module Decidim
12
12
 
13
13
  def create
14
14
  authorize! :vote, proposal
15
-
16
- proposal.votes.create!(author: current_user)
17
15
  @from_proposals_list = params[:from_proposals_list] == "true"
18
- render :update_buttons_and_counters
16
+
17
+ VoteProposal.call(proposal, current_user) do
18
+ on(:ok) do
19
+ proposal.reload
20
+ render :update_buttons_and_counters
21
+ end
22
+
23
+ on(:invalid) do
24
+ render json: { error: I18n.t("proposal_votes.create.error", scope: "decidim.proposals") }, status: 422
25
+ end
26
+ end
19
27
  end
20
28
 
21
29
  def destroy
22
30
  authorize! :unvote, proposal
23
-
24
- proposal.votes.where(author: current_user).destroy_all
25
- proposal.reload
26
-
27
31
  @from_proposals_list = params[:from_proposals_list] == "true"
28
- render :update_buttons_and_counters
32
+
33
+ UnvoteProposal.call(proposal, current_user) do
34
+ on(:ok) do
35
+ proposal.reload
36
+ render :update_buttons_and_counters
37
+ end
38
+ end
29
39
  end
30
40
 
31
41
  private
@@ -87,9 +87,9 @@ module Decidim
87
87
  true
88
88
  end
89
89
 
90
- # Public: Overrides the `reported_content` Reportable concern method.
91
- def reported_content
92
- "<h3>#{title}</h3><p>#{body}</p>"
90
+ # Public: Overrides the `reported_content_url` Reportable concern method.
91
+ def reported_content_url
92
+ ResourceLocatorPresenter.new(self).url
93
93
  end
94
94
  end
95
95
  end
@@ -7,7 +7,6 @@ module Decidim
7
7
  belongs_to :proposal, foreign_key: "decidim_proposal_id", class_name: "Decidim::Proposals::Proposal", counter_cache: true
8
8
  belongs_to :author, foreign_key: "decidim_author_id", class_name: "Decidim::User"
9
9
 
10
- validates :proposal, :author, presence: true
11
10
  validates :proposal, uniqueness: { scope: :author }
12
11
  validate :author_and_proposal_same_organization
13
12
 
@@ -0,0 +1,23 @@
1
+ <div class="author-data__main">
2
+ <div class="author author--inline">
3
+ <span class="author__avatar author__avatar--small">
4
+ <%= image_tag proposal.author_avatar_url %>
5
+ </span>
6
+ <span class="author__name">
7
+ <% if proposal.author&.deleted? %>
8
+ <span class="label label--small label--basic">
9
+ <%= t('.deleted') %>
10
+ </span>
11
+ <% else %>
12
+ <%= proposal.author_name %>
13
+ <% end %>
14
+ </span>
15
+ <% if proposal.user_group && proposal.user_group.verified? %>
16
+ &nbsp;
17
+ <span class="label label--highlight label--small">
18
+ <%= t ".verified_user_group" %>
19
+ </span>
20
+ <% end %>
21
+ <%= l proposal.created_at, format: "%d/%m/%Y" %>
22
+ </div>
23
+ </div>
@@ -2,11 +2,11 @@
2
2
  <% resources.each do |proposal| %>
3
3
  <div class="card--list__item">
4
4
  <div class="card--list__text">
5
- <%= link_to decidim_resource_path(proposal) do %>
5
+ <%= link_to resource_locator(proposal).path do %>
6
6
  <%= icon "proposals", class: "card--list__icon", remove_icon_class: true %>
7
7
  <% end %>
8
8
  <div>
9
- <%= link_to decidim_resource_path(proposal), class: "card__link" do %>
9
+ <%= link_to resource_locator(proposal).path, class: "card__link" do %>
10
10
  <h5 class="card--list__heading"><%= proposal.title %></h5>
11
11
  <% end %>
12
12
  <div class="author">
@@ -6,15 +6,7 @@
6
6
  <h5 class="card__title"><%= proposal.title %></h5>
7
7
  <% end %>
8
8
  <div class="card__author author-data author-data--small">
9
- <div class="author-data__main">
10
- <div class="author author--inline">
11
- <span class="author__avatar author__avatar--small">
12
- <%= image_tag proposal.author_avatar_url %>
13
- </span>
14
- <span class="author__name"><%= proposal.author_name %></span>
15
- <%= l proposal.created_at, format: "%d/%m/%Y" %>
16
- </div>
17
- </div>
9
+ <%= render partial: "author", locals: { proposal: proposal } %>
18
10
  </div>
19
11
  </div>
20
12
  <%= render partial: "proposal_badge", locals: { proposal: proposal } %>
@@ -1,13 +1,9 @@
1
1
  <div id="proposal-<%= proposal.id %>-vote-button">
2
2
  <% if !current_user %>
3
3
  <% if current_settings.votes_blocked? %>
4
- <button class="card__button button <%= vote_button_classes(from_proposals_list) %> disabled" disabled data-toggle="loginModal">
5
- <%= t('.votes_blocked') %>
6
- </button>
4
+ <%= action_authorized_button_to :vote, t('.votes_blocked'), proposal_proposal_vote_path(proposal_id: proposal, from_proposals_list: from_proposals_list), class: "card__button button #{vote_button_classes(from_proposals_list)} disabled", disabled: true %>
7
5
  <% else %>
8
- <button class="card__button button <%= vote_button_classes(from_proposals_list) %>" data-toggle="loginModal">
9
- <%= t('.vote') %>
10
- </button>
6
+ <%= action_authorized_button_to :vote, t('.vote'), proposal_proposal_vote_path(proposal_id: proposal, from_proposals_list: from_proposals_list), class: "card__button button #{vote_button_classes(from_proposals_list)}" %>
11
7
  <% end %>
12
8
  <% else %>
13
9
  <% if @voted_proposals ? @voted_proposals.include?(proposal.id) : proposal.voted_by?(current_user) %>
@@ -43,7 +43,7 @@
43
43
  <% end %>
44
44
 
45
45
  <div class="actions">
46
- <%= form.submit t(".send"), class: "button expanded" %>
46
+ <%= form.submit t(".send"), class: "button expanded", "data-disable-with" => "#{t('.send')}..." %>
47
47
  </div>
48
48
  <% end %>
49
49
  </div>
@@ -8,17 +8,7 @@
8
8
  <div class="row column view-header">
9
9
  <h2 class="heading2"><%= @proposal.title %></h2>
10
10
  <div class="author-data">
11
- <div class="author-data__main">
12
- <div class="author author--inline">
13
- <span class="author__avatar">
14
- <%= image_tag @proposal.author_avatar_url %>
15
- </span>
16
- <%= l @proposal.created_at, format: :long %>
17
- <span class="author__name">
18
- <%= @proposal.author_name %>
19
- </span>
20
- </div>
21
- </div>
11
+ <%= render partial: "author", locals: { proposal: @proposal } %>
22
12
  <div class="author-data__extra">
23
13
  <button type="button" data-open="<%= current_user.present? ? 'flagModal' : 'loginModal' %>" title="<%= t('.report') %>" aria-controls="<%= current_user.present? ? 'flagModal' : 'loginModal' %>" aria-haspopup="true" tabindex="0">
24
14
  <%= icon "flag", aria_label: t('.report'), class: 'icon--small' %>
@@ -79,7 +79,13 @@ ca:
79
79
  scope: Àmbit
80
80
  state: Estat
81
81
  title: Títol
82
+ proposal_votes:
83
+ create:
84
+ error: Hi ha hagut errors en votar la proposta.
82
85
  proposals:
86
+ author:
87
+ deleted: Usuari eliminat
88
+ verified_user_group: Organització verificada
83
89
  count:
84
90
  proposals_count:
85
91
  one: 1 proposta
@@ -81,7 +81,13 @@ en:
81
81
  scope: Scope
82
82
  state: State
83
83
  title: Title
84
+ proposal_votes:
85
+ create:
86
+ error: There's been errors when voting the proposal.
84
87
  proposals:
88
+ author:
89
+ deleted: Deleted user
90
+ verified_user_group: Verified organization
85
91
  count:
86
92
  proposals_count:
87
93
  one: 1 proposal
@@ -79,7 +79,13 @@ es:
79
79
  scope: Ámbito
80
80
  state: Estado
81
81
  title: Título
82
+ proposal_votes:
83
+ create:
84
+ error: Ha habido errores al votar la propuesta.
82
85
  proposals:
86
+ author:
87
+ deleted: Usuario eliminado
88
+ verified_user_group: Organización verificada
83
89
  count:
84
90
  proposals_count:
85
91
  one: 1 propuesta
@@ -121,8 +121,6 @@ eu:
121
121
  most_voted: Bozkatuenak
122
122
  random: Ausazkoa eran
123
123
  recent: Berrienak
124
- proposal:
125
- view_proposal: Ikusi proposamena
126
124
  show:
127
125
  proposal_accepted_reason: 'Proposamen hau onartu da arrazoi hauengatik:'
128
126
  proposal_rejected_reason: 'Proposamen hau baztertu da arrazoi hauengatik:'
@@ -108,8 +108,6 @@ fi:
108
108
  most_voted: Eniten ääniä saaneet
109
109
  random: Satunnainen
110
110
  recent: Viimeisimmät
111
- proposal:
112
- view_proposal: Näytä ehdotus
113
111
  show:
114
112
  proposal_accepted_reason: 'Tämä ehdotus on hyväksytty, koska:'
115
113
  proposal_rejected_reason: 'Tämä ehdotus on hylätty, koska:'
@@ -118,8 +118,6 @@ fr:
118
118
  most_voted: Les plus votées
119
119
  random: Aléatoire
120
120
  recent: Les plus récents
121
- proposal:
122
- view_proposal: Voir la proposition
123
121
  show:
124
122
  proposal_accepted_reason: 'Cette proposition a été acceptée parce que :'
125
123
  proposal_rejected_reason: 'Cette proposition a été refusée parce que:'
@@ -0,0 +1,147 @@
1
+ it:
2
+ activemodel:
3
+ attributes:
4
+ proposal:
5
+ body: Corpo del testo
6
+ category_id: Categoria
7
+ scope_id: Visibilità
8
+ title: Titolo
9
+ user_group_id: Crea proposta come
10
+ proposal_answer:
11
+ answer: Risposta
12
+ decidim:
13
+ features:
14
+ proposals:
15
+ actions:
16
+ create: Crea
17
+ vote: Vota
18
+ name: Proposte
19
+ settings:
20
+ global:
21
+ comments_enabled: Commenti abilitati
22
+ geocoding_enabled: Geocoding abilitato
23
+ official_proposals_enabled: Proposte ufficiali abilitate
24
+ proposal_answering_enabled: Risposta Proposte abilitata
25
+ vote_limit: Numero max di proposte votabili
26
+ step:
27
+ comments_blocked: Commenti bloccati
28
+ creation_enabled: Creazione delle Proposte abilitata
29
+ proposal_answering_enabled: Risposta Proposte abilitata
30
+ votes_blocked: Votazioni bloccate
31
+ votes_enabled: Votazioni abilitate
32
+ votes_hidden: Voti nascosti (se i voti sono abilitati, spuntando questa casella verrà nascosto il numero dei voti)
33
+ proposals:
34
+ actions:
35
+ answer: Risposta
36
+ new: Nuovo
37
+ title: Azioni
38
+ admin:
39
+ actions:
40
+ preview: Anteprima
41
+ exports:
42
+ proposals: Proposte
43
+ models:
44
+ proposal:
45
+ name: Proposta
46
+ proposal_answers:
47
+ edit:
48
+ accepted: Accettata
49
+ answer_proposal: Risposta
50
+ rejected: Rifiutata
51
+ title: Risposta per la proposta %{title}
52
+ proposals:
53
+ answer:
54
+ invalid: E' stato riscontrato un problema nella risposta per questa proposta
55
+ success: OK, risposta per la proposta registrata.
56
+ create:
57
+ invalid: Sono stati riscontrati dei problemi durante la creazione di questa proposta
58
+ success: OK, proposta creata.
59
+ form:
60
+ select_a_category: Scegli una categoria
61
+ index:
62
+ title: Proposte
63
+ new:
64
+ create: Crea
65
+ title: Crea una proposta
66
+ answers:
67
+ accepted: Accettata
68
+ not_answered: Non risposto
69
+ rejected: Rifiutata
70
+ create:
71
+ error: C'è stato un errore durante il salvataggio di questa proposta.
72
+ success: OK, la proposta è stata creata.
73
+ models:
74
+ proposal:
75
+ fields:
76
+ category: Categoria
77
+ official_proposal: Proposta ufficiale
78
+ scope: Visibilità
79
+ state: Stato
80
+ title: Titolo
81
+ proposals:
82
+ count:
83
+ proposals_count:
84
+ one: 1 proposta
85
+ other: "%{count} proposte"
86
+ filters:
87
+ accepted: Accettata
88
+ activity: Attività
89
+ category: Categoria
90
+ category_prompt: Scegli una categoria
91
+ citizenship: Cittadinanza
92
+ official: Ufficiale
93
+ origin: Origine
94
+ rejected: Rifiutata
95
+ related_to: Associata a
96
+ scopes: Visibilità
97
+ search: Cerca
98
+ state: Stato
99
+ voted: Votata
100
+ filters_small_view:
101
+ close_modal: Chiudi modalità
102
+ filter: Filtra
103
+ filter_by: Filtra per
104
+ unfold: Espandi
105
+ index:
106
+ new_proposal: Nuova proposta
107
+ view_proposal: Visualizza proposta
108
+ linked_proposals:
109
+ proposal_votes:
110
+ one: <span class="card--list__data__number">1</span>voto
111
+ other: <span class="card--list__data__number">%{count}</span>voti
112
+ new:
113
+ back: Indietro
114
+ select_a_category: Scegli una categoria
115
+ send: Invia
116
+ title: Nuova proposta
117
+ orders:
118
+ label: 'Ordina le proposte per:'
119
+ most_voted: Più votate
120
+ random: A caso
121
+ recent: le più recenti
122
+ proposal:
123
+ view_proposal: Visualizza la proposta
124
+ show:
125
+ proposal_accepted_reason: 'Questa proposta è stata accettata perché:'
126
+ proposal_rejected_reason: 'Questa proposta è stata rifiutata perché:'
127
+ vote_button:
128
+ already_voted: Già votata
129
+ no_votes_remaining: Sono finite le votazioni possibili
130
+ vote: Vota
131
+ votes_blocked: Votazioni disabilitate
132
+ votes_count:
133
+ count:
134
+ one: VOTO
135
+ other: VOTI
136
+ votes_limit:
137
+ vote_limit:
138
+ description: Invece di votare tutte le proposte possibili puoi soltanto votare fino a %{limit} proposte.
139
+ left: Restano
140
+ title: Hai ancora %{limit} voti
141
+ votes: Voti
142
+ resource_links:
143
+ included_proposals:
144
+ proposal_projects: 'Le proposte compaiono nei seguenti progetti:'
145
+ proposal_results: 'Le proposte compaiono nei seguenti risultati:'
146
+ proposals_from_meeting:
147
+ proposal_meetings: Meeting associati alla proposta
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateDecidimProposals < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  create_table :decidim_proposals_proposals do |t|
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateProposalVotes < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  create_table :decidim_proposals_proposal_votes do |t|
4
6
  t.references :decidim_proposal, null: false, index: { name: "decidim_proposals_proposal_vote_proposal" }
5
7
  t.references :decidim_author, null: false, index: { name: "decidim_proposals_proposal_vote_author" }
6
-
8
+
7
9
  t.timestamps
8
10
  end
9
11
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddTextSearchIndexes < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  add_index :decidim_proposals_proposals, :title, name: "decidim_proposals_proposal_title_search"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddCounterCacheVotesToProposals < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  add_column :decidim_proposals_proposals, :proposal_votes_count, :integer, null: false, default: 0
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddUserGroupIdToProposals < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  add_column :decidim_proposals_proposals, :decidim_user_group_id, :integer, index: true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddAnswersToProposals < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  add_column :decidim_proposals_proposals, :state, :string, index: true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddIndexToDecidimProposalsProposalsProposalVotesCount < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  add_index :decidim_proposals_proposals, :proposal_votes_count
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateProposalReports < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  create_table :decidim_proposals_proposal_reports do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddReportCountToProposals < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  add_column :decidim_proposals_proposals, :report_count, :integer, default: 0
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddReferenceToProposals < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  add_column :decidim_proposals_proposals, :reference, :string
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddHiddenAtToProposals < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  add_column :decidim_proposals_proposals, :hidden_at, :datetime
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddGeolocalizationFieldsToProposals < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  add_column :decidim_proposals_proposals, :address, :text
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class MigrateProposalReportsDataToReports < ActiveRecord::Migration[5.0]
2
4
  class Decidim::Proposals::ProposalReport < ApplicationRecord
3
5
  belongs_to :user, foreign_key: "decidim_user_id", class_name: "Decidim::User"
@@ -6,16 +8,12 @@ class MigrateProposalReportsDataToReports < ActiveRecord::Migration[5.0]
6
8
 
7
9
  def change
8
10
  Decidim::Proposals::ProposalReport.all.each do |proposal_report|
9
- moderation = Decidim::Moderation.find_or_create_by!({
10
- reportable: proposal_report.proposal,
11
- participatory_process: proposal_report.proposal.feature.participatory_process
12
- })
13
- Decidim::Report.create!({
14
- moderation: moderation,
15
- user: proposal_report.user,
16
- reason: proposal_report.reason,
17
- details: proposal_report.details
18
- })
11
+ moderation = Decidim::Moderation.find_or_create_by!(reportable: proposal_report.proposal,
12
+ participatory_process: proposal_report.proposal.feature.participatory_process)
13
+ Decidim::Report.create!(moderation: moderation,
14
+ user: proposal_report.user,
15
+ reason: proposal_report.reason,
16
+ details: proposal_report.details)
19
17
  moderation.update_attributes!(report_count: moderation.report_count + 1)
20
18
  end
21
19
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class RemoveNotNullReferenceProposals < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  change_column_null :decidim_proposals_proposals, :reference, true
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MigrateProposalsCategory < ActiveRecord::Migration[5.1]
4
+ def change
5
+ # Create categorizations ensuring database integrity
6
+ execute('
7
+ INSERT INTO decidim_categorizations(decidim_category_id, categorizable_id, categorizable_type, created_at, updated_at)
8
+ SELECT decidim_category_id, decidim_proposals_proposals.id, \'Decidim::Proposals::Proposal\', NOW(), NOW()
9
+ FROM decidim_proposals_proposals
10
+ INNER JOIN decidim_categories ON decidim_categories.id = decidim_proposals_proposals.decidim_category_id
11
+ ')
12
+ # Remove unused column
13
+ remove_column :decidim_proposals_proposals, :decidim_category_id
14
+ end
15
+ end
@@ -92,13 +92,17 @@ Decidim.register_feature(:proposals) do |feature|
92
92
  scopes = feature.organization.scopes + [nil]
93
93
 
94
94
  20.times do |n|
95
+ author = Decidim::User.where(organization: feature.organization).all.sample
96
+ user_group = [true, false].sample ? author.user_groups.verified.sample : nil
97
+
95
98
  proposal = Decidim::Proposals::Proposal.create!(
96
99
  feature: feature,
97
100
  category: categories.sample,
98
101
  scope: scopes.sample,
99
102
  title: Faker::Lorem.sentence(2),
100
103
  body: Faker::Lorem.paragraphs(2).join("\n"),
101
- author: Decidim::User.where(organization: feature.organization).all.sample
104
+ author: author,
105
+ user_group: user_group
102
106
  )
103
107
 
104
108
  if n > 15
@@ -46,12 +46,7 @@ module Decidim
46
46
 
47
47
  def meetings
48
48
  @proposal.linked_resources(:meetings, "proposals_from_meeting").map do |meeting|
49
- decidim_resource_url(
50
- meeting,
51
- feature_id: feature,
52
- participatory_process_id: participatory_process,
53
- host: organization.host
54
- )
49
+ Decidim::ResourceLocatorPresenter.new(meeting).url
55
50
  end
56
51
  end
57
52
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-proposals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-06-02 00:00:00.000000000 Z
13
+ date: 2017-06-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: decidim-core
@@ -18,28 +18,28 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.2.0
21
+ version: 0.3.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 0.2.0
28
+ version: 0.3.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: decidim-comments
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - '='
34
34
  - !ruby/object:Gem::Version
35
- version: 0.2.0
35
+ version: 0.3.0
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - '='
41
41
  - !ruby/object:Gem::Version
42
- version: 0.2.0
42
+ version: 0.3.0
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rectify
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -88,56 +88,56 @@ dependencies:
88
88
  requirements:
89
89
  - - '='
90
90
  - !ruby/object:Gem::Version
91
- version: 0.2.0
91
+ version: 0.3.0
92
92
  type: :development
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - '='
97
97
  - !ruby/object:Gem::Version
98
- version: 0.2.0
98
+ version: 0.3.0
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: decidim-meetings
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
103
  - - '='
104
104
  - !ruby/object:Gem::Version
105
- version: 0.2.0
105
+ version: 0.3.0
106
106
  type: :development
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - '='
111
111
  - !ruby/object:Gem::Version
112
- version: 0.2.0
112
+ version: 0.3.0
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: decidim-results
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - '='
118
118
  - !ruby/object:Gem::Version
119
- version: 0.2.0
119
+ version: 0.3.0
120
120
  type: :development
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
123
123
  requirements:
124
124
  - - '='
125
125
  - !ruby/object:Gem::Version
126
- version: 0.2.0
126
+ version: 0.3.0
127
127
  - !ruby/object:Gem::Dependency
128
128
  name: decidim-budgets
129
129
  requirement: !ruby/object:Gem::Requirement
130
130
  requirements:
131
131
  - - '='
132
132
  - !ruby/object:Gem::Version
133
- version: 0.2.0
133
+ version: 0.3.0
134
134
  type: :development
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  requirements:
138
138
  - - '='
139
139
  - !ruby/object:Gem::Version
140
- version: 0.2.0
140
+ version: 0.3.0
141
141
  description: A proposals component for decidim's participatory processes.
142
142
  email:
143
143
  - josepjaume@gmail.com
@@ -158,6 +158,8 @@ files:
158
158
  - app/commands/decidim/proposals/admin/create_proposal.rb
159
159
  - app/commands/decidim/proposals/create_proposal.rb
160
160
  - app/commands/decidim/proposals/create_proposal_export.rb
161
+ - app/commands/decidim/proposals/unvote_proposal.rb
162
+ - app/commands/decidim/proposals/vote_proposal.rb
161
163
  - app/controllers/concerns/decidim/proposals/orderable.rb
162
164
  - app/controllers/decidim/proposals/admin/application_controller.rb
163
165
  - app/controllers/decidim/proposals/admin/proposal_answers_controller.rb
@@ -186,6 +188,7 @@ files:
186
188
  - app/views/decidim/proposals/admin/proposals/new.html.erb
187
189
  - app/views/decidim/proposals/proposal_votes/update_buttons_and_counters.js.erb
188
190
  - app/views/decidim/proposals/proposal_widgets/show.html.erb
191
+ - app/views/decidim/proposals/proposals/_author.html.erb
189
192
  - app/views/decidim/proposals/proposals/_count.html.erb
190
193
  - app/views/decidim/proposals/proposals/_filters.html.erb
191
194
  - app/views/decidim/proposals/proposals/_filters_small_view.html.erb
@@ -210,6 +213,7 @@ files:
210
213
  - config/locales/eu.yml
211
214
  - config/locales/fi.yml
212
215
  - config/locales/fr.yml
216
+ - config/locales/it.yml
213
217
  - config/locales/nl.yml
214
218
  - db/migrate/20161212110850_create_decidim_proposals.rb
215
219
  - db/migrate/20170112115253_create_proposal_votes.rb
@@ -225,6 +229,7 @@ files:
225
229
  - db/migrate/20170228105156_add_geolocalization_fields_to_proposals.rb
226
230
  - db/migrate/20170307085300_migrate_proposal_reports_data_to_reports.rb
227
231
  - db/migrate/20170410073742_remove_not_null_reference_proposals.rb
232
+ - db/migrate/20170612101809_migrate_proposals_category.rb
228
233
  - lib/decidim/proposals.rb
229
234
  - lib/decidim/proposals/admin.rb
230
235
  - lib/decidim/proposals/admin_engine.rb