decidim-surveys 0.19.1 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5bf3b75387df3baa5f23a051b8c6c3141e4de0b50a318b598ddf921bc16c68e
4
- data.tar.gz: a49fcdd21d45cbcd42c0a8b87a97fd44e6c4ab0f5fe862ff68520fc569fd6715
3
+ metadata.gz: 4dd661081971e6b292d2f5e02e8cf550fdb1bda49362457e58d54c70cf9e8fe7
4
+ data.tar.gz: 9175ee414a9cb29703776e94d4c669eeb0832ba661d293fe020fd06dee50a6fb
5
5
  SHA512:
6
- metadata.gz: 58e2ec2f61f751056ec1f0f4337a3dfe10bef9916f9c8f13c309fde6b95b3b15e3bdf9db116138ce651bb67ccda829af2bc43ea27e4d585500d706b415590396
7
- data.tar.gz: 1734f209975336d6af102216a05554eb857154b2825974a67498f50c7e0373d82e5011c7b6cfcd93507fb3ecf4204ae55ff273d0d9b3ab3ff2096b009f8473af
6
+ metadata.gz: f3023f2d94690c36c060d16b77cc97dea7e8c4565aee66259240d2483043bf32c5eca35d0020a7f15f1388e4ccbfdb3357dc2d1059599addd26cfb7c07178d1f
7
+ data.tar.gz: 3083fb86f2f15ba9c260244b621e8e97f2e475b47f8c9726a02c7ee31b1634ca6bf9da969bd6b9ffaa3e53a7c76bc609e518cc54d10fb53a4d868c2a1604c043
@@ -7,7 +7,7 @@ module Decidim
7
7
  include Decidim::Forms::Concerns::HasQuestionnaire
8
8
  helper Decidim::Surveys::SurveyHelper
9
9
 
10
- delegate :allow_answers?, to: :current_settings
10
+ delegate :allow_answers?, :allow_unregistered?, to: :current_settings
11
11
 
12
12
  before_action :check_permissions
13
13
 
@@ -4,7 +4,7 @@ module Decidim
4
4
  module Surveys
5
5
  class Permissions < Decidim::DefaultPermissions
6
6
  def permissions
7
- return permission_action unless user
7
+ return permission_action unless user || context[:current_settings].allow_unregistered?
8
8
 
9
9
  return Decidim::Surveys::Admin::Permissions.new(user, permission_action, context).permissions if permission_action.scope == :admin
