decidim-consultations 0.11.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +51 -0
- data/Rakefile +3 -0
- data/app/assets/config/decidim_consultations_manifest.js +5 -0
- data/app/assets/config/decidim_consultations_manifest.scss +3 -0
- data/app/assets/images/decidim/consultations/icon.svg +70 -0
- data/app/assets/images/decidim/consultations/icon2.svg +88 -0
- data/app/assets/javascripts/decidim/consultations/show_more.js.es6 +12 -0
- data/app/assets/javascripts/decidim/consultations/social_share.js +2 -0
- data/app/assets/javascripts/decidim/consultations/utils.js.es6 +19 -0
- data/app/assets/javascripts/decidim/consultations/vote_dialog.js +36 -0
- data/app/assets/stylesheets/decidim/consultations/_question.scss +46 -0
- data/app/assets/stylesheets/decidim/consultations/_stats.scss +22 -0
- data/app/assets/stylesheets/decidim/consultations/_video_wrapper.scss +14 -0
- data/app/assets/stylesheets/decidim/consultations/banners/_block-banner.scss +39 -0
- data/app/assets/stylesheets/decidim/consultations/consultations.scss +6 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-banner.scss +13 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-card.scss +17 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-header.scss +115 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-home-banner.scss +15 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-home-intro.scss +30 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-intro.scss +11 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-title.scss +26 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/_consultations_nav.scss +7 -0
- data/app/assets/stylesheets/decidim/consultations/consultations/introductory_image.scss +3 -0
- data/app/assets/stylesheets/decidim/consultations/highlighted-content-banner.css.scss +42 -0
- data/app/assets/stylesheets/decidim/consultations/social_share.css.scss +18 -0
- data/app/commands/decidim/consultations/admin/create_consultation.rb +61 -0
- data/app/commands/decidim/consultations/admin/create_question.rb +68 -0
- data/app/commands/decidim/consultations/admin/create_response.rb +39 -0
- data/app/commands/decidim/consultations/admin/publish_consultation.rb +34 -0
- data/app/commands/decidim/consultations/admin/publish_consultation_results.rb +34 -0
- data/app/commands/decidim/consultations/admin/publish_question.rb +34 -0
- data/app/commands/decidim/consultations/admin/unpublish_consultation.rb +34 -0
- data/app/commands/decidim/consultations/admin/unpublish_consultation_results.rb +34 -0
- data/app/commands/decidim/consultations/admin/unpublish_question.rb +34 -0
- data/app/commands/decidim/consultations/admin/update_consultation.rb +64 -0
- data/app/commands/decidim/consultations/admin/update_question.rb +72 -0
- data/app/commands/decidim/consultations/admin/update_response.rb +46 -0
- data/app/commands/decidim/consultations/unvote_question.rb +37 -0
- data/app/commands/decidim/consultations/vote_question.rb +42 -0
- data/app/constraints/decidim/consultations/current_component.rb +28 -0
- data/app/constraints/decidim/consultations/current_question.rb +36 -0
- data/app/controllers/concerns/decidim/consultations/action_authorization.rb +38 -0
- data/app/controllers/concerns/decidim/consultations/admin/consultation_admin.rb +24 -0
- data/app/controllers/concerns/decidim/consultations/admin/question_admin.rb +28 -0
- data/app/controllers/concerns/decidim/consultations/needs_consultation.rb +54 -0
- data/app/controllers/concerns/decidim/consultations/needs_question.rb +79 -0
- data/app/controllers/concerns/decidim/consultations/orderable.rb +52 -0
- data/app/controllers/decidim/consultations/admin/application_controller.rb +14 -0
- data/app/controllers/decidim/consultations/admin/categories_controller.rb +13 -0
- data/app/controllers/decidim/consultations/admin/component_permissions_controller.rb +13 -0
- data/app/controllers/decidim/consultations/admin/components_controller.rb +13 -0
- data/app/controllers/decidim/consultations/admin/consultation_publications_controller.rb +44 -0
- data/app/controllers/decidim/consultations/admin/consultation_results_publications_controller.rb +44 -0
- data/app/controllers/decidim/consultations/admin/consultations_controller.rb +100 -0
- data/app/controllers/decidim/consultations/admin/question_attachments_controller.rb +25 -0
- data/app/controllers/decidim/consultations/admin/question_publications_controller.rb +44 -0
- data/app/controllers/decidim/consultations/admin/questions_controller.rb +88 -0
- data/app/controllers/decidim/consultations/admin/responses_controller.rb +85 -0
- data/app/controllers/decidim/consultations/consultation_widgets_controller.rb +25 -0
- data/app/controllers/decidim/consultations/consultations_controller.rb +75 -0
- data/app/controllers/decidim/consultations/question_votes_controller.rb +40 -0
- data/app/controllers/decidim/consultations/question_widgets_controller.rb +26 -0
- data/app/controllers/decidim/consultations/questions_controller.rb +23 -0
- data/app/forms/decidim/consultations/admin/consultation_form.rb +56 -0
- data/app/forms/decidim/consultations/admin/question_form.rb +74 -0
- data/app/forms/decidim/consultations/admin/response_form.rb +18 -0
- data/app/forms/decidim/consultations/vote_form.rb +28 -0
- data/app/helpers/decidim/consultations/admin/consultations_helper.rb +14 -0
- data/app/helpers/decidim/consultations/admin/questions_helper.rb +14 -0
- data/app/helpers/decidim/consultations/consultations_helper.rb +17 -0
- data/app/models/concerns/decidim/consultations/override_categorization.rb +21 -0
- data/app/models/concerns/decidim/consultations/publicable_results.rb +51 -0
- data/app/models/decidim/consultation.rb +79 -0
- data/app/models/decidim/consultations/abilities/admin/consultation_admin_ability.rb +34 -0
- data/app/models/decidim/consultations/abilities/admin/question_admin_ability.rb +30 -0
- data/app/models/decidim/consultations/abilities/admin/response_admin_ability.rb +26 -0
- data/app/models/decidim/consultations/abilities/current_user_ability.rb +45 -0
- data/app/models/decidim/consultations/abilities/everyone_ability.rb +23 -0
- data/app/models/decidim/consultations/application_record.rb +9 -0
- data/app/models/decidim/consultations/question.rb +127 -0
- data/app/models/decidim/consultations/response.rb +19 -0
- data/app/models/decidim/consultations/vote.rb +26 -0
- data/app/presenters/decidim/consultations/question_stats_presenter.rb +52 -0
- data/app/queries/decidim/consultations/admin/admin_users.rb +40 -0
- data/app/queries/decidim/consultations/organization_active_consultations.rb +20 -0
- data/app/queries/decidim/consultations/organization_consultations.rb +20 -0
- data/app/queries/decidim/consultations/organization_questions.rb +20 -0
- data/app/services/decidim/consultations/consultation_search.rb +51 -0
- data/app/views/decidim/consultations/_consultation.html.erb +32 -0
- data/app/views/decidim/consultations/admin/consultations/_form.html.erb +58 -0
- data/app/views/decidim/consultations/admin/consultations/edit.html.erb +42 -0
- data/app/views/decidim/consultations/admin/consultations/index.html.erb +74 -0
- data/app/views/decidim/consultations/admin/consultations/new.html.erb +11 -0
- data/app/views/decidim/consultations/admin/questions/_form.html.erb +84 -0
- data/app/views/decidim/consultations/admin/questions/edit.html.erb +32 -0
- data/app/views/decidim/consultations/admin/questions/index.html.erb +74 -0
- data/app/views/decidim/consultations/admin/questions/new.html.erb +13 -0
- data/app/views/decidim/consultations/admin/responses/_form.html.erb +11 -0
- data/app/views/decidim/consultations/admin/responses/edit.html.erb +18 -0
- data/app/views/decidim/consultations/admin/responses/index.html.erb +48 -0
- data/app/views/decidim/consultations/admin/responses/new.html.erb +13 -0
- data/app/views/decidim/consultations/consultation_widgets/show.html.erb +5 -0
- data/app/views/decidim/consultations/consultations/_consultation_card.html.erb +24 -0
- data/app/views/decidim/consultations/consultations/_consultation_details.html.erb +17 -0
- data/app/views/decidim/consultations/consultations/_consultations.html.erb +16 -0
- data/app/views/decidim/consultations/consultations/_count.html.erb +1 -0
- data/app/views/decidim/consultations/consultations/_filters.html.erb +25 -0
- data/app/views/decidim/consultations/consultations/_filters_small_view.html.erb +23 -0
- data/app/views/decidim/consultations/consultations/_highlighted_questions.html.erb +13 -0
- data/app/views/decidim/consultations/consultations/_question.html.erb +40 -0
- data/app/views/decidim/consultations/consultations/_regular_questions.html.erb +14 -0
- data/app/views/decidim/consultations/consultations/finished.html.erb +15 -0
- data/app/views/decidim/consultations/consultations/index.html.erb +27 -0
- data/app/views/decidim/consultations/consultations/index.js.erb +10 -0
- data/app/views/decidim/consultations/consultations/show.html.erb +11 -0
- data/app/views/decidim/consultations/question_votes/update_vote_button.js.erb +9 -0
- data/app/views/decidim/consultations/question_widgets/show.html.erb +2 -0
- data/app/views/decidim/consultations/questions/_results.html.erb +15 -0
- data/app/views/decidim/consultations/questions/_right_column.html.erb +20 -0
- data/app/views/decidim/consultations/questions/_statistics.html.erb +31 -0
- data/app/views/decidim/consultations/questions/_technical_data.html.erb +38 -0
- data/app/views/decidim/consultations/questions/_vote_button.html.erb +76 -0
- data/app/views/decidim/consultations/questions/_vote_modal.html.erb +27 -0
- data/app/views/decidim/consultations/questions/_vote_modal_confirm.html.erb +33 -0
- data/app/views/decidim/consultations/questions/show.html.erb +58 -0
- data/app/views/layouts/decidim/_consultation_header.html.erb +16 -0
- data/app/views/layouts/decidim/_consultation_voting_data.html.erb +10 -0
- data/app/views/layouts/decidim/_question_components.html.erb +38 -0
- data/app/views/layouts/decidim/_question_header.html.erb +46 -0
- data/app/views/layouts/decidim/admin/consultation.html.erb +28 -0
- data/app/views/layouts/decidim/admin/consultations.html.erb +16 -0
- data/app/views/layouts/decidim/admin/question.html.erb +72 -0
- data/app/views/layouts/decidim/consultation.html.erb +17 -0
- data/app/views/layouts/decidim/consultation_choose.html.erb +7 -0
- data/app/views/layouts/decidim/question.html.erb +19 -0
- data/config/locales/ca.yml +248 -0
- data/config/locales/en.yml +249 -0
- data/config/locales/es.yml +248 -0
- data/config/locales/eu.yml +248 -0
- data/config/locales/fi.yml +248 -0
- data/config/locales/fr.yml +248 -0
- data/config/locales/gl.yml +248 -0
- data/config/locales/it.yml +248 -0
- data/config/locales/nl.yml +248 -0
- data/config/locales/pl.yml +258 -0
- data/config/locales/pt-BR.yml +248 -0
- data/config/locales/pt.yml +248 -0
- data/config/locales/ru.yml +6 -0
- data/config/locales/sv.yml +248 -0
- data/config/locales/uk.yml +6 -0
- data/db/migrate/20180109092205_create_decidim_consultations.rb +37 -0
- data/db/migrate/20180112053247_create_decidim_consultations_questions.rb +35 -0
- data/db/migrate/20180115132000_add_end_voting_date_to_decidim_consultations.rb +18 -0
- data/db/migrate/20180115170933_add_slug_to_decidim_consultations_questions.rb +32 -0
- data/db/migrate/20180119084217_create_decidim_consultations_votes.rb +17 -0
- data/db/migrate/20180119084331_add_votes_count_to_decidim_consultations_question.rb +7 -0
- data/db/migrate/20180122113155_add_origin_scope_to_decidim_consultations_questions.rb +8 -0
- data/db/migrate/20180122113400_add_origin_title_to_decidim_consultations_questions.rb +8 -0
- data/db/migrate/20180122113447_add_origin_string_to_decidim_consultations_questions.rb +7 -0
- data/db/migrate/20180126142459_add_enable_highlighted_banner_to_decidim_consultations.rb +7 -0
- data/db/migrate/20180129063438_add_i_frame_url_to_decidim_consultations_questions.rb +8 -0
- data/db/migrate/20180129063700_create_decidim_consultations_responses.rb +14 -0
- data/db/migrate/20180129122226_rename_decidim_consultations_vote_to_decidim_consultations_endorsement.rb +7 -0
- data/db/migrate/20180129122504_rename_decidim_consultations_questions_votes_count_to_endorsements_count.rb +7 -0
- data/db/migrate/20180130060754_add_responses_count_to_decidim_consultations_questions.rb +22 -0
- data/db/migrate/20180130110449_rename_vote_related_attributes.rb +9 -0
- data/db/migrate/20180130142018_add_decidim_user_group_id_to_decidim_consultations_endorsements.rb +7 -0
- data/db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb +36 -0
- data/db/migrate/20180131083844_add_response_to_decidim_consultations_endorsements.rb +10 -0
- data/db/migrate/20180201135823_rename_endorsement_to_vote.rb +23 -0
- data/db/migrate/20180202050920_add_hero_image_to_decidim_consultations_question.rb +8 -0
- data/db/migrate/20180202085309_add_results_published_at_to_decidim_consultations.rb +7 -0
- data/db/migrate/20180202133655_add_votes_count_to_decidim_consultations_response.rb +7 -0
- data/db/migrate/20180212100503_remove_enable_highlighted_banner_flag.rb +7 -0
- data/db/migrate/20180219092120_add_order_to_decidim_consultations_questions.rb +7 -0
- data/db/migrate/20180320100658_add_introductory_image_to_decidim_consultations.rb +7 -0
- data/db/seeds/Exampledocument.pdf +0 -0
- data/db/seeds/city.jpeg +0 -0
- data/db/seeds/city2.jpeg +0 -0
- data/db/seeds/homepage_image.jpg +0 -0
- data/lib/decidim/consultations.rb +18 -0
- data/lib/decidim/consultations/admin.rb +10 -0
- data/lib/decidim/consultations/admin_engine.rb +72 -0
- data/lib/decidim/consultations/engine.rb +83 -0
- data/lib/decidim/consultations/participatory_space.rb +171 -0
- data/lib/decidim/consultations/test/factories.rb +104 -0
- data/lib/decidim/consultations/version.rb +9 -0
- metadata +288 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# A command that sets a consultation as published.
|
7
|
+
class PublishConsultation < Rectify::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# consultation - A Consultation that will be published
|
11
|
+
def initialize(consultation)
|
12
|
+
@consultation = consultation
|
13
|
+
end
|
14
|
+
|
15
|
+
# Executes the command. Broadcasts these events:
|
16
|
+
#
|
17
|
+
# - :ok when everything is valid.
|
18
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def call
|
22
|
+
return broadcast(:invalid) if consultation.nil? || consultation.published?
|
23
|
+
|
24
|
+
consultation.publish!
|
25
|
+
broadcast(:ok)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :consultation
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# A command that sets a consultation results as published.
|
7
|
+
class PublishConsultationResults < Rectify::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# consultation - A Consultation that will get its results published
|
11
|
+
def initialize(consultation)
|
12
|
+
@consultation = consultation
|
13
|
+
end
|
14
|
+
|
15
|
+
# Executes the command. Broadcasts these events:
|
16
|
+
#
|
17
|
+
# - :ok when everything is valid.
|
18
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def call
|
22
|
+
return broadcast(:invalid) if consultation.nil? || consultation.results_published?
|
23
|
+
|
24
|
+
consultation.publish_results!
|
25
|
+
broadcast(:ok)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :consultation
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# A command that sets a question as published.
|
7
|
+
class PublishQuestion < Rectify::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# question - A Question that will be published
|
11
|
+
def initialize(question)
|
12
|
+
@question = question
|
13
|
+
end
|
14
|
+
|
15
|
+
# Executes the command. Broadcasts these events:
|
16
|
+
#
|
17
|
+
# - :ok when everything is valid.
|
18
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def call
|
22
|
+
return broadcast(:invalid) if question.nil? || question.published?
|
23
|
+
|
24
|
+
question.publish!
|
25
|
+
broadcast(:ok)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :question
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# A command that sets a consultation as unpublished.
|
7
|
+
class UnpublishConsultation < Rectify::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# consultation - A Consultation that will be unpublished
|
11
|
+
def initialize(consultation)
|
12
|
+
@consultation = consultation
|
13
|
+
end
|
14
|
+
|
15
|
+
# Executes the command. Broadcasts these events:
|
16
|
+
#
|
17
|
+
# - :ok when everything is valid.
|
18
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def call
|
22
|
+
return broadcast(:invalid) if consultation.nil? || !consultation.published?
|
23
|
+
|
24
|
+
consultation.unpublish!
|
25
|
+
broadcast(:ok)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :consultation
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# A command that sets a consultation results as unpublished.
|
7
|
+
class UnpublishConsultationResults < Rectify::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# consultation - A Consultation that will get its results unpublished
|
11
|
+
def initialize(consultation)
|
12
|
+
@consultation = consultation
|
13
|
+
end
|
14
|
+
|
15
|
+
# Executes the command. Broadcasts these events:
|
16
|
+
#
|
17
|
+
# - :ok when everything is valid.
|
18
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def call
|
22
|
+
return broadcast(:invalid) if consultation.nil? || !consultation.results_published?
|
23
|
+
|
24
|
+
consultation.unpublish_results!
|
25
|
+
broadcast(:ok)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :consultation
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# A command that sets a question as unpublished.
|
7
|
+
class UnpublishQuestion < Rectify::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# question - A Question that will be unpublished
|
11
|
+
def initialize(question)
|
12
|
+
@question = question
|
13
|
+
end
|
14
|
+
|
15
|
+
# Executes the command. Broadcasts these events:
|
16
|
+
#
|
17
|
+
# - :ok when everything is valid.
|
18
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def call
|
22
|
+
return broadcast(:invalid) if question.nil? || !question.published?
|
23
|
+
|
24
|
+
question.unpublish!
|
25
|
+
broadcast(:ok)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :question
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when updating an existing participatory
|
7
|
+
# consultation in the system.
|
8
|
+
class UpdateConsultation < Rectify::Command
|
9
|
+
# Public: Initializes the command.
|
10
|
+
#
|
11
|
+
# consultation - the Consultation to update
|
12
|
+
# form - A form object with the params.
|
13
|
+
def initialize(consultation, form)
|
14
|
+
@consultation = consultation
|
15
|
+
@form = form
|
16
|
+
end
|
17
|
+
|
18
|
+
# Executes the command. Broadcasts these events:
|
19
|
+
#
|
20
|
+
# - :ok when everything is valid.
|
21
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
def call
|
25
|
+
return broadcast(:invalid) if form.invalid?
|
26
|
+
update_consultation
|
27
|
+
|
28
|
+
if consultation.valid?
|
29
|
+
broadcast(:ok, consultation)
|
30
|
+
else
|
31
|
+
form.errors.add(:banner_image, consultation.errors[:banner_image]) if consultation.errors.include? :banner_image
|
32
|
+
form.errors.add(:introductory_image, consultation.errors[:introductory_image]) if consultation.errors.include? :introductory_image
|
33
|
+
broadcast(:invalid)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_reader :form, :consultation
|
40
|
+
|
41
|
+
def update_consultation
|
42
|
+
consultation.assign_attributes(attributes)
|
43
|
+
consultation.save! if consultation.valid?
|
44
|
+
end
|
45
|
+
|
46
|
+
def attributes
|
47
|
+
{
|
48
|
+
title: form.title,
|
49
|
+
subtitle: form.subtitle,
|
50
|
+
description: form.description,
|
51
|
+
slug: form.slug,
|
52
|
+
banner_image: form.banner_image,
|
53
|
+
remove_banner_image: form.remove_banner_image,
|
54
|
+
highlighted_scope: form.highlighted_scope,
|
55
|
+
introductory_video_url: form.introductory_video_url,
|
56
|
+
start_voting_date: form.start_voting_date,
|
57
|
+
end_voting_date: form.end_voting_date,
|
58
|
+
introductory_image: form.introductory_image
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when updating an existing participatory
|
7
|
+
# question in the system.
|
8
|
+
class UpdateQuestion < Rectify::Command
|
9
|
+
# Public: Initializes the command.
|
10
|
+
#
|
11
|
+
# question - the Question to update
|
12
|
+
# form - A form object with the params.
|
13
|
+
def initialize(question, form)
|
14
|
+
@question = question
|
15
|
+
@form = form
|
16
|
+
end
|
17
|
+
|
18
|
+
# Executes the command. Broadcasts these events:
|
19
|
+
#
|
20
|
+
# - :ok when everything is valid.
|
21
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
def call
|
25
|
+
return broadcast(:invalid) if form.invalid?
|
26
|
+
update_question
|
27
|
+
|
28
|
+
if question.valid?
|
29
|
+
broadcast(:ok, question)
|
30
|
+
else
|
31
|
+
form.errors.add(:hero_image, question.errors[:hero_image]) if question.errors.include? :hero_image
|
32
|
+
form.errors.add(:banner_image, question.errors[:banner_image]) if question.errors.include? :banner_image
|
33
|
+
broadcast(:invalid)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_reader :form, :question
|
40
|
+
|
41
|
+
def update_question
|
42
|
+
question.assign_attributes(attributes)
|
43
|
+
question.save! if question.valid?
|
44
|
+
end
|
45
|
+
|
46
|
+
def attributes
|
47
|
+
{
|
48
|
+
decidim_scope_id: form.decidim_scope_id,
|
49
|
+
title: form.title,
|
50
|
+
subtitle: form.subtitle,
|
51
|
+
slug: form.slug,
|
52
|
+
what_is_decided: form.what_is_decided,
|
53
|
+
promoter_group: form.promoter_group,
|
54
|
+
participatory_scope: form.participatory_scope,
|
55
|
+
question_context: form.question_context,
|
56
|
+
hashtag: form.hashtag,
|
57
|
+
hero_image: form.hero_image,
|
58
|
+
remove_hero_image: form.remove_hero_image,
|
59
|
+
banner_image: form.banner_image,
|
60
|
+
remove_banner_image: form.remove_banner_image,
|
61
|
+
origin_scope: form.origin_scope,
|
62
|
+
origin_title: form.origin_title,
|
63
|
+
origin_url: form.origin_url,
|
64
|
+
external_voting: form.external_voting,
|
65
|
+
i_frame_url: form.i_frame_url,
|
66
|
+
order: form.order
|
67
|
+
}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when updating an response in the system.
|
7
|
+
class UpdateResponse < Rectify::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# response - the response to update
|
11
|
+
# form - A form object with the params.
|
12
|
+
def initialize(response, form)
|
13
|
+
@response = response
|
14
|
+
@form = form
|
15
|
+
end
|
16
|
+
|
17
|
+
# Executes the command. Broadcasts these events:
|
18
|
+
#
|
19
|
+
# - :ok when everything is valid.
|
20
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
21
|
+
#
|
22
|
+
# Returns nothing.
|
23
|
+
def call
|
24
|
+
return broadcast(:invalid) if form.invalid?
|
25
|
+
update_response
|
26
|
+
broadcast(:ok, response)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :form, :response
|
32
|
+
|
33
|
+
def update_response
|
34
|
+
response.assign_attributes(attributes)
|
35
|
+
response.save
|
36
|
+
end
|
37
|
+
|
38
|
+
def attributes
|
39
|
+
{
|
40
|
+
title: form.title
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
# A command with all the business logic when a user unvotes a question.
|
6
|
+
class UnvoteQuestion < Rectify::Command
|
7
|
+
# Public: Initializes the command.
|
8
|
+
#
|
9
|
+
# question - A Decidim::Consultations::Question object.
|
10
|
+
# current_user - The current user.
|
11
|
+
def initialize(question, current_user)
|
12
|
+
@question = question
|
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 question.
|
19
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
20
|
+
#
|
21
|
+
# Returns nothing.
|
22
|
+
def call
|
23
|
+
destroy_vote
|
24
|
+
broadcast(:ok, @question)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def destroy_vote
|
30
|
+
@question
|
31
|
+
.votes
|
32
|
+
.where(author: @current_user)
|
33
|
+
.destroy_all
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Consultations
|
5
|
+
# A command with all the business logic when a user votes a question.
|
6
|
+
class VoteQuestion < Rectify::Command
|
7
|
+
# Public: Initializes the command.
|
8
|
+
#
|
9
|
+
# form - A Decidim::Consultations::VoteForm object.
|
10
|
+
# current_user - The current user.
|
11
|
+
def initialize(form)
|
12
|
+
@form = form
|
13
|
+
end
|
14
|
+
|
15
|
+
# Executes the command. Broadcasts these events:
|
16
|
+
#
|
17
|
+
# - :ok when everything is valid, together with the vote.
|
18
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def call
|
22
|
+
vote = build_vote
|
23
|
+
if vote.save
|
24
|
+
broadcast(:ok, vote)
|
25
|
+
else
|
26
|
+
broadcast(:invalid, vote)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_reader :form
|
33
|
+
|
34
|
+
def build_vote
|
35
|
+
form.context.current_question.votes.build(
|
36
|
+
author: form.context.current_user,
|
37
|
+
response: form.response
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|