decidim-surveys 0.30.3 → 0.31.0.rc2
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 +4 -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 +5 -5
 - 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 +101 -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 +50 -29
 - data/config/locales/ca.yml +50 -29
 - data/config/locales/cs.yml +37 -39
 - data/config/locales/de.yml +42 -26
 - data/config/locales/el.yml +0 -23
 - data/config/locales/en.yml +54 -33
 - data/config/locales/es-MX.yml +49 -28
 - data/config/locales/es-PY.yml +49 -28
 - data/config/locales/es.yml +49 -28
 - data/config/locales/eu.yml +48 -27
 - data/config/locales/fi-plain.yml +46 -25
 - data/config/locales/fi.yml +46 -25
 - data/config/locales/fr-CA.yml +40 -32
 - data/config/locales/fr.yml +40 -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 +48 -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 +13 -23
 - 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 +35 -28
 - 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
 
    
        data/config/locales/sl.yml
    CHANGED
    
    
    
        data/config/locales/sv.yml
    CHANGED
    
    | 
         @@ -9,14 +9,15 @@ sv: 
     | 
|
| 
       9 
9 
     | 
    
         
             
                  decidim/surveys/survey:
         
     | 
| 
       10 
10 
     | 
    
         
             
                    one: Enkät
         
     | 
| 
       11 
11 
     | 
    
         
             
                    other: Enkäter
         
     | 
| 
       12 
     | 
    
         
            -
                  decidim/surveys/survey_answer:
         
     | 
| 
       13 
     | 
    
         
            -
                    one: Svar
         
     | 
| 
       14 
     | 
    
         
            -
                    other: Svar
         
     | 
| 
       15 
12 
     | 
    
         
             
              decidim:
         
     | 
| 
      
 13 
     | 
    
         
            +
                admin:
         
     | 
| 
      
 14 
     | 
    
         
            +
                  actions:
         
     | 
| 
      
 15 
     | 
    
         
            +
                    confirm_unpublish_survey: Är du säker på att du vill avpublisera denna enkät?
         
     | 
| 
      
 16 
     | 
    
         
            +
                    see_survey: Se enkät
         
     | 
| 
       16 
17 
     | 
    
         
             
                components:
         
     | 
| 
       17 
18 
     | 
    
         
             
                  surveys:
         
     | 
| 
       18 
19 
     | 
    
         
             
                    actions:
         
     | 
| 
       19 
     | 
    
         
            -
                       
     | 
| 
      
 20 
     | 
    
         
            +
                      respond: Besvara
         
     | 
| 
       20 
21 
     | 
    
         
             
                    settings:
         
     | 
| 
       21 
22 
     | 
    
         
             
                      global:
         
     | 
| 
       22 
23 
     | 
    
         
             
                        announcement: Meddelande
         
     | 
| 
         @@ -34,18 +35,14 @@ sv: 
     | 
|
| 
       34 
35 
     | 
    
         
             
                      email_outro: Du har fått det här meddelandet eftersom du följer %{participatory_space_title}. Du kan sluta att ta emot meddelanden via föregående länk.
         
     | 
| 
       35 
36 
     | 
    
         
             
                      email_subject: En ny enkät i %{participatory_space_title}
         
     | 
| 
       36 
37 
     | 
    
         
             
                      notification_title: Enkäten <a href="%{resource_path}">%{resource_title}</a> i <a href="%{participatory_space_url}">%{participatory_space_title}</a> är nu öppen.
         
     | 
| 
       37 
     | 
    
         
            -
                metrics:
         
     | 
| 
       38 
     | 
    
         
            -
                  survey_answers:
         
     | 
| 
       39 
     | 
    
         
            -
                    description: Antal enkäter besvarade av deltagarna
         
     | 
| 
       40 
     | 
    
         
            -
                    object: svar på enkäter
         
     | 
| 
       41 
     | 
    
         
            -
                    title: Svar på enkäter
         
     | 
| 
       42 
38 
     | 
    
         
             
                statistics:
         
     | 
| 
       43 
     | 
    
         
            -
                   
     | 
| 
      
 39 
     | 
    
         
            +
                  responses: 'Svar:'
         
     | 
| 
      
 40 
     | 
    
         
            +
                  surveys_count_tooltip: Antalet tillgängliga undersökningar och svar som samlats in.
         
     | 
| 
       44 
41 
     | 
    
         
             
                surveys:
         
     | 
| 
       45 
42 
     | 
    
         
             
                  admin:
         
     | 
| 
       46 
     | 
    
         
            -
                    exports:
         
     | 
| 
       47 
     | 
    
         
            -
                      survey_user_answers: Svar från enkätdeltagarna
         
     | 
| 
       48 
43 
     | 
    
         
             
                    surveys:
         
     | 
| 
      
 44 
     | 
    
         
            +
                      new:
         
     | 
| 
      
 45 
     | 
    
         
            +
                        title: Ny undersökning
         
     | 
| 
       49 
46 
     | 
    
         
             
                      update:
         
     | 
| 
       50 
47 
     | 
    
         
             
                        invalid: Det gick inte att spara enkäten.
         
     | 
| 
       51 
48 
     | 
    
         
             
                        success: Enkäten har sparats.
         
     | 
| 
         @@ -54,14 +51,7 @@ sv: 
     | 
|
| 
       54 
51 
     | 
    
         
             
                  models:
         
     | 
| 
       55 
52 
     | 
    
         
             
                    survey:
         
     | 
| 
       56 
53 
     | 
    
         
             
                      fields:
         
     | 
| 
       57 
     | 
    
         
            -
                         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
                      subject: Svarsbekräftelse för formuläret %{questionnaire_title}
         
     | 
| 
       62 
     | 
    
         
            -
                    export_name: Enkätsvar
         
     | 
| 
       63 
     | 
    
         
            -
                  surveys:
         
     | 
| 
       64 
     | 
    
         
            -
                    answer:
         
     | 
| 
       65 
     | 
    
         
            -
                      invalid: Det gick inte att besvara enkäten.
         
     | 
| 
       66 
     | 
    
         
            -
                      spam_detected: Det gick inte att svara på formuläret. Kanske har du varit för snabb, kan du försöka igen?
         
     | 
| 
       67 
     | 
    
         
            -
                      success: Enkäten har besvarats.
         
     | 
| 
      
 54 
     | 
    
         
            +
                        published: Publicerad
         
     | 
| 
      
 55 
     | 
    
         
            +
                      published:
         
     | 
| 
      
 56 
     | 
    
         
            +
                        published: Publicerad
         
     | 
| 
      
 57 
     | 
    
         
            +
                        unpublished: Avpublicerad
         
     | 
    
        data/config/locales/tr-TR.yml
    CHANGED
    
    | 
         @@ -9,14 +9,9 @@ tr: 
     | 
|
| 
       9 
9 
     | 
    
         
             
                  decidim/surveys/survey:
         
     | 
| 
       10 
10 
     | 
    
         
             
                    one: Anket
         
     | 
| 
       11 
11 
     | 
    
         
             
                    other: Anketler
         
     | 
| 
       12 
     | 
    
         
            -
                  decidim/surveys/survey_answer:
         
     | 
| 
       13 
     | 
    
         
            -
                    one: Cevap
         
     | 