10
10
  return permission_action if permission_action.scope != :public
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Surveys
5
+ # Importer for Surveys specific data (this is, its questionnaire).
6
+ class DataImporter < Decidim::Importers::Importer
7
+ def initialize(component)
8
+ @component = component
9
+ end
10
+
11
+ # Public: Creates a new Decidim::Surveys::Survey and Decidim::Forms::Questionnaire associated to the given +component+
12
+ # for each serialized survey object.
13
+ # It imports the whole tree of Survey->Questionnaire->questions->answer_options.
14
+ #
15
+ # serialized - The Hash of attributes for the Questionnaire and its relations.
16
+ # user - The +user+ that is performing this action
17
+ #
18
+ # Returns the ser.
19
+ def import(serialized, user)
20
+ ActiveRecord::Base.transaction do
21
+ # we duplicate so that we can delete without affecting the received Hash
22
+ serialized.dup.collect do |serialized_survey|
23
+ import_survey(serialized_survey, user)
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ # Returns a persisted Survey instance build from +serialized_survey+.
31
+ def import_survey(serialized_survey, user)
32
+ serialized_survey = serialized_survey.with_indifferent_access
33
+ survey = build_survey(serialized_survey)
34
+ serialized_questionnaire = serialized_survey[:questionnaire]
35
+ serialized_questions = serialized_questionnaire.delete(:questions)
36
+
37
+ questionnaire = build_questionnaire(survey, serialized_questionnaire)
38
+ Decidim.traceability.perform_action!(:create, Decidim::Surveys::Survey, user) do
39
+ survey.save!
40
+ survey
41
+ end
42
+ import_questions(questionnaire, serialized_questions)
43
+ survey
44
+ end
45
+
46
+ def build_survey(_serialized)
47
+ Survey.new(component: @component)
48
+ end
49
+
50
+ # Builds a Decidim::Forms::Questionnaire with all its questions and answer_options.
51
+ def build_questionnaire(survey, serialized_questionnaire)
52
+ survey.build_questionnaire(serialized_questionnaire.except(:id, :published_at))
53
+ end
54
+
55
+ def import_questions(questionnaire, serialized_questions)
56
+ serialized_questions.each do |serialized_question|
57
+ serialized_answer_options = serialized_question.delete(:answer_options)
58
+ question = questionnaire.questions.create!(serialized_question.except(:id, :created_at, :updated_at))
59
+ serialized_answer_options.each do |serialized_answer_option|
60
+ question.answer_options.create!(serialized_answer_option.except(:id, :created_at, :updated_at))
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Surveys
5
+ # This class serializes the specific data in each Survey.
6
+ # This is `Questionnaire->questions->answer_options` but not `answers`
7
+ # and `answer_choices`.
8
+ class DataSerializer < Decidim::Exporters::Serializer
9
+ # Returns: Array of Decidim::Forms::Questionnaire as a json hash,
10
+ # or nil if none exists.
11
+ def serialize
12
+ component = resource
13
+ surveys = Decidim::Surveys::Survey.where(component: component)
14
+ surveys.collect do |survey|
15
+ next if survey.questionnaire.nil?
16
+
17
+ json = serialize_survey(survey)
18
+ json.with_indifferent_access.merge(survey_id: survey.id)
19
+ end
20
+ end
21
+
22
+ def serialize_survey(survey)
23
+ questionnaire = survey.questionnaire
24
+ questionnaire_json = questionnaire.attributes.as_json
25
+ questionnaire_json[:questions] = serialize_questions(questionnaire.questions.order(:position))
26
+ json = survey.attributes.as_json
27
+ json[:questionnaire] = questionnaire_json
28
+ json
29
+ end
30
+
31
+ def serialize_questions(questions)
32
+ questions.collect do |question|
33
+ json = question.attributes.as_json
34
+ json[:answer_options] = serialize_answer_options(question.answer_options)
35
+ json
36
+ end
37
+ end
38
+
39
+ def serialize_answer_options(answer_options)
40
+ answer_options.collect do |option|
41
+ option.attributes.as_json
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -30,6 +30,7 @@ ar:
30
30
  announcement: إعلان
31
31
  step:
32
32
  allow_answers: السماح بالإجابات
33
+ allow_unregistered: السماح للمستخدمين غير المسجَّلِين بالإجابة على استطلاع الرأي
33
34
  announcement: إعلان
34
35
  events:
35
36
  surveys:
@@ -22,6 +22,8 @@ ca:
22
22
  announcement: Avís
23
23
  step:
24
24
  allow_answers: Permetre respostes
25
+ allow_unregistered: Permet a usuaris no registrats contestar l'enquesta
26
+ allow_unregistered_help: Si s'activa, no caldrà identificar-se per a contestar l'enquesta. Això pot comportar que les dades siguin poc fiables i serà més vulnerable a atacs automatitzats. Utilitzeu-ho amb cura!
25
27
  announcement: Avís
26
28
  events:
27
29
  surveys:
@@ -53,4 +55,5 @@ ca:
53
55
  surveys:
54
56
  answer:
55
57
  invalid: S'ha produït un error en respondre l'enquesta.
58
+ spam_detected: Hi ha hagut un problema contestant el formulari. Potser has estat massa ràpid, ho pots tornar a intentar?
56
59
  success: Enquesta resposta correctament.
@@ -26,6 +26,8 @@ cs:
26
26
  announcement: Oznámení
27
27
  step:
28
28
  allow_answers: Povolte odpovědi
29
+ allow_unregistered: Umožnit neregistrovaným uživatelům odpovědět na průzkum
30
+ allow_unregistered_help: Pokud je aktivní, nebude vyžadován žádný přihlašovací postup, aby šlo odpovědět na průzkum, což může vést k slabým nebo nespolehlivým údajům a bude náchylnější k automatizovaným útokům. Používejte obezřetně!
29
31
  announcement: Oznámení
