decidim-surveys 0.30.1 → 0.31.0.rc1
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.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/app/commands/decidim/surveys/admin/create_survey.rb +14 -2
- data/app/commands/decidim/surveys/admin/publish_survey.rb +3 -3
- data/app/commands/decidim/surveys/admin/update_survey.rb +0 -13
- data/app/commands/decidim/surveys/admin/update_survey_settings.rb +53 -0
- data/app/commands/decidim/surveys/{publish_answers.rb → publish_responses.rb} +8 -8
- data/app/commands/decidim/surveys/{unpublish_answers.rb → unpublish_responses.rb} +8 -8
- data/app/controllers/decidim/surveys/admin/application_controller.rb +13 -0
- data/app/controllers/decidim/surveys/admin/{publish_answers_controller.rb → publish_responses_controller.rb} +9 -9
- data/app/controllers/decidim/surveys/admin/questions/surveys_controller.rb +48 -0
- data/app/controllers/decidim/surveys/admin/{answers_controller.rb → responses_controller.rb} +18 -13
- data/app/controllers/decidim/surveys/admin/settings/surveys_controller.rb +42 -0
- data/app/controllers/decidim/surveys/admin/surveys_controller.rb +20 -39
- data/app/controllers/decidim/surveys/surveys_controller.rb +15 -12
- data/app/forms/decidim/surveys/admin/survey_form.rb +3 -7
- data/app/forms/decidim/surveys/admin/survey_settings_form.rb +18 -0
- data/app/helpers/decidim/surveys/{publish_answers_helper.rb → publish_responses_helper.rb} +11 -11
- data/app/helpers/decidim/surveys/survey_helper.rb +1 -1
- data/app/jobs/decidim/surveys/{clean_survey_answers_job.rb → clean_survey_responses_job.rb} +4 -4
- data/app/jobs/decidim/surveys/settings_change_job.rb +5 -5
- data/app/mailers/decidim/surveys/survey_confirmation_mailer.rb +6 -6
- data/app/models/decidim/surveys/survey.rb +4 -4
- data/app/permissions/decidim/surveys/admin/permissions.rb +6 -4
- data/app/permissions/decidim/surveys/permissions.rb +1 -1
- data/app/serializers/decidim/surveys/data_importer.rb +5 -5
- data/app/serializers/decidim/surveys/data_serializer.rb +5 -5
- data/app/views/decidim/surveys/admin/publish_responses/_toggle_button.html.erb +22 -0
- data/app/views/decidim/surveys/admin/{publish_answers → publish_responses}/index.html.erb +4 -4
- data/app/views/decidim/surveys/admin/questions/surveys/edit.html.erb +44 -0
- data/app/views/decidim/surveys/admin/responses/index.html.erb +101 -0
- data/app/views/decidim/surveys/admin/responses/show.html.erb +43 -0
- data/app/views/decidim/surveys/admin/{surveys → settings/surveys}/_form.html.erb +2 -3
- data/app/views/decidim/surveys/admin/settings/surveys/edit.html.erb +23 -0
- data/app/views/decidim/surveys/admin/surveys/_tabs_menu.html.erb +11 -0
- data/app/views/decidim/surveys/admin/surveys/edit.html.erb +18 -18
- data/app/views/decidim/surveys/admin/surveys/index.html.erb +89 -23
- data/app/views/decidim/surveys/admin/surveys/new.html.erb +23 -0
- data/app/views/decidim/surveys/survey_confirmation_mailer/confirmation.html.erb +1 -1
- data/app/views/decidim/surveys/surveys/{_published_questions_answers.html.erb → _published_questions_responses.html.erb} +2 -2
- data/app/views/decidim/surveys/surveys/not_allowed.html.erb +2 -2
- data/app/views/layouts/decidim/admin/surveys.html.erb +18 -0
- data/config/assets.rb +1 -1
- data/config/locales/ar.yml +0 -20
- data/config/locales/bg.yml +0 -28
- data/config/locales/ca-IT.yml +45 -29
- data/config/locales/ca.yml +45 -29
- data/config/locales/cs.yml +33 -39
- data/config/locales/de.yml +43 -27
- data/config/locales/el.yml +0 -23
- data/config/locales/en.yml +49 -33
- data/config/locales/es-MX.yml +44 -28
- data/config/locales/es-PY.yml +44 -28
- data/config/locales/es.yml +44 -28
- data/config/locales/eu.yml +43 -27
- data/config/locales/fi-plain.yml +41 -25
- data/config/locales/fi.yml +41 -25
- data/config/locales/fr-CA.yml +35 -32
- data/config/locales/fr.yml +35 -32
- data/config/locales/ga-IE.yml +0 -13
- data/config/locales/gl.yml +0 -22
- data/config/locales/hu.yml +0 -16
- data/config/locales/id-ID.yml +0 -15
- data/config/locales/is-IS.yml +0 -2
- data/config/locales/it.yml +0 -22
- data/config/locales/ja.yml +43 -27
- data/config/locales/lb.yml +0 -22
- data/config/locales/lt.yml +0 -25
- data/config/locales/lv.yml +0 -17
- data/config/locales/nl.yml +0 -22
- data/config/locales/no.yml +0 -22
- data/config/locales/pl.yml +0 -30
- data/config/locales/pt-BR.yml +0 -22
- data/config/locales/pt.yml +0 -22
- data/config/locales/ro-RO.yml +18 -23
- data/config/locales/ru.yml +0 -13
- data/config/locales/sk.yml +0 -18
- data/config/locales/sl.yml +0 -8
- data/config/locales/sv.yml +8 -26
- data/config/locales/tr-TR.yml +0 -22
- data/config/locales/uk.yml +0 -13
- data/config/locales/zh-CN.yml +0 -15
- data/config/locales/zh-TW.yml +0 -22
- data/db/migrate/20250317110501_rename_answer_to_response_in_decidim_surveys.rb +8 -0
- data/lib/decidim/api/survey_type.rb +12 -0
- data/lib/decidim/surveys/admin_engine.rb +46 -7
- data/lib/decidim/surveys/component.rb +24 -19
- data/lib/decidim/surveys/engine.rb +8 -25
- data/lib/decidim/surveys/seeds.rb +42 -42
- data/lib/decidim/surveys/test/factories.rb +3 -3
- data/lib/decidim/surveys/version.rb +1 -1
- data/lib/tasks/surveys/upgrade/decidim_surveys_upgrade_tasks.rake +16 -82
- metadata +36 -29
- data/app/queries/decidim/surveys/metrics/answers_metric_manage.rb +0 -65
- data/app/queries/decidim/surveys/metrics/survey_participants_metric_measure.rb +0 -30
- data/app/views/decidim/surveys/admin/answers/index.html.erb +0 -49
- data/app/views/decidim/surveys/admin/answers/show.html.erb +0 -43
- data/app/views/decidim/surveys/admin/publish_answers/_toggle_button.html.erb +0 -22
- data/app/views/decidim/surveys/admin/surveys/edit_questions.html.erb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e206d9a7b9769b02f5a4098f8ccfdef11030d5f895bd0d53fab94942f00e7a02
|
4
|
+
data.tar.gz: 1a55fa9ebebe3de7e07c585b6b09fe75acf7b0128ec1d18a0c7774300c68b775
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df2e36649d389cf3738d8b2b9a157bfb97d741ca65e26e8fe8606cc1c86fcecf60a96bbfd4defb7b04994766bd23058bfe05007edf8daa6d2fbac08b21e5105a
|
7
|
+
data.tar.gz: e278e5f6e92b90694833d5f2f2f6ee80b42bb11795e68397e6b784619f4cad07b8a5c0ba24a4069c541f87be3383b2d6d7afdaa2b79a2cd24193eafb1547f768
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# Decidim::Surveys
|
2
2
|
|
3
|
-
The Surveys module adds one new component to Decidim: defining and
|
3
|
+
The Surveys module adds one new component to Decidim: defining and responding surveys.
|
4
4
|
|
5
5
|
The main features are:
|
6
6
|
|
7
7
|
* Admins can define a Survey.
|
8
|
-
* Users can participate on these surveys by
|
9
|
-
* Admins can download the
|
8
|
+
* Users can participate on these surveys by responding from the public page.
|
9
|
+
* Admins can download the responses by CSV.
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
|
@@ -6,12 +6,24 @@ module Decidim
|
|
6
6
|
# Command that gets called whenever a component's survey has to be created. It
|
7
7
|
# usually happens as a callback when the component itself is created.
|
8
8
|
class CreateSurvey < Decidim::Command
|
9
|
-
def initialize(component)
|
9
|
+
def initialize(component, form)
|
10
10
|
@component = component
|
11
|
+
@form = form
|
11
12
|
end
|
12
13
|
|
14
|
+
attr_reader :form
|
15
|
+
|
13
16
|
def call
|
14
|
-
|
17
|
+
return broadcast(:invalid) if form.invalid?
|
18
|
+
|
19
|
+
@survey = Survey.new(
|
20
|
+
component: @component,
|
21
|
+
questionnaire: Decidim::Forms::Questionnaire.new(
|
22
|
+
title: form.title,
|
23
|
+
description: form.description,
|
24
|
+
tos: form.tos
|
25
|
+
)
|
26
|
+
)
|
15
27
|
|
16
28
|
@survey.save ? broadcast(:ok, @survey) : broadcast(:invalid)
|
17
29
|
end
|
@@ -27,7 +27,7 @@ module Decidim
|
|
27
27
|
|
28
28
|
transaction do
|
29
29
|
publish_survey
|
30
|
-
|
30
|
+
delete_responses if @survey.clean_after_publish?
|
31
31
|
end
|
32
32
|
|
33
33
|
broadcast(:ok, survey)
|
@@ -49,8 +49,8 @@ module Decidim
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
def
|
53
|
-
@questionnaire.
|
52
|
+
def delete_responses
|
53
|
+
@questionnaire.responses.destroy_all
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -25,7 +25,6 @@ module Decidim
|
|
25
25
|
|
26
26
|
Decidim.traceability.perform_action!("update", @survey, @user) do
|
27
27
|
transaction do
|
28
|
-
update_survey_attributes
|
29
28
|
update_questionnaire_attributes
|
30
29
|
end
|
31
30
|
rescue ActiveRecord::RecordInvalid
|
@@ -37,18 +36,6 @@ module Decidim
|
|
37
36
|
|
38
37
|
private
|
39
38
|
|
40
|
-
def update_survey_attributes
|
41
|
-
@survey.update!(
|
42
|
-
allow_answers: @form.allow_answers,
|
43
|
-
allow_editing_answers: @form.allow_editing_answers,
|
44
|
-
allow_unregistered: @form.allow_unregistered,
|
45
|
-
starts_at: @form.starts_at,
|
46
|
-
ends_at: @form.ends_at,
|
47
|
-
clean_after_publish: @form.clean_after_publish,
|
48
|
-
announcement: @form.announcement
|
49
|
-
)
|
50
|
-
end
|
51
|
-
|
52
39
|
def update_questionnaire_attributes
|
53
40
|
@questionnaire.update!(
|
54
41
|
title: @form.title,
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Surveys
|
5
|
+
module Admin
|
6
|
+
# This command is executed when the user changes a Survey Settings (also known as their attributes) from the admin
|
7
|
+
# panel.
|
8
|
+
class UpdateSurveySettings < Decidim::Forms::Admin::UpdateQuestionnaire
|
9
|
+
# Initializes a UpdateSurveySettings Command.
|
10
|
+
#
|
11
|
+
# form - The form from which to get the data.
|
12
|
+
# survey - The current instance of the survey to be updated.
|
13
|
+
# user - The user doing the update
|
14
|
+
def initialize(form, survey, user)
|
15
|
+
@form = form
|
16
|
+
@survey = survey
|
17
|
+
@user = user
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :form, :survey, :user
|
21
|
+
|
22
|
+
# Updates the survey questionnaire if valid.
|
23
|
+
#
|
24
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
25
|
+
def call
|
26
|
+
Decidim.traceability.perform_action!("update", survey, user) do
|
27
|
+
transaction do
|
28
|
+
update_survey_settings
|
29
|
+
end
|
30
|
+
rescue ActiveRecord::RecordInvalid
|
31
|
+
broadcast(:invalid)
|
32
|
+
end
|
33
|
+
|
34
|
+
broadcast(:ok)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def update_survey_settings
|
40
|
+
survey.update!(
|
41
|
+
allow_responses: form.allow_responses,
|
42
|
+
allow_editing_responses: form.allow_editing_responses,
|
43
|
+
allow_unregistered: form.allow_unregistered,
|
44
|
+
starts_at: form.starts_at,
|
45
|
+
ends_at: form.ends_at,
|
46
|
+
clean_after_publish: form.clean_after_publish,
|
47
|
+
announcement: form.announcement
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -2,24 +2,24 @@
|
|
2
2
|
|
3
3
|
module Decidim
|
4
4
|
module Surveys
|
5
|
-
# This command is executed when the admin publishes the
|
5
|
+
# This command is executed when the admin publishes the Responses from the admin
|
6
6
|
# panel.
|
7
|
-
class
|
7
|
+
class PublishResponses < Decidim::Command
|
8
8
|
include Decidim::TranslatableAttributes
|
9
9
|
|
10
|
-
# Initializes a
|
10
|
+
# Initializes a PublishResponses Command.
|
11
11
|
#
|
12
12
|
def initialize(question_id, current_user)
|
13
13
|
@question_id = question_id
|
14
14
|
@current_user = current_user
|
15
15
|
end
|
16
16
|
|
17
|
-
# Publishes the questions'
|
17
|
+
# Publishes the questions' responses
|
18
18
|
#
|
19
19
|
# Broadcasts :ok if successful, :invalid otherwise.
|
20
20
|
def call
|
21
21
|
transaction do
|
22
|
-
|
22
|
+
publish_survey_response
|
23
23
|
create_action_log
|
24
24
|
end
|
25
25
|
|
@@ -32,8 +32,8 @@ module Decidim
|
|
32
32
|
|
33
33
|
attr_reader :question_id, :current_user
|
34
34
|
|
35
|
-
def
|
36
|
-
question.update(
|
35
|
+
def publish_survey_response
|
36
|
+
question.update(survey_responses_published_at: Time.current)
|
37
37
|
end
|
38
38
|
|
39
39
|
def question
|
@@ -42,7 +42,7 @@ module Decidim
|
|
42
42
|
|
43
43
|
def create_action_log
|
44
44
|
Decidim::ActionLogger.log(
|
45
|
-
"
|
45
|
+
"publish_responses",
|
46
46
|
current_user,
|
47
47
|
question,
|
48
48
|
nil,
|
@@ -2,24 +2,24 @@
|
|
2
2
|
|
3
3
|
module Decidim
|
4
4
|
module Surveys
|
5
|
-
# This command is executed when the admin unpublishes the
|
5
|
+
# This command is executed when the admin unpublishes the Responses from the admin
|
6
6
|
# panel.
|
7
|
-
class
|
7
|
+
class UnpublishResponses < Decidim::Command
|
8
8
|
include Decidim::TranslatableAttributes
|
9
9
|
|
10
|
-
# Initializes a
|
10
|
+
# Initializes a UnpublishResponses Command.
|
11
11
|
#
|
12
12
|
def initialize(question_id, current_user)
|
13
13
|
@question_id = question_id
|
14
14
|
@current_user = current_user
|
15
15
|
end
|
16
16
|
|
17
|
-
# Unpublishes the questions'
|
17
|
+
# Unpublishes the questions' responses
|
18
18
|
#
|
19
19
|
# Broadcasts :ok if successful, :invalid otherwise.
|
20
20
|
def call
|
21
21
|
transaction do
|
22
|
-
|
22
|
+
unpublish_survey_response
|
23
23
|
create_action_log
|
24
24
|
end
|
25
25
|
|
@@ -32,8 +32,8 @@ module Decidim
|
|
32
32
|
|
33
33
|
attr_reader :question_id, :current_user
|
34
34
|
|
35
|
-
def
|
36
|
-
question.update(
|
35
|
+
def unpublish_survey_response
|
36
|
+
question.update(survey_responses_published_at: nil)
|
37
37
|
end
|
38
38
|
|
39
39
|
def question
|
@@ -42,7 +42,7 @@ module Decidim
|
|
42
42
|
|
43
43
|
def create_action_log
|
44
44
|
Decidim::ActionLogger.log(
|
45
|
-
"
|
45
|
+
"unpublish_responses",
|
46
46
|
current_user,
|
47
47
|
question,
|
48
48
|
nil,
|
@@ -9,6 +9,19 @@ module Decidim
|
|
9
9
|
# Note that it inherits from `Decidim::Admin::Components::BaseController`, which
|
10
10
|
# override its layout and provide all kinds of useful methods.
|
11
11
|
class ApplicationController < Decidim::Admin::Components::BaseController
|
12
|
+
helper_method :public_url
|
13
|
+
|
14
|
+
layout :layout_for_action
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def layout_for_action
|
19
|
+
"decidim/admin/surveys" unless %w(index new create).include?(action_name) && controller_name == "surveys"
|
20
|
+
end
|
21
|
+
|
22
|
+
def public_url
|
23
|
+
Decidim::EngineRouter.main_proxy(current_component).survey_path(survey)
|
24
|
+
end
|
12
25
|
end
|
13
26
|
end
|
14
27
|
end
|
@@ -3,22 +3,22 @@
|
|
3
3
|
module Decidim
|
4
4
|
module Surveys
|
5
5
|
module Admin
|
6
|
-
# This controller allows the user to see which questions'
|
7
|
-
class
|
8
|
-
include Decidim::Forms::Admin::Concerns::
|
6
|
+
# This controller allows the user to see which questions' responses can be published, and publish or unpublish them
|
7
|
+
class PublishResponsesController < Admin::ApplicationController
|
8
|
+
include Decidim::Forms::Admin::Concerns::HasQuestionnaireResponsesUrlHelper
|
9
9
|
|
10
|
-
helper
|
10
|
+
helper PublishResponsesHelper
|
11
11
|
|
12
12
|
def index
|
13
|
-
enforce_permission_to(:index, :
|
13
|
+
enforce_permission_to(:index, :questionnaire_publish_responses, survey:)
|
14
14
|
|
15
15
|
@survey ||= survey
|
16
16
|
end
|
17
17
|
|
18
18
|
def update
|
19
|
-
enforce_permission_to(:update, :
|
19
|
+
enforce_permission_to(:update, :questionnaire_publish_responses, survey:)
|
20
20
|
|
21
|
-
Decidim::Surveys::
|
21
|
+
Decidim::Surveys::PublishResponses.call(params[:id], current_user) do
|
22
22
|
on(:ok) do
|
23
23
|
render json: {}
|
24
24
|
end
|
@@ -30,9 +30,9 @@ module Decidim
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def destroy
|
33
|
-
enforce_permission_to(:destroy, :
|
33
|
+
enforce_permission_to(:destroy, :questionnaire_publish_responses, survey:)
|
34
34
|
|
35
|
-
Decidim::Surveys::
|
35
|
+
Decidim::Surveys::UnpublishResponses.call(params[:id], current_user) do
|
36
36
|
on(:ok) do
|
37
37
|
render json: {}
|
38
38
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Surveys
|
5
|
+
module Admin
|
6
|
+
module Questions
|
7
|
+
# This controller allows the user create and edit questionnaires for Surveys.
|
8
|
+
class SurveysController < Admin::ApplicationController
|
9
|
+
include Decidim::Forms::Admin::Concerns::HasQuestionnaire
|
10
|
+
include Decidim::Forms::Admin::Concerns::HasQuestionnaireResponsesUrlHelper
|
11
|
+
|
12
|
+
helper_method :surveys
|
13
|
+
|
14
|
+
def edit_questions_template
|
15
|
+
"decidim/surveys/admin/questions/surveys/edit"
|
16
|
+
end
|
17
|
+
|
18
|
+
def questionnaire_for
|
19
|
+
survey
|
20
|
+
end
|
21
|
+
|
22
|
+
def after_update_url
|
23
|
+
edit_questions_questions_survey_path(survey)
|
24
|
+
end
|
25
|
+
|
26
|
+
def questionnaire_participants_url
|
27
|
+
Decidim::EngineRouter.admin_proxy(survey.component).survey_responses_path(survey)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify the public url from which the survey can be viewed and responded
|
31
|
+
def public_url
|
32
|
+
Decidim::EngineRouter.main_proxy(current_component).survey_path(survey)
|
33
|
+
end
|
34
|
+
|
35
|
+
def edit_questionnaire_title
|
36
|
+
t(:title, scope: "decidim.forms.admin.questionnaires.form", questionnaire_for: translated_attribute(current_component.name))
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def survey
|
42
|
+
@survey ||= Decidim::Surveys::Survey.where(component: current_component).find(params[:id])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/app/controllers/decidim/surveys/admin/{answers_controller.rb → responses_controller.rb}
RENAMED
@@ -4,25 +4,26 @@ module Decidim
|
|
4
4
|
module Surveys
|
5
5
|
module Admin
|
6
6
|
# This controller allows the user to update a Page.
|
7
|
-
class
|
8
|
-
include Decidim::Forms::Admin::Concerns::
|
7
|
+
class ResponsesController < Admin::ApplicationController
|
8
|
+
include Decidim::Forms::Admin::Concerns::HasQuestionnaireResponses
|
9
9
|
|
10
10
|
def index
|
11
|
-
enforce_permission_to :index, :
|
11
|
+
enforce_permission_to :index, :questionnaire_responses
|
12
12
|
|
13
13
|
@query = paginate(collection)
|
14
14
|
@participants = participants(@query)
|
15
15
|
@total = questionnaire.count_participants
|
16
|
+
@survey = questionnaire_for
|
16
17
|
|
17
|
-
render template: "decidim/surveys/admin/
|
18
|
+
render template: "decidim/surveys/admin/responses/index"
|
18
19
|
end
|
19
20
|
|
20
21
|
def show
|
21
|
-
enforce_permission_to :show, :
|
22
|
+
enforce_permission_to :show, :questionnaire_responses
|
22
23
|
|
23
24
|
@participant = participant(participants_query.participant(params[:id]))
|
24
25
|
|
25
|
-
render template: "decidim/surveys/admin/
|
26
|
+
render template: "decidim/surveys/admin/responses/show"
|
26
27
|
end
|
27
28
|
|
28
29
|
def questionnaire_for
|
@@ -30,7 +31,7 @@ module Decidim
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def questionnaire_export_response_url(id)
|
33
|
-
Decidim::EngineRouter.admin_proxy(questionnaire_for.component).
|
34
|
+
Decidim::EngineRouter.admin_proxy(questionnaire_for.component).export_response_survey_response_path(questionnaire_for, id:)
|
34
35
|
end
|
35
36
|
|
36
37
|
def questionnaire_url
|
@@ -38,16 +39,20 @@ module Decidim
|
|
38
39
|
end
|
39
40
|
|
40
41
|
# Specify where to redirect after exporting a user response
|
41
|
-
def
|
42
|
-
Decidim::EngineRouter.admin_proxy(questionnaire_for.component).
|
42
|
+
def questionnaire_participant_responses_url(id)
|
43
|
+
Decidim::EngineRouter.admin_proxy(questionnaire_for.component).survey_response_path(questionnaire_for, id:)
|
43
44
|
end
|
44
45
|
|
45
46
|
def questionnaire_participants_url
|
46
|
-
Decidim::EngineRouter.admin_proxy(questionnaire_for.component).
|
47
|
+
Decidim::EngineRouter.admin_proxy(questionnaire_for.component).survey_responses_path(questionnaire_for)
|
47
48
|
end
|
48
49
|
|
49
50
|
private
|
50
51
|
|
52
|
+
def survey
|
53
|
+
questionnaire.questionnaire_for
|
54
|
+
end
|
55
|
+
|
51
56
|
def questionnaire
|
52
57
|
@questionnaire ||= Decidim::Forms::Questionnaire.find_by(questionnaire_for:)
|
53
58
|
end
|
@@ -60,12 +65,12 @@ module Decidim
|
|
60
65
|
@collection ||= participants_query.participants
|
61
66
|
end
|
62
67
|
|
63
|
-
def participant(
|
64
|
-
Decidim::Forms::Admin::QuestionnaireParticipantPresenter.new(participant:
|
68
|
+
def participant(response)
|
69
|
+
Decidim::Forms::Admin::QuestionnaireParticipantPresenter.new(participant: response)
|
65
70
|
end
|
66
71
|
|
67
72
|
def participants(query)
|
68
|
-
query.map { |
|
73
|
+
query.map { |response| participant(response) }
|
69
74
|
end
|
70
75
|
end
|
71
76
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Surveys
|
5
|
+
module Admin
|
6
|
+
module Settings
|
7
|
+
# This controller allows the user to update the settings for a Survey.
|
8
|
+
class SurveysController < Admin::ApplicationController
|
9
|
+
def edit
|
10
|
+
enforce_permission_to(:update, :questionnaire)
|
11
|
+
|
12
|
+
@form = form(Admin::SurveySettingsForm).from_model(survey)
|
13
|
+
end
|
14
|
+
|
15
|
+
def update
|
16
|
+
enforce_permission_to(:update, :questionnaire)
|
17
|
+
|
18
|
+
@form = form(Admin::SurveySettingsForm).from_params(params)
|
19
|
+
|
20
|
+
Admin::UpdateSurveySettings.call(@form, survey, current_user) do
|
21
|
+
on(:ok) do
|
22
|
+
flash[:notice] = I18n.t("update.success", scope: "decidim.surveys.admin.surveys")
|
23
|
+
redirect_to edit_settings_survey_path(survey)
|
24
|
+
end
|
25
|
+
|
26
|
+
on(:invalid) do
|
27
|
+
flash.now[:alert] = I18n.t("update.invalid", scope: "decidim.surveys.admin.surveys")
|
28
|
+
render action: "edit", status: :unprocessable_entity
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def survey
|
36
|
+
@survey ||= Decidim::Surveys::Survey.where(component: current_component).find(params[:id])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -3,19 +3,25 @@
|
|
3
3
|
module Decidim
|
4
4
|
module Surveys
|
5
5
|
module Admin
|
6
|
-
# This controller allows
|
6
|
+
# This controller allows to index, create, update, destroy, publish and unpublish a Survey.
|
7
7
|
class SurveysController < Admin::ApplicationController
|
8
|
-
include Decidim::Forms::Admin::Concerns::HasQuestionnaire
|
9
|
-
include Decidim::Forms::Admin::Concerns::HasQuestionnaireAnswersUrlHelper
|
10
8
|
include Decidim::Surveys::Admin::Filterable
|
11
9
|
|
12
10
|
helper_method :surveys
|
13
11
|
|
14
12
|
def index; end
|
15
13
|
|
14
|
+
def new
|
15
|
+
enforce_permission_to(:create, :questionnaire)
|
16
|
+
|
17
|
+
@form = form(Admin::SurveyForm).instance
|
18
|
+
end
|
19
|
+
|
16
20
|
def create
|
17
21
|
enforce_permission_to(:create, :questionnaire)
|
18
|
-
|
22
|
+
|
23
|
+
@form = form(Admin::SurveyForm).from_params(params)
|
24
|
+
Decidim::Surveys::Admin::CreateSurvey.call(current_component, @form) do
|
19
25
|
on(:ok) do |survey|
|
20
26
|
flash[:notice] = I18n.t("create.success", scope: "decidim.surveys.admin.surveys")
|
21
27
|
redirect_to edit_survey_path(survey)
|
@@ -23,35 +29,35 @@ module Decidim
|
|
23
29
|
|
24
30
|
on(:invalid) do
|
25
31
|
flash.now[:alert] = I18n.t("create.invalid", scope: "decidim.surveys.admin.surveys")
|
26
|
-
render action: "
|
32
|
+
render action: "new", status: :unprocessable_entity
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
30
36
|
|
31
37
|
def edit
|
32
|
-
enforce_permission_to(:update, :questionnaire, questionnaire:)
|
38
|
+
enforce_permission_to(:update, :questionnaire, questionnaire: survey)
|
33
39
|
@form = form(Admin::SurveyForm).from_model(survey)
|
34
40
|
end
|
35
41
|
|
36
42
|
def update
|
37
|
-
enforce_permission_to(:update, :questionnaire, questionnaire:)
|
43
|
+
enforce_permission_to(:update, :questionnaire, questionnaire: survey)
|
38
44
|
@form = form(Admin::SurveyForm).from_params(params)
|
39
45
|
|
40
46
|
Admin::UpdateSurvey.call(@form, survey, current_user) do
|
41
47
|
on(:ok) do
|
42
48
|
flash[:notice] = I18n.t("update.success", scope: "decidim.surveys.admin.surveys")
|
43
|
-
redirect_to(
|
49
|
+
redirect_to edit_survey_path(survey)
|
44
50
|
end
|
45
51
|
|
46
52
|
on(:invalid) do
|
47
53
|
flash.now[:alert] = I18n.t("update.invalid", scope: "decidim.surveys.admin.surveys")
|
48
|
-
render action: "edit"
|
54
|
+
render action: "edit", status: :unprocessable_entity
|
49
55
|
end
|
50
56
|
end
|
51
57
|
end
|
52
58
|
|
53
59
|
def publish
|
54
|
-
enforce_permission_to(:update, :questionnaire, questionnaire:)
|
60
|
+
enforce_permission_to(:update, :questionnaire, questionnaire: survey)
|
55
61
|
Decidim::Surveys::Admin::PublishSurvey.call(survey, current_user) do
|
56
62
|
on(:ok) do
|
57
63
|
flash[:notice] = I18n.t("publish.success", scope: "decidim.surveys.admin.surveys")
|
@@ -60,13 +66,13 @@ module Decidim
|
|
60
66
|
|
61
67
|
on(:invalid) do
|
62
68
|
flash.now[:alert] = I18n.t("publish.invalid", scope: "decidim.surveys.admin.surveys")
|
63
|
-
render action: "index"
|
69
|
+
render action: "index", status: :unprocessable_entity
|
64
70
|
end
|
65
71
|
end
|
66
72
|
end
|
67
73
|
|
68
74
|
def unpublish
|
69
|
-
enforce_permission_to(:update, :questionnaire, questionnaire:)
|
75
|
+
enforce_permission_to(:update, :questionnaire, questionnaire: survey)
|
70
76
|
Decidim::Surveys::Admin::UnpublishSurvey.call(survey, current_user) do
|
71
77
|
on(:ok) do
|
72
78
|
flash[:notice] = I18n.t("unpublish.success", scope: "decidim.surveys.admin.surveys")
|
@@ -75,13 +81,13 @@ module Decidim
|
|
75
81
|
|
76
82
|
on(:invalid) do
|
77
83
|
flash.now[:alert] = I18n.t("unpublish.invalid", scope: "decidim.surveys.admin.surveys")
|
78
|
-
render action: "index"
|
84
|
+
render action: "index", status: :unprocessable_entity
|
79
85
|
end
|
80
86
|
end
|
81
87
|
end
|
82
88
|
|
83
89
|
def destroy
|
84
|
-
enforce_permission_to(:destroy, :questionnaire, questionnaire:)
|
90
|
+
enforce_permission_to(:destroy, :questionnaire, questionnaire: survey)
|
85
91
|
Decidim::Commands::DestroyResource.call(survey, current_user) do
|
86
92
|
on(:ok) do
|
87
93
|
flash[:notice] = I18n.t("destroy.success", scope: "decidim.surveys.admin.surveys")
|
@@ -91,31 +97,6 @@ module Decidim
|
|
91
97
|
end
|
92
98
|
end
|
93
99
|
|
94
|
-
def edit_questions_template
|
95
|
-
"decidim/surveys/admin/surveys/edit_questions"
|
96
|
-
end
|
97
|
-
|
98
|
-
def questionnaire_for
|
99
|
-
survey
|
100
|
-
end
|
101
|
-
|
102
|
-
def after_update_url
|
103
|
-
surveys_path
|
104
|
-
end
|
105
|
-
|
106
|
-
def questionnaire_participants_url
|
107
|
-
Decidim::EngineRouter.admin_proxy(survey.component).survey_answers_path(survey)
|
108
|
-
end
|
109
|
-
|
110
|
-
# Specify the public url from which the survey can be viewed and answered
|
111
|
-
def public_url
|
112
|
-
Decidim::EngineRouter.main_proxy(current_component).survey_path(survey)
|
113
|
-
end
|
114
|
-
|
115
|
-
def edit_questionnaire_title
|
116
|
-
t(:title, scope: "decidim.forms.admin.questionnaires.form", questionnaire_for: translated_attribute(current_component.name))
|
117
|
-
end
|
118
|
-
|
119
100
|
private
|
120
101
|
|
121
102
|
def surveys
|