| 
       14 
     | 
    
         
            -
                    other: Cevaplar
         
     | 
| 
       15 
12 
     | 
    
         
             
              decidim:
         
     | 
| 
       16 
13 
     | 
    
         
             
                components:
         
     | 
| 
       17 
14 
     | 
    
         
             
                  surveys:
         
     | 
| 
       18 
     | 
    
         
            -
                    actions:
         
     | 
| 
       19 
     | 
    
         
            -
                      answer: Cevap
         
     | 
| 
       20 
15 
     | 
    
         
             
                    settings:
         
     | 
| 
       21 
16 
     | 
    
         
             
                      global:
         
     | 
| 
       22 
17 
     | 
    
         
             
                        announcement: Duyuru
         
     | 
| 
         @@ -34,26 +29,9 @@ tr: 
     | 
|
| 
       34 
29 
     | 
    
         
             
                      email_outro: Bu bildirimi, %{participatory_space_title} adlı kişiyi takip ettiğiniz için aldınız. Önceki bağlantıyı izleyerek bildirim almayı durdurabilirsiniz.
         
     | 
| 
       35 
30 
     | 
    
         
             
                      email_subject: '%{participatory_space_title} içinde yeni bir anket'
         
     | 
| 
       36 
31 
     | 
    
         
             
                      notification_title: <a href="%{participatory_space_url}">%{participatory_space_title} </a> içindeki anket <a href="%{resource_path}">%{resource_title} </a> şimdi açık.
         
     | 
| 
       37 
     | 
    
         
            -
                metrics:
         
     | 
| 
       38 
     | 
    
         
            -
                  survey_answers:
         
     | 
| 
       39 
     | 
    
         
            -
                    description: Katılımcılar tarafından cevaplanan anket sayısı
         
     | 
| 
       40 
     | 
    
         
            -
                    object: anketlerin cevapları
         
     | 
| 
       41 
     | 
    
         
            -
                    title: Anketlere verilen cevaplar
         
     | 
| 
       42 
32 
     | 
    
         
             
                surveys:
         
     | 
| 
       43 
33 
     | 
    
         
             
                  admin:
         
     | 
| 
       44 
     | 
    
         
            -
                    exports:
         
     | 
| 
       45 
     | 
    
         
            -
                      survey_user_answers: Ankete katılanların cevapları
         
     | 
| 
       46 
34 
     | 
    
         
             
                    surveys:
         
     | 
| 
       47 
35 
     | 
    
         
             
                      update:
         
     | 
| 
       48 
36 
     | 
    
         
             
                        invalid: Anketi kaydederken bir sorun oluştu.
         
     | 
| 
       49 
37 
     | 
    
         
             
                        success: Anket başarıyla kaydedildi.
         
     | 
| 
       50 
     | 
    
         
            -
                  survey_confirmation_mailer:
         
     | 
| 
       51 
     | 
    
         
            -
                    confirmation:
         
     | 
| 
       52 
     | 
    
         
            -
                      body: '%{participatory_space} alanındaki %{questionnaire_title} anketini başarıyla cevapladınız'
         
     | 
| 
       53 
     | 
    
         
            -
                      subject:
         
     | 
| 
       54 
     | 
    
         
            -
                    export_name: Anket cevapları
         
     | 
| 
       55 
     | 
    
         
            -
                  surveys:
         
     | 
| 
       56 
     | 
    
         
            -
                    answer:
         
     | 
| 
       57 
     | 
    
         
            -
                      invalid: Anketi cevaplarken bir sorun oluştu.
         
     | 
| 
       58 
     | 
    
         
            -
                      spam_detected: Formu yanıtlarken bir sorun oluştu. Belki çok hızlı davranmış olabilirsiniz, tekrar deneyebilir misiniz?
         
     | 
| 
       59 
     | 
    
         
            -
                      success: Anket başarıyla cevaplandı.
         
     | 
    
        data/config/locales/uk.yml
    CHANGED
    
    | 
         @@ -11,16 +11,9 @@ uk: 
     | 
|
| 
       11 
11 
     | 
    
         
             
                    few: Опитування
         
     | 
| 
       12 
12 
     | 
    
         
             
                    many: Опитувань
         
     | 
| 
       13 
13 
     | 
    
         
             
                    other: Опитувань
         
     | 
| 
       14 
     | 
    
         
            -
                  decidim/surveys/survey_answer:
         
     | 
| 
       15 
     | 
    
         
            -
                    one: Відповідь
         
     | 
| 
       16 
     | 
    
         
            -
                    few: Відповіді
         
     | 
| 
       17 
     | 
    
         
            -
                    many: Відповідей
         
     | 
| 
       18 
     | 
    
         
            -
                    other: Відповідей
         
     | 
| 
       19 
14 
     | 
    
         
             
              decidim:
         
     | 
| 
       20 
15 
     | 
    
         
             
                components:
         
     | 
| 
       21 
16 
     | 
    
         
             
                  surveys:
         
     | 
| 
       22 
     | 
    
         
            -
                    actions:
         
     | 
| 
       23 
     | 
    
         
            -
                      answer: Відповідь
         
     | 
| 
       24 
17 
     | 
    
         
             
                    settings:
         
     | 
| 
       25 
18 
     | 
    
         
             
                      global:
         
     | 
| 
       26 
19 
     | 
    
         
             
                        announcement: Оголошення
         
     | 
| 
         @@ -40,13 +33,7 @@ uk: 
     | 
|
| 
       40 
33 
     | 
    
         
             
                      notification_title: В <a href="%{participatory_space_url}">%{participatory_space_title}</a> почалось опитування <a href="%{resource_path}">%{resource_title}</a>.
         
     | 
| 
       41 
34 
     | 
    
         
             
                surveys:
         
     | 
| 
       42 
35 
     | 
    
         
             
                  admin:
         
     | 
| 
       43 
     | 
    
         
            -
                    exports:
         
     | 
| 
       44 
     | 
    
         
            -
                      survey_user_answers: Відповіді учасників на опитування
         
     | 
| 
       45 
36 
     | 
    
         
             
                    surveys:
         
     | 
| 
       46 
37 
     | 
    
         
             
                      update:
         
     | 
| 
       47 
38 
     | 
    
         
             
                        invalid: При спробі збереження цього опитування сталися помилки.
         
     | 
| 
       48 
39 
     | 
    
         
             
                        success: Опитування успішно збережено.
         
     | 
| 
       49 
     | 
    
         
            -
                  surveys:
         
     | 
| 
       50 
     | 
    
         
            -
                    answer:
         
     | 
| 
       51 
     | 
    
         
            -
                      invalid: При відповідях на опитування сталися помилки.
         
     | 
| 
       52 
     | 
    
         
            -
                      success: Опитування успішно пройдено.
         
     | 
    
        data/config/locales/zh-CN.yml
    CHANGED
    
    | 
         @@ -8,13 +8,9 @@ zh-CN: 
     | 
|
| 
       8 
8 
     | 
    
         
             
                models:
         
     | 
| 
       9 
9 
     | 
    
         
             
                  decidim/surveys/survey:
         
     | 
| 
       10 
10 
     | 
    
         
             
                    other: 调查
         
     | 