30
32
  events:
31
33
  surveys:
@@ -57,4 +59,5 @@ cs:
57
59
  surveys:
58
60
  answer:
59
61
  invalid: Při odpovědi na průzkum došlo k chybám.
62
+ spam_detected: Při vyplňování formuláře došlo k potížím. Možná jste byli příliš rychlí, můžete to zkusit znovu?
60
63
  success: Průzkum úspěšně odpověděl.
@@ -23,6 +23,8 @@ en:
23
23
  announcement: Announcement
24
24
  step:
25
25
  allow_answers: Allow answers
26
+ allow_unregistered: Allow unregistered users to answer the survey
27
+ allow_unregistered_help: If active, no login will be required in order to answer the survey. This may lead to poor or unreliable data and it will be more vulnerable to automated attacks. Use with caution!
26
28
  announcement: Announcement
27
29
  events:
28
30
  surveys:
@@ -54,4 +56,5 @@ en:
54
56
  surveys:
55
57
  answer:
56
58
  invalid: There was a problem answering the survey.
59
+ spam_detected: There was a problem answering the form. Maybe you've been too quick, can you try again?
57
60
  success: Survey successfully answered.
@@ -22,6 +22,8 @@ fi-pl:
22
22
  announcement: Ilmoitus
23
23
  step:
24
24
  allow_answers: Salli vastaukset
25
+ allow_unregistered: Salli rekisteröitymättömien käyttäjien vastata tähän kyselyyn
26
+ allow_unregistered_help: Mikäli tämä asetus on päällä, käyttäjien ei tarvitse kirjautua sisään vastatakseen kyselyyn. Tämä voi johtaa heikkolaatuiseen tai epäluotettavaan tietoon ja tekee automaattisista hyökkäyksistä helpompaa. Käytä harkiten!
25
27
  announcement: Ilmoitus
26
28
  events:
27
29
  surveys:
@@ -53,4 +55,5 @@ fi-pl:
53
55
  surveys:
54
56
  answer:
55
57
  invalid: Kyselyyn vastaaminen epäonnistui.
58
+ spam_detected: Kyselyn vastaamisessa tapahtui virhe. Ehkä olit liian nopea, voisitko yrittää uudestaan?
56
59
  success: Kyselyyn vastattu onnistuneesti.
@@ -22,6 +22,8 @@ fi:
22
22
  announcement: Ilmoitus
23
23
  step:
24
24
  allow_answers: Salli vastaukset
25
+ allow_unregistered: Salli rekisteröitymättömien käyttäjien vastata tähän kyselyyn
26
+ allow_unregistered_help: Mikäli tämä asetus on päällä, käyttäjien ei tarvitse kirjautua sisään vastatakseen kyselyyn. Tämä voi johtaa heikkolaatuiseen tai epäluotettavaan tietoon ja tekee automaattisista hyökkäyksistä helpompaa. Käytä harkiten!
25
27
  announcement: Ilmoitus
26
28
  events:
27
29
  surveys:
@@ -53,4 +55,5 @@ fi:
53
55
  surveys:
54
56
  answer:
55
57
  invalid: Kyselyyn vastaaminen epäonnistui.
58
+ spam_detected: Kyselyn vastaamisessa tapahtui virhe. Ehkä olit liian nopea, voisitko yrittää uudestaan?
56
59
  success: Kyselyyn vastaaminen onnistui.
@@ -22,6 +22,8 @@ fr:
22
22
  announcement: Annonce
23
23
  step:
24
24
  allow_answers: Autoriser les réponses
25
+ allow_unregistered: Autoriser les utilisateurs non inscrits à répondre à l'enquête
26
+ allow_unregistered_help: Si activé, aucun login ne sera nécessaire pour répondre à l'enquête. Cela peut conduire à des données pauvres ou non fiables et rend plus vulnérable aux attaques automatiques. A utiliser avec précaution !
25
27
  announcement: Annonce
26
28
  events:
27
29
  surveys:
@@ -53,4 +55,5 @@ fr:
53
55
  surveys:
54
56
  answer:
55
57
  invalid: Votre réponse à l'enquête comporte des erreurs.
58
+ spam_detected: Il y a eu un problème lors de la réponse au questionnaire. Peut-être avez-vous été trop rapide, pouvez-vous réessayer ?
56
59
  success: Votre réponse à l'enquête a bien été enregistrée.
@@ -22,6 +22,8 @@ hu:
22
22
  announcement: Közlemény
23
23
  step:
24
24
  allow_answers: Válaszok engedélyezése
25
+ allow_unregistered: Nem regisztrált felhasználók számára a kérdőív kitöltésének engedélyezése
26
+ allow_unregistered_help: Amennyiben aktív, nem szükséges a bejelentkezés a kérdőív kitöltéséhez. Ez megbízhatatlan, kevésbé hiteles adatokhoz vezethet és sérülékenyebbé teszi a rendszert az automatizált támadásokkal szemben. Óvatosan használjuk!
25
27
  announcement: Közlemény
26
28
  events:
27
29
  surveys:
@@ -53,4 +55,5 @@ hu:
53
55
  surveys:
54
56
  answer:
55
57
  invalid: Hiba történt a felmérés megválaszolása során.
58
+ spam_detected: Probléma történt az űrlap megválaszolása során. Lehet, hogy túl gyorsan próbálkoztál, megpróbálnád újra?
56
59
  success: Felmérés kitöltése sikeres.
@@ -22,6 +22,8 @@ it:
22
22
  announcement: Annuncio
23
23
  step:
24
24
  allow_answers: Consenti risposte
25
+ allow_unregistered: Consenti agli utenti non registrati di rispondere al sondaggio
26
+ allow_unregistered_help: Se attivo, nessun login sarà richiesto per rispondere all'indagine. Questo può portare a dati inaffidabili e sarà più vulnerabile agli attacchi automatizzati. Utilizzare con cautela!
25
27
  announcement: Annuncio
26
28
  events:
27
29
  surveys:
@@ -53,4 +55,5 @@ it:
53
55
  surveys:
54
56
  answer:
55
57
  invalid: Ci sono stati degli errori durante il salvataggio dell'indagine.
58
+ spam_detected: C'è stato un problema nella risposta al modulo. Forse sei stato troppo veloce, puoi riprovare?
56
59
  success: Il questionario è stato salvato correttamente.
@@ -22,6 +22,8 @@ nl:
22
22
  announcement: Aankondiging
23
23
  step:
24
24
  allow_answers: Antwoorden toestaan
25
+ allow_unregistered: Sta niet-geregistreerde gebruikers toe om de enquête te beantwoorden
26
+ allow_unregistered_help: Een login zal dan niet nodig zijn om de vragen te beantwoorden. De bevraging zal daardoor kwetsbaarder zijn voor geautomatiseerde aanvallen wat kan leiden tot onbetrouwbare resultaten. Wees voorzichtig !
25
27
  announcement: Aankondiging
26
28
  events:
27
29
  surveys:
@@ -53,4 +55,5 @@ nl:
53
55
  surveys:
54
56
  answer:
55
57
  invalid: Er zijn fouten opgetreden bij het opslaan van de pagina.
58
+ spam_detected: Er was een probleem bij het beantwoorden van het formulier. Misschien bent u te snel geweest, kunt u het opnieuw proberen?
56
59
  success: Enquête met succes beantwoord.
@@ -18,6 +18,8 @@
18
18
  announcement: Kunngjøring
19
19
  step:
20
20
  allow_answers: Tillat svar
21
+ allow_unregistered: Tillat uregistrerte brukere å svare på undersøkelsen
22
+ allow_unregistered_help: Hvis aktiv, er det ikke nødvendig med innlogging for å svare på undersøkelsen. Dette kan føre til dårlige eller upålitelig data, og den vil være mer sårbare for automatiserte angrep. Bruk med forsiktighet!
21
23
  announcement: Kunngjøring
22
24
  events:
23
25
  surveys:
@@ -8,6 +8,9 @@ Decidim.register_component(:surveys) do |component|
8
8
  component.icon = "decidim/surveys/icon.svg"