| 
       11 
     | 
    
         
            -
                  decidim/surveys/survey_answer:
         
     | 
| 
       12 
     | 
    
         
            -
                    other: 答案
         
     | 
| 
       13 
11 
     | 
    
         
             
              decidim:
         
     | 
| 
       14 
12 
     | 
    
         
             
                components:
         
     | 
| 
       15 
13 
     | 
    
         
             
                  surveys:
         
     | 
| 
       16 
     | 
    
         
            -
                    actions:
         
     | 
| 
       17 
     | 
    
         
            -
                      answer: 答案
         
     | 
| 
       18 
14 
     | 
    
         
             
                    settings:
         
     | 
| 
       19 
15 
     | 
    
         
             
                      global:
         
     | 
| 
       20 
16 
     | 
    
         
             
                        announcement: 通 知
         
     | 
| 
         @@ -32,20 +28,9 @@ zh-CN: 
     | 
|
| 
       32 
28 
     | 
    
         
             
                      email_outro: 您收到此通知是因为您正在关注 %{participatory_space_title}。您可以停止收到跟随上一个链接的通知。
         
     | 
| 
       33 
29 
     | 
    
         
             
                      email_subject: '%{participatory_space_title} 的新调查'
         
     | 
| 
       34 
30 
     | 
    
         
             
                      notification_title: <a href="%{resource_path}">%{resource_title}</a> 在 <a href="%{participatory_space_url}">%{participatory_space_title}</a> 中的调查现已打开。
         
     | 
| 
       35 
     | 
    
         
            -
                metrics:
         
     | 
| 
       36 
     | 
    
         
            -
                  survey_answers:
         
     | 
| 
       37 
     | 
    
         
            -
                    description: 参与者回答的调查次数
         
     | 
| 
       38 
     | 
    
         
            -
                    object: 调查答案
         
     | 
| 
       39 
     | 
    
         
            -
                    title: 对调查的答复
         
     | 
| 
       40 
31 
     | 
    
         
             
                surveys:
         
     | 
| 
       41 
32 
     | 
    
         
             
                  admin:
         
     | 
| 
       42 
     | 
    
         
            -
                    exports:
         
     | 
| 
       43 
     | 
    
         
            -
                      survey_user_answers: 调查参与者答案
         
     | 
| 
       44 
33 
     | 
    
         
             
                    surveys:
         
     | 
| 
       45 
34 
     | 
    
         
             
                      update:
         
     | 
| 
       46 
35 
     | 
    
         
             
                        invalid: 保存调查时出现问题。
         
     | 
| 
       47 
36 
     | 
    
         
             
                        success: 调查保存成功。
         
     | 
| 
       48 
     | 
    
         
            -
                  surveys:
         
     | 
| 
       49 
     | 
    
         
            -
                    answer:
         
     | 
| 
       50 
     | 
    
         
            -
                      invalid: 回答调查时出现问题。
         
     | 
| 
       51 
     | 
    
         
            -
                      success: 调查回答成功。
         
     | 
    
        data/config/locales/zh-TW.yml
    CHANGED
    
    | 
         @@ -8,13 +8,9 @@ zh-TW: 
     | 
|
| 
       8 
8 
     | 
    
         
             
                models:
         
     | 
| 
       9 
9 
     | 
    
         
             
                  decidim/surveys/survey:
         
     | 
| 
       10 
10 
     | 
    
         
             
                    other: 調查
         
     | 
| 
       11 
     | 
    
         
            -
                  decidim/surveys/survey_answer:
         
     | 
| 
       12 
     | 
    
         
            -
                    other: 回答
         
     | 
| 
       13 
11 
     | 
    
         
             
              decidim:
         
     | 
| 
       14 
12 
     | 
    
         
             
                components:
         
     | 
| 
       15 
13 
     | 
    
         
             
                  surveys:
         
     | 
| 
       16 
     | 
    
         
            -
                    actions:
         
     | 
| 
       17 
     | 
    
         
            -
                      answer: 回答
         
     | 
| 
       18 
14 
     | 
    
         
             
                    settings:
         
     | 
| 
       19 
15 
     | 
    
         
             
                      global:
         
     | 
| 
       20 
16 
     | 
    
         
             
                        announcement: 公告
         
     | 
| 
         @@ -32,29 +28,11 @@ zh-TW: 
     | 
|
| 
       32 
28 
     | 
    
         
             
                      email_outro: 你收到此通知是因為你正在追蹤 %{participatory_space_title}。你可以透過前面的連結停止接收通知。
         
     | 
| 
       33 
29 
     | 
    
         
             
                      email_subject: 在%{participatory_space_title} 中的新調查
         
     | 
| 
       34 
30 
     | 
    
         
             
                      notification_title: 現在開放在<a href="%{participatory_space_url}">%{participatory_space_title}</a>中的<a href="%{resource_path}">%{resource_title}</a>調查。
         
     | 
| 
       35 
     | 
    
         
            -
                metrics:
         
     | 
| 
       36 
     | 
    
         
            -
                  survey_answers:
         
     | 
| 
       37 
     | 
    
         
            -
                    description: 參與者回答調查的數量
         
     | 
| 
       38 
     | 
    
         
            -
                    object: 參與調查的回答
         
     | 
| 
       39 
     | 
    
         
            -
                    title: 參與調查的回答
         
     | 
| 
       40 
     | 
    
         
            -
                statistics:
         
     | 
| 
       41 
     | 
    
         
            -
                  answers_count: 回答
         
     | 
| 
       42 
31 
     | 
    
         
             
                surveys:
         
     | 
| 
       43 
32 
     | 
    
         
             
                  admin:
         
     | 
| 
       44 
     | 
    
         
            -
                    exports:
         
     | 
| 
       45 
     | 
    
         
            -
                      survey_user_answers: 參與者問卷回答
         
     | 
| 
       46 
33 
     | 
    
         
             
                    surveys:
         
     | 
| 
       47 
34 
     | 
    
         
             
                      update:
         
     | 
| 
       48 
35 
     | 
    
         
             
                        invalid: 儲存問卷時出現問題。
         
     | 
| 
       49 
36 
     | 
    
         
             
                        success: 問卷成功儲存
         
     | 
| 
       50 
37 
     | 
    
         
             
                  last_activity:
         
     | 
| 
       51 
38 
     | 
    
         
             
                    new_survey: '新問卷調查'
         
     | 
| 
       52 
     | 
    
         
            -
                  models:
         
     | 
| 
       53 
     | 
    
         
            -
                    survey:
         
     | 
| 
       54 
     | 
    
         
            -
                      fields:
         
     | 
| 
       55 
     | 
    
         
            -
                        answers: 回答
         
     | 
| 
       56 
     | 
    
         
            -
                  surveys:
         
     | 
| 
       57 
     | 
    
         
            -
                    answer:
         
     | 
| 
       58 
     | 
    
         
            -
                      invalid: 回答問卷時出現問題。
         
     | 
| 
       59 
     | 
    
         
            -
                      spam_detected: 回答表單時出現問題。也許您回答太快了,可以再試一次嗎?
         
     | 
| 
       60 
     | 
    
         
            -
                      success: 問卷回答成功。
         
     | 
| 
         @@ -0,0 +1,8 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class RenameAnswerToResponseInDecidimSurveys < ActiveRecord::Migration[7.0]
         
     | 
| 
      
 4 
     | 
    
         
            +
              def change
         
     | 
| 
      
 5 
     | 
    
         
            +
                rename_column :decidim_surveys_surveys, :allow_answers, :allow_responses
         
     | 
| 
      
 6 
     | 
    
         
            +
                rename_column :decidim_surveys_surveys, :allow_editing_answers, :allow_editing_responses
         
     | 
| 
      
 7 
     | 
    
         
            +
              end
         
     | 
| 
      
 8 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -7,8 +7,20 @@ module Decidim 
     | 
|
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                  description "A survey"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
      
 10 
     | 
    
         
            +
                  field :allow_editing_responses, GraphQL::Types::Boolean, "Whether this survey accepts editing responses or not.", null: true
         
     | 
| 
      
 11 
     | 
    
         
            +
                  field :allow_responses, GraphQL::Types::Boolean, "Whether this survey accepts responses or not.", null: true
         
     | 
| 
      
 12 
     | 
    
         
            +
                  field :allow_unregistered, GraphQL::Types::Boolean, "Whether this survey accepts answers or not.", null: true
         
     | 
| 
      
 13 
     | 
    
         
            +
                  field :announcement, Decidim::Core::TranslatedFieldType, "The announcement info for this survey", null: true
         
     | 
| 
      
 14 
     | 
    
         
            +
                  field :ends_at, Decidim::Core::DateTimeType, "The time this survey ends accepting answers", null: true
         
     | 
| 
       10 
15 
     | 
    
         
             
                  field :id, GraphQL::Types::ID, "The internal ID for this survey", null: false
         
     | 
| 
      
 16 
     | 
    
         
            +
                  field :published_at, Decidim::Core::DateTimeType, description: "The date and time this survey was published", null: true
         
     | 
| 
       11 
17 
     | 
    
         
             
                  field :questionnaire, Decidim::Forms::QuestionnaireType, "The questionnaire for this survey", null: true
         
     | 
| 
      
 18 
     | 
    
         
            +
                  field :starts_at, Decidim::Core::DateTimeType, "The time this survey starts accepting answers", null: true
         
     | 
| 
      
 19 
     | 
    
         
            +
                  field :url, GraphQL::Types::String, "The URL for this survey", null: false
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  def url
         
     | 
| 
      
 22 
     | 
    
         
            +
                    Decidim::ResourceLocatorPresenter.new(object).url
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
       12 
24 
     | 
    
         | 
| 
       13 
25 
     | 
    
         
             
                  def self.authorized?(object, context)
         
     | 
| 
       14 
26 
     | 
    
         
             
                    context[:survey] = object
         
     | 
| 
         @@ -10,28 +10,67 @@ module Decidim 
     | 
|
| 
       10 
10 
     | 
    
         
             
                  paths["lib/tasks"] = nil
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
                  routes do
         
     | 
| 
       13 
     | 
    
         
            -
                    get "/ 
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
                    get "/response_options", to: "questions/surveys#response_options", as: :response_options_survey
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                    resources :surveys do
         
     | 
| 
       15 
16 
     | 
    
         
             
                      member do
         
     | 
| 
       16 
     | 
    
         
            -
                        get :edit_questions
         
     | 
| 
       17 
     | 
    
         
            -
                        patch :update_questions
         
     | 
| 
       18 
17 
     | 
    
         
             
                        put :publish
         
     | 
| 
       19 
18 
     | 
    
         
             
                        put :unpublish
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                        namespace :questions do
         
     | 
| 
      
 21 
     | 
    
         
            +
                          get :edit_questions
         
     | 
| 
      
 22 
     | 
    
         
            +
                          patch :update_questions
         
     | 
| 
      
 23 
     | 
    
         
            +
                          get :edit
         
     | 
| 
      
 24 
     | 
    
         
            +
                          patch :update
         
     | 
| 
      
 25 
     | 
    
         
            +
                        end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                        namespace :settings do
         
     | 
| 
      
 28 
     | 
    
         
            +
                          get :edit
         
     | 
| 
      
 29 
     | 
    
         
            +
                          patch :update
         
     | 
| 
      
 30 
     | 
    
         
            +
                        end
         
     | 
| 
       20 
31 
     | 
    
         
             
                      end
         
     | 
| 
       21 
     | 
    
         
            -
                      resources : 
     | 
| 
      
 32 
     | 
    
         
            +
                      resources :responses, only: [:index, :show] do
         
     | 
| 
       22 
33 
     | 
    
         
             
                        member do
         
     | 
| 
       23 
34 
     | 
    
         
             
                          get :export_response
         
     | 
| 
       24 
35 
     | 
    
         
             
                        end
         
     | 
| 
       25 
36 
     | 
    
         
             
                      end
         
     | 
| 
       26 
     | 
    
         
            -
                      resources : 
     | 
| 
      
 37 
     | 
    
         
            +
                      resources :publish_responses, only: [:index, :update, :destroy]
         
     | 
| 
       27 
38 
     | 
    
         
             
                    end
         
     | 
| 
       28 
39 
     | 
    
         
             
                    root to: "surveys#index"
         
     | 
| 
       29 
40 
     | 
    
         
             
                  end
         
     | 
| 
       30 
41 
     | 
    
         | 
| 
      
 42 
     | 
    
         
            +
                  initializer "decidim_surveys_admin.menu" do
         
     | 
| 
      
 43 
     | 
    
         
            +
                    Decidim.menu :admin_surveys_menu do |menu|
         
     | 
| 
      
 44 
     | 
    
         
            +
                      responses_count = @survey.nil? ? 0 : Decidim::Forms::QuestionnaireParticipants.new(@survey.questionnaire).count_participants
         
     | 
| 
      
 45 
     | 
    
         
            +
                      responses_caption = I18n.t("responses", scope: "decidim.admin.menu.surveys_menu")
         
     | 
| 
      
 46 
     | 
    
         
            +
                      responses_caption += content_tag(:span, responses_count, class: "component-counter")
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                      menu.add_item :main_survey,
         
     | 
| 
      
 49 
     | 
    
         
            +
                                    I18n.t("main", scope: "decidim.admin.menu.surveys_menu"),
         
     | 
| 
      
 50 
     | 
    
         
            +
                                    @survey.nil? ? new_survey_path : Decidim::EngineRouter.admin_proxy(@survey.component).edit_survey_path(@survey),
         
     | 
| 
      
 51 
     | 
    
         
            +
                                    icon_name: "bill-line"
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                      menu.add_item :survey_questions_edit,
         
     | 
| 
      
 54 
     | 
    
         
            +
                                    I18n.t("questions", scope: "decidim.admin.menu.surveys_menu"),
         
     | 
| 
      
 55 
     | 
    
         
            +
                                    @survey.nil? ? "#" : Decidim::EngineRouter.admin_proxy(@survey.component).edit_questions_questions_survey_path(@survey),
         
     | 
| 
      
 56 
     | 
    
         
            +
                                    icon_name: "question-answer-line"
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                      menu.add_item :survey_responses_view,
         
     | 
| 
      
 59 
     | 
    
         
            +
                                    responses_caption.html_safe,
         
     | 
| 
      
 60 
     | 
    
         
            +
                                    @survey.nil? ? "#" : Decidim::EngineRouter.admin_proxy(@survey.component).survey_responses_path(@survey),
         
     | 
| 
      
 61 
     | 
    
         
            +
                                    icon_name: "draft-line"
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                      menu.add_item :survey_settings_edit,
         
     | 
| 
      
 64 
     | 
    
         
            +
                                    I18n.t("settings", scope: "decidim.admin.menu.surveys_menu"),
         
     | 
| 
      
 65 
     | 
    
         
            +
                                    @survey.nil? ? "#" : Decidim::EngineRouter.admin_proxy(@survey.component).edit_settings_survey_path(@survey),
         
     | 
| 
      
 66 
     | 
    
         
            +
                                    icon_name: "settings-4-line"
         
     | 
| 
      
 67 
     | 
    
         
            +
                    end
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
       31 
70 
     | 
    
         
             
                  initializer "decidim_surveys_admin.notifications.components" do
         
     | 
| 
       32 
71 
     | 
    
         
             
                    config.to_prepare do
         
     | 
| 
       33 
72 
     | 
    
         
             
                      Decidim::EventsManager.subscribe(/^decidim\.events\.components/) do |event_name, data|
         
     | 
| 
       34 
     | 
    
         
            -
                         
     | 
| 
      
 73 
     | 
    
         
            +
                        CleanSurveyResponsesJob.perform_later(event_name, data)
         
     | 
| 
       35 
74 
     | 
    
         
             
                      end
         
     | 
| 
       36 
75 
     | 
    
         
             
                    end
         
     | 
| 
       37 
76 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -12,40 +12,45 @@ Decidim.register_component(:surveys) do |component| 
     | 
|
| 
       12 
12 
     | 
    
         
             
              component.specific_data_importer_class_name = "Decidim::Surveys::DataImporter"
         
     | 
| 
       13 