9
9
  component.stylesheet = "decidim/surveys/surveys"
10
10
  component.permissions_class_name = "Decidim::Surveys::Permissions"
11
+ component.serializes_specific_data = true
12
+ component.specific_data_serializer_class_name = "Decidim::Surveys::DataSerializer"
13
+ component.specific_data_importer_class_name = "Decidim::Surveys::DataImporter"
11
14
 
12
15
  component.on(:copy) do |context|
13
16
  Decidim::Surveys::CreateSurvey.call(context[:new_component]) do
@@ -44,7 +47,7 @@ Decidim.register_component(:surveys) do |component|
44
47
  answers = Decidim::Forms::Answer.where(questionnaire: surveys.map(&:questionnaire))
45
48
  answers = answers.where("created_at >= ?", start_at) if start_at.present?
46
49
  answers = answers.where("created_at <= ?", end_at) if end_at.present?
47
- answers.group(:decidim_user_id).count.size
50
+ answers.group(:session_token).count.size
48
51
  end
49
52
 
50
53
  # These actions permissions can be configured in the admin panel
@@ -56,6 +59,7 @@ Decidim.register_component(:surveys) do |component|
56
59
 
57
60
  component.settings(:step) do |settings|
58
61
  settings.attribute :allow_answers, type: :boolean, default: false
62
+ settings.attribute :allow_unregistered, type: :boolean, default: false
59
63
  settings.attribute :announcement, type: :text, translated: true, editor: true
60
64
  end
61
65
 
@@ -11,7 +11,7 @@ FactoryBot.define do
11
11
  participatory_space { create(:participatory_process, :with_steps) }
12
12
  end
13
13
 
14
- factory :survey, class: "Decidim::Surveys::Survey" do
14
+ factory :survey, class: Decidim::Surveys::Survey do
15
15
  questionnaire { build(:questionnaire) }
16
16
  component { build(:surveys_component) }
17
17
  end
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-surveys version.
5
5
  module Surveys
6
6
  def self.version
7
- "0.19.1"
7
+ "0.20.0"
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-surveys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.1
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-12-13 00:00:00.000000000 Z
13
+ date: 2020-01-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: decidim-core
@@ -18,70 +18,70 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.19.1
21
+ version: 0.20.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 0.19.1
28
+ version: 0.20.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: decidim-forms
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - '='
34
34
  - !ruby/object:Gem::Version
35
- version: 0.19.1
35
+ version: 0.20.0
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - '='
41
41
  - !ruby/object:Gem::Version
42
- version: 0.19.1
42
+ version: 0.20.0
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: decidim-admin
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - '='
48
48
  - !ruby/object:Gem::Version
49
- version: 0.19.1
49
+ version: 0.20.0
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - '='
55
55
  - !ruby/object:Gem::Version
56
- version: 0.19.1
56
+ version: 0.20.0
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: decidim-dev
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - '='
62
62
  - !ruby/object:Gem::Version
63
- version: 0.19.1
63
+ version: 0.20.0
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - '='
69
69
  - !ruby/object:Gem::Version
70
- version: 0.19.1
70
+ version: 0.20.0
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: decidim-participatory_processes
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - '='
76
76
  - !ruby/object:Gem::Version
77
- version: 0.19.1
77
+ version: 0.20.0
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - '='
83
83
  - !ruby/object:Gem::Version
84
- version: 0.19.1
84
+ version: 0.20.0
85
85
  description: A surveys component for decidim's participatory spaces.
86
86
  email:
87
87
  - josepjaume@gmail.com
@@ -110,6 +110,8 @@ files:
110
110
  - app/permissions/decidim/surveys/permissions.rb
111
111
  - app/queries/decidim/surveys/metrics/answers_metric_manage.rb
112
112
  - app/queries/decidim/surveys/metrics/survey_participants_metric_measure.rb
113
+ - app/serializers/decidim/surveys/data_importer.rb
114
+ - app/serializers/decidim/surveys/data_serializer.rb
113
115
  - app/views/decidim/surveys/surveys/no_permission.html.erb
114
116
  - config/locales/ar-SA.yml
115
117
  - config/locales/ar.yml