13 
     | 
    
         
             
              component.query_type = "Decidim::Surveys::SurveysType"
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
              component.data_portable_entities = ["Decidim::Forms:: 
     | 
| 
      
 15 
     | 
    
         
            +
              component.data_portable_entities = ["Decidim::Forms::Response"]
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
              component.newsletter_participant_entities = ["Decidim::Forms:: 
     | 
| 
      
 17 
     | 
    
         
            +
              component.newsletter_participant_entities = ["Decidim::Forms::Response"]
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
              component.on(:before_destroy) do |instance|
         
     | 
| 
       20 
20 
     | 
    
         
             
                survey = Decidim::Surveys::Survey.find_by(decidim_component_id: instance.id)
         
     | 
| 
       21 
     | 
    
         
            -
                 
     | 
| 
      
 21 
     | 
    
         
            +
                survey_responses_for_component = Decidim::Forms::Response.where(questionnaire: survey.questionnaire)
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                raise "Cannot destroy this component when there are survey  
     | 
| 
      
 23 
     | 
    
         
            +
                raise "Cannot destroy this component when there are survey responses" if survey_responses_for_component.any?
         
     | 
| 
       24 
24 
     | 
    
         
             
              end
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
26 
     | 
    
         
             
              component.register_resource(:survey) do |resource|
         
     | 
| 
       27 
27 
     | 
    
         
             
                resource.model_class_name = "Decidim::Surveys::Survey"
         
     | 
| 
       28 
28 
     | 
    
         
             
                resource.card = "decidim/surveys/survey"
         
     | 
| 
       29 
     | 
    
         
            -
                resource.actions = %w( 
     | 
| 
      
 29 
     | 
    
         
            +
                resource.actions = %w(respond)
         
     | 
| 
       30 
30 
     | 
    
         
             
              end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
              component.register_stat :surveys_count, 
     | 
| 
      
 32 
     | 
    
         
            +
              component.register_stat :surveys_count,
         
     | 
| 
      
 33 
     | 
    
         
            +
                                      primary: true,
         
     | 
| 
      
 34 
     | 
    
         
            +
                                      priority: Decidim::StatsRegistry::MEDIUM_PRIORITY,
         
     | 
| 
      
 35 
     | 
    
         
            +
                                      sub_title: "responses",
         
     | 
| 
      
 36 
     | 
    
         
            +
                                      icon_name: "survey-line",
         
     | 
| 
      
 37 
     | 
    
         
            +
                                      tooltip_key: "surveys_count_tooltip" do |components, start_at, end_at|
         
     | 
| 
       33 
38 
     | 
    
         
             
                surveys = Decidim::Surveys::Survey.where(component: components)
         
     | 
| 
       34 
39 
     | 
    
         
             
                surveys = surveys.where(created_at: start_at..) if start_at.present?
         
     | 
| 
       35 
40 
     | 
    
         
             
                surveys = surveys.where(created_at: ..end_at) if end_at.present?
         
     | 
| 
       36 
     | 
    
         
            -
                surveys.count
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                 
     | 
| 
       41 
     | 
    
         
            -
                 
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                 
     | 
| 
      
 41 
     | 
    
         
            +
                first = surveys.count
         
     | 
| 
      
 42 
     | 
    
         
            +
                participatory_space_surveys = Decidim::Surveys::Survey.includes(:questionnaire).where(component: components)
         
     | 
| 
      
 43 
     | 
    
         
            +
                responses = Decidim::Forms::Response.where(questionnaire: participatory_space_surveys.map(&:questionnaire))
         
     | 
| 
      
 44 
     | 
    
         
            +
                responses = responses.where(created_at: start_at..) if start_at.present?
         
     | 
| 
      
 45 
     | 
    
         
            +
                responses = responses.where(created_at: ..end_at) if end_at.present?
         
     | 
| 
      
 46 
     | 
    
         
            +
                [
         
     | 
| 
      
 47 
     | 
    
         
            +
                  first,
         
     | 
| 
      
 48 
     | 
    
         
            +
                  responses.group(:session_token).count.size
         
     | 
| 
      
 49 
     | 
    
         
            +
                ]
         
     | 
| 
       45 
50 
     | 
    
         
             
              end
         
     | 
| 
       46 
51 
     | 
    
         | 
| 
       47 
52 
     | 
    
         
             
              # These actions permissions can be configured in the admin panel
         
     | 
| 
       48 
     | 
    
         
            -
              component.actions = %w( 
     | 
| 
      
 53 
     | 
    
         
            +
              component.actions = %w(respond)
         
     | 
| 
       49 
54 
     | 
    
         | 
| 
       50 
55 
     | 
    
         
             
              component.settings(:global) do |settings|
         
     | 
| 
       51 
56 
     | 
    
         
             
                settings.attribute :announcement, type: :text, translated: true, editor: true
         
     | 
| 
         @@ -55,15 +60,15 @@ Decidim.register_component(:surveys) do |component| 
     | 
|
| 
       55 
60 
     | 
    
         
             
                settings.attribute :announcement, type: :text, translated: true, editor: true
         
     | 
| 
       56 
61 
     | 
    
         
             
              end
         
     | 
| 
       57 
62 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
              component.exports : 
     | 
| 
      
 63 
     | 
    
         
            +
              component.exports :survey_user_responses do |exports|
         
     | 
| 
       59 
64 
     | 
    
         
             
                exports.collection do |f|
         
     | 
| 
       60 
65 
     | 
    
         
             
                  survey = Decidim::Surveys::Survey.find_by(component: f)
         
     | 
| 
       61 
     | 
    
         
            -
                  Decidim::Forms:: 
     | 
| 
      
 66 
     | 
    
         
            +
                  Decidim::Forms::QuestionnaireUserResponses.for(survey.questionnaire)
         
     | 
| 
       62 
67 
     | 
    
         
             
                end
         
     | 
| 
       63 
68 
     | 
    
         | 
| 
       64 
69 
     | 
    
         
             
                exports.formats %w(CSV JSON Excel FormPDF)
         
     | 
| 
       65 
70 
     | 
    
         | 
| 
       66 
     | 
    
         
            -
                exports.serializer Decidim::Forms:: 
     | 
| 
      
 71 
     | 
    
         
            +
                exports.serializer Decidim::Forms::UserResponsesSerializer
         
     | 
| 
       67 
72 
     | 
    
         
             
              end
         
     | 
| 
       68 
73 
     | 
    
         | 
| 
       69 
74 
     | 
    
         
             
              component.seeds do |participatory_space|
         
     | 
| 
         @@ -11,7 +11,7 @@ module Decidim 
     | 
|
| 
       11 
11 
     | 
    
         
             
                  routes do
         
     | 
| 
       12 
12 
     | 
    
         
             
                    resources :surveys, only: [:index, :show, :edit] do
         
     | 
| 
       13 
13 
     | 
    
         
             
                      member do
         
     | 
| 
       14 
     | 
    
         
            -
                        post : 
     | 
| 
      
 14 
     | 
    
         
            +
                        post :respond
         
     | 
| 
       15 
15 
     | 
    
         
             
                      end
         
     | 
| 
       16 
16 
     | 
    
         
             
                    end
         
     | 
| 
       17 
17 
     | 
    
         
             
                    root to: "surveys#index"
         
     | 
| 
         @@ -29,39 +29,22 @@ module Decidim 
     | 
|
| 
       29 
29 
     | 
    
         
             
                    end
         
     | 
| 
       30 
30 
     | 
    
         
             
                  end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
                  initializer "decidim_surveys. 
     | 
| 
       33 
     | 
    
         
            -
                    Decidim.metrics_registry.register(:survey_answers) do |metric_registry|
         
     | 
| 
       34 
     | 
    
         
            -
                      metric_registry.manager_class = "Decidim::Surveys::Metrics::AnswersMetricManage"
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                      metric_registry.settings do |settings|
         
     | 
| 
       37 
     | 
    
         
            -
                        settings.attribute :highlighted, type: :boolean, default: false
         
     | 
| 
       38 
     | 
    
         
            -
                        settings.attribute :scopes, type: :array, default: %w(participatory_process)
         
     | 
| 
       39 
     | 
    
         
            -
                        settings.attribute :weight, type: :integer, default: 5
         
     | 
| 
       40 
     | 
    
         
            -
                        settings.attribute :stat_block, type: :string, default: "small"
         
     | 
| 
       41 
     | 
    
         
            -
                      end
         
     | 
| 
       42 
     | 
    
         
            -
                    end
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                    Decidim.metrics_operation.register(:participants, :surveys) do |metric_operation|
         
     | 
| 
       45 
     | 
    
         
            -
                      metric_operation.manager_class = "Decidim::Surveys::Metrics::SurveyParticipantsMetricMeasure"
         
     | 
| 
       46 
     | 
    
         
            -
                    end
         
     | 
| 
       47 
     | 
    
         
            -
                  end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                  initializer "decidim_surveys.webpacker.assets_path" do
         
     | 
| 
      
 32 
     | 
    
         
            +
                  initializer "decidim_surveys.shakapacker.assets_path" do
         
     | 
| 
       50 
33 
     | 
    
         
             
                    Decidim.register_assets_path File.expand_path("app/packs", root)
         
     | 
| 
       51 
34 
     | 
    
         
             
                  end
         
     | 
| 
       52 
35 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
                  initializer "decidim_surveys. 
     | 
| 
      
 36 
     | 
    
         
            +
                  initializer "decidim_surveys.responses_email" do
         
     | 
| 
       54 
37 
     | 
    
         
             
                    config.to_prepare do
         
     | 
| 
       55 
     | 
    
         
            -
                      ActiveSupport::Notifications.subscribe("decidim.forms. 
     | 
| 
      
 38 
     | 
    
         
            +
                      ActiveSupport::Notifications.subscribe("decidim.forms.response_questionnaire:after") do |_event_name, data|
         
     | 
| 
       56 
39 
     | 
    
         
             
                        extra_data = data[:extra]
         
     | 
| 
       57 
40 
     | 
    
         
             
                        if data[:resource].questionnaire_for.instance_of?(::Decidim::Surveys::Survey)
         
     | 
| 
       58 
41 
     | 
    
         
             
                          component = data[:resource].questionnaire_for.component
         
     | 
| 
       59 
42 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
                           
     | 
| 
       61 
     | 
    
         
            -
                           
     | 
| 
      
 43 
     | 
    
         
            +
                          responses = Decidim::Forms::QuestionnaireUserResponses.for(data[:resource])
         
     | 
| 
      
 44 
     | 
    
         
            +
                          user_responses = responses.select { |a| a.first.session_token == extra_data[:session_token] }
         
     | 
| 
       62 
45 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
                          if component.manifest_name == "surveys" &&  
     | 
| 
       64 
     | 
    
         
            -
                            Decidim::Surveys::SurveyConfirmationMailer.confirmation(extra_data[:event_author], extra_data[:questionnaire],  
     | 
| 
      
 46 
     | 
    
         
            +
                          if component.manifest_name == "surveys" && user_responses.present?
         
     | 
| 
      
 47 
     | 
    
         
            +
                            Decidim::Surveys::SurveyConfirmationMailer.confirmation(extra_data[:event_author], extra_data[:questionnaire], user_responses).deliver_later
         
     | 
| 
       65 
48 
     | 
    
         
             
                          end
         
     | 
| 
       66 
49 
     | 
    
         
             
                        end
         
     | 
| 
       67 
50 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -14,13 +14,13 @@ module Decidim 
     | 
|
| 
       14 
14 
     | 
    
         
             
                  def call
         
     | 
| 
       15 
15 
     | 
    
         
             
                    component = create_component!
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                     
     | 
| 
      
 17 
     | 
    
         
            +
                    number_of_records.times do
         
     | 
| 
       18 
18 
     | 
    
         
             
                      questionnaire = create_questionnaire!(component:)
         
     | 
| 
       19 
19 
     | 
    
         
             
                      create_questions!(questionnaire:)
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
                      next if questionnaire.questionnaire_for. 
     | 
| 
      
 21 
     | 
    
         
            +
                      next if questionnaire.questionnaire_for.allow_responses
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                      rand(200).times {  
     | 
| 
      
 23 
     | 
    
         
            +
                      rand(200).times { create_responses!(questionnaire:) }
         
     | 
| 
       24 
24 
     | 
    
         
             
                    end
         
     | 
| 
       25 
25 
     | 
    
         
             
                  end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
         @@ -56,7 +56,7 @@ module Decidim 
     | 
|
| 
       56 
56 
     | 
    
         
             
                    params = {
         
     | 
| 
       57 
57 
     | 
    
         
             
                      component:,
         
     | 
| 
       58 
58 
     | 
    
         
             
                      questionnaire:,
         
     | 
| 
       59 
     | 
    
         
            -
                       
     | 
| 
      
 59 
     | 
    
         
            +
                      allow_responses: [true, false].sample,
         
     | 
| 
       60 
60 
     | 
    
         
             
                      published_at: Time.current
         
     | 
| 
       61 
61 
     | 
    
         
             
                    }
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
         @@ -71,9 +71,9 @@ module Decidim 
     | 
|
| 
       71 
71 
     | 
    
         
             
                  end
         
     | 
| 
       72 
72 
     | 
    
         | 
| 
       73 
73 
     | 
    
         
             
                  def create_questions!(questionnaire:)
         
     | 
| 
       74 
     | 
    
         
            -
                    %w( 
     | 
| 
      
 74 
     | 
    
         
            +
                    %w(short_response long_response files).each_with_index do |text_question_type, index|
         
     | 
| 
       75 
75 
     | 
    
         
             
                      Decidim::Forms::Question.create!(
         
     | 
| 
       76 
     | 
    
         
            -
                        mandatory: text_question_type == " 
     | 
| 
      
 76 
     | 
    
         
            +
                        mandatory: text_question_type == "short_response",
         
     | 
| 
       77 
77 
     | 
    
         
             
                        questionnaire:,
         
     | 
| 
       78 
78 
     | 
    
         
             
                        body: Decidim::Faker::Localized.paragraph,
         
     | 
| 
       79 
79 
     | 
    
         
             
                        question_type: text_question_type,
         
     | 
| 
         @@ -91,7 +91,7 @@ module Decidim 
     | 
|
| 
       91 
91 
     | 
    
         
             
                      )
         
     | 
| 
       92 
92 
     | 
    
         | 
| 
       93 
93 
     | 
    
         
             
                      3.times do
         
     | 
| 
       94 
     | 
    
         
            -
                        question. 
     | 
| 
      
 94 
     | 
    
         
            +
                        question.response_options.create!(body: Decidim::Faker::Localized.sentence)
         
     | 
| 
       95 
95 
     | 
    
         
             
                      end
         
     | 
| 
       96 
96 
     | 
    
         | 
| 
       97 
97 
     | 
    
         
             
                      # Files type questions do not support being conditionals for another questions
         
     | 
| 
         @@ -101,7 +101,7 @@ module Decidim 
     | 
|
| 
       101 
101 
     | 
    
         
             
                      question.display_conditions.create!(
         
     | 
| 
       102 
102 
     | 
    
         
             
                        condition_question: possible_condition_questions.sample,
         
     | 
| 
       103 
103 
     | 
    
         
             
                        question:,
         
     | 
| 
       104 
     | 
    
         
            -
                        condition_type: : 
     | 
| 
      
 104 
     | 
    
         
            +
                        condition_type: :responded,
         
     | 
| 
       105 
105 
     | 
    
         
             
                        mandatory: true
         
     | 
| 
       106 
106 
     | 
    
         
             
                      )
         
     | 
| 
       107 
107 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -115,7 +115,7 @@ module Decidim 
     | 
|
| 
       115 
115 
     | 
    
         
             
                      )
         
     | 
| 
       116 
116 
     | 
    
         | 
| 
       117 
117 
     | 
    
         
             
                      3.times do |position|
         
     | 
| 
       118 
     | 
    
         
            -
                        question. 
     | 
| 
      
 118 
     | 
    
         
            +
                        question.response_options.create!(body: Decidim::Faker::Localized.sentence)
         
     | 
| 
       119 
119 
     | 
    
         
             
                        question.matrix_rows.create!(body: Decidim::Faker::Localized.sentence, position:)
         
     | 
| 
       120 
120 
     | 
    
         
             
                      end
         
     | 
| 
       121 
121 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -128,77 +128,77 @@ module Decidim 
     | 
|
| 
       128 
128 
     | 
    
         
             
                    )
         
     | 
| 
       129 
129 
     | 
    
         
             
                  end
         
     | 
| 
       130 
130 
     | 
    
         | 
| 
       131 
     | 
    
         
            -
                  def  
     | 
| 
      
 131 
     | 
    
         
            +
                  def create_responses!(questionnaire:, user: nil)
         
     | 
| 
       132 
132 
     | 
    
         
             
                    user = find_or_initialize_user_by(email: "survey-#{questionnaire.id}-#{rand(1_000_000)}@example.org") if user.nil?
         
     | 
| 
       133 
133 
     | 
    
         | 
| 
       134 
     | 
    
         
            -
                     
     | 
| 
      
 134 
     | 
    
         
            +
                    response_options = {
         
     | 
| 
       135 
135 
     | 
    
         
             
                      user:,
         
     | 
| 
       136 
136 
     | 
    
         
             
                      questionnaire:,
         
     | 
| 
       137 
     | 
    
         
            -
                      session_token: Digest:: 
     | 
| 
      
 137 
     | 
    
         
            +
                      session_token: Digest::SHA256.hexdigest("#{user.id}-#{Rails.application.secret_key_base}"),
         
     | 
| 
       138 
138 
     | 
    
         
             
                      ip_hash: Faker::Internet.device_token.slice(0, 24)
         
     | 
| 
       139 
139 
     | 
    
         
             
                    }
         
     | 
| 
       140 
140 
     | 
    
         | 
| 
       141 
141 
     | 
    
         
             
                    questionnaire.questions.each do |question|
         
     | 
| 
       142 
142 
     | 
    
         
             
                      case question.question_type
         
     | 
| 
       143 
     | 
    
         
            -
                      when " 
     | 
| 
       144 
     | 
    
         
            -
                         
     | 
| 
      
 143 
     | 
    
         
            +
                      when "short_response", "long_response"
         
     | 
| 
      
 144 
     | 
    
         
            +
                        create_response_for_text_question_type!(response_options.merge({ question: }))
         
     | 
| 
       145 
145 
     | 
    
         
             
                      when "single_option", "multiple_option"
         
     | 
| 
       146 
     | 
    
         
            -
                         
     | 
| 
      
 146 
     | 
    
         
            +
                        create_response_for_multiple_choice_question_type(response_options.merge({ question: }))
         
     | 
| 
       147 
147 
     | 
    
         
             
                      when "sorting"
         
     | 
| 
       148 
     | 
    
         
            -
                         
     | 
| 
      
 148 
     | 
    
         
            +
                        create_response_for_sorting_question_type(response_options.merge({ question: }))
         
     | 
| 
       149 
149 
     | 
    
         
             
                      when "matrix_single", "matrix_multiple"
         
     | 
| 
       150 
     | 
    
         
            -
                         
     | 
| 
      
 150 
     | 
    
         
            +
                        create_response_for_matrix_question_type(response_options.merge({ question: }))
         
     | 
| 
       151 
151 
     | 
    
         
             
                      end
         
     | 
| 
       152 
152 
     | 
    
         
             
                    end
         
     | 
| 
       153 
153 
     | 
    
         
             
                  rescue ActiveRecord::RecordInvalid
         
     | 
| 
       154 
154 
     | 
    
         
             
                    # Silently ignore the error as we do not care if the user already exists
         
     | 
| 
       155 
155 
     | 
    
         
             
                  end
         
     | 
| 
       156 
156 
     | 
    
         | 
| 
       157 
     | 
    
         
            -
                  def  
     | 
| 
       158 
     | 
    
         
            -
                    Decidim::Forms:: 
     | 
| 
      
 157 
     | 
    
         
            +
                  def create_response_for_text_question_type!(options)
         
     | 
| 
      
 158 
     | 
    
         
            +
                    Decidim::Forms::Response.create!(
         
     | 
| 
       159 
159 
     | 
    
         
             
                      **options, body: ::Faker::Lorem.paragraph(sentence_count: 1)
         
     | 
| 
       160 
160 
     | 
    
         
             
                    )
         
     | 
| 
       161 
161 
     | 
    
         
             
                  end
         
     | 
| 
       162 
162 
     | 
    
         | 
| 
       163 
     | 
    
         
            -
                  def  
     | 
| 
       164 
     | 
    
         
            -
                     
     | 
| 
       165 
     | 
    
         
            -
                     
     | 
| 
       166 
     | 
    
         
            -
                    available_positions = (0..( 
     | 
| 
      
 163 
     | 
    
         
            +
                  def create_response_for_sorting_question_type(options)
         
     | 
| 
      
 164 
     | 
    
         
            +
                    response = Decidim::Forms::Response.create!(**options)
         
     | 
| 
      
 165 
     | 
    
         
            +
                    response_options = options[:question].response_options
         
     | 
| 
      
 166 
     | 
    
         
            +
                    available_positions = (0..(response_options.size - 1)).to_a
         
     | 
| 
       167 
167 
     | 
    
         | 
| 
       168 
     | 
    
         
            -
                     
     | 
| 
      
 168 
     | 
    
         
            +
                    response_options.each do |response_option|
         
     | 
| 
       169 
169 
     | 
    
         
             
                      position = available_positions.sample
         
     | 
| 
       170 
     | 
    
         
            -
                      body =  
     | 
| 
      
 170 
     | 
    
         
            +
                      body = response_option[I18n.locale]
         
     | 
| 
       171 
171 
     | 
    
         | 
| 
       172 
     | 
    
         
            -
                      Decidim::Forms:: 
     | 
| 
       173 
     | 
    
         
            -
                         
     | 
| 
       174 
     | 
    
         
            -
                         
     | 
| 
      
 172 
     | 
    
         
            +
                      Decidim::Forms::ResponseChoice.create!(
         
     | 
| 
      
 173 
     | 
    
         
            +
                        response:,
         
     | 
| 
      
 174 
     | 
    
         
            +
                        response_option:,
         
     | 
| 
       175 
175 
     | 
    
         
             
                        body:,
         
     | 
| 
       176 
176 
     | 
    
         
             
                        position:
         
     | 
| 
       177 
177 
     | 
    
         
             
                      )
         
     | 
| 
       178 
178 
     | 
    
         
             
                    end
         
     | 
| 
       179 
179 
     | 
    
         
             
                  end
         
     | 
| 
       180 
180 
     | 
    
         | 
| 
       181 
     | 
    
         
            -
                  def  
     | 
| 
       182 
     | 
    
         
            -
                     
     | 
| 
       183 
     | 
    
         
            -
                     
     | 
| 
       184 
     | 
    
         
            -
                    body =  
     | 
| 
      
 181 
     | 
    
         
            +
                  def create_response_for_multiple_choice_question_type(options)
         
     | 
| 
      
 182 
     | 
    
         
            +
                    response = Decidim::Forms::Response.create!(**options)
         
     | 
| 
      
 183 
     | 
    
         
            +
                    response_option = options[:question].response_options.sample
         
     | 
| 
      
 184 
     | 
    
         
            +
                    body = response_option[I18n.locale]
         
     | 
| 
       185 
185 
     | 
    
         | 
| 
       186 
     | 
    
         
            -
                    Decidim::Forms:: 
     | 
| 
       187 
     | 
    
         
            -
                       
     | 
| 
       188 
     | 
    
         
            -
                       
     | 
| 
      
 186 
     | 
    
         
            +
                    Decidim::Forms::ResponseChoice.create!(
         
     | 
| 
      
 187 
     | 
    
         
            +
                      response:,
         
     | 
| 
      
 188 
     | 
    
         
            +
                      response_option:,
         
     | 
| 
       189 
189 
     | 
    
         
             
                      body:
         
     | 
| 
       190 
190 
     | 
    
         
             
                    )
         
     | 
| 
       191 
191 
     | 
    
         
             
                  end
         
     | 
| 
       192 
192 
     | 
    
         | 
| 
       193 
     | 
    
         
            -
                  def  
     | 
| 
       194 
     | 
    
         
            -
                     
     | 
| 
       195 
     | 
    
         
            -
                     
     | 
| 
      
 193 
     | 
    
         
            +
                  def create_response_for_matrix_question_type(options)
         
     | 
| 
      
 194 
     | 
    
         
            +
                    response = Decidim::Forms::Response.create!(**options)
         
     | 
| 
      
 195 
     | 
    
         
            +
                    response_option = options[:question].response_options.sample
         
     | 
| 
       196 
196 
     | 
    
         
             
                    matrix_row = options[:question].matrix_rows.sample
         
     | 
| 
       197 
     | 
    
         
            -
                    body =  
     | 
| 
      
 197 
     | 
    
         
            +
                    body = response_option[I18n.locale]
         
     | 
| 
       198 
198 
     | 
    
         | 
| 
       199 
     | 
    
         
            -
                    Decidim::Forms:: 
     | 
| 
       200 
     | 
    
         
            -
                       
     | 
| 
       201 
     | 
    
         
            -
                       
     | 
| 
      
 199 
     | 
    
         
            +
                    Decidim::Forms::ResponseChoice.create!(
         
     | 
| 
      
 200 
     | 
    
         
            +
                      response:,
         
     | 
| 
      
 201 
     | 
    
         
            +
                      response_option:,
         
     | 
| 
       202 
202 
     | 
    
         
             
                      matrix_row:,
         
     | 
| 
       203 
203 
     | 
    
         
             
                      body:
         
     | 
| 
       204 
204 
     | 
    
         
             
                    )
         
     | 
| 
         @@ -27,11 +27,11 @@ FactoryBot.define do 
     | 
|
| 
       27 
27 
     | 
    
         
             
                end
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
                trait :allow_edit do
         
     | 
| 
       30 
     | 
    
         
            -
                   
     | 
| 
      
 30 
     | 
    
         
            +
                  allow_editing_responses { true }
         
     | 
| 
       31 
31 
     | 
    
         
             
                end
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
                trait : 
     | 
| 
       34 
     | 
    
         
            -
                   
     | 
| 
      
 33 
     | 
    
         
            +
                trait :allow_responses do
         
     | 
| 
      
 34 
     | 
    
         
            +
                  allow_responses { true }
         
     | 
| 
       35 
35 
     | 
    
         
             
                end
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
37 
     | 
    
         
             
                trait :allow_unregistered do
         
     |