decidim-consultations 0.19.1 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/decidim/consultations/icon.svg +1 -3
  3. data/app/assets/images/decidim/consultations/icon2.svg +1 -88
  4. data/app/assets/javascripts/decidim/consultations/utils_multiple.js +1 -1
  5. data/app/assets/stylesheets/decidim/consultations/_question.scss +0 -6
  6. data/app/assets/stylesheets/decidim/consultations/_question_multiple_votes.scss +22 -0
  7. data/app/assets/stylesheets/decidim/consultations/consultations.scss +1 -0
  8. data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-header.scss +0 -1
  9. data/app/cells/decidim/consultations/consultation_m/data.erb +1 -1
  10. data/app/cells/decidim/consultations/consultation_m/footer.erb +1 -1
  11. data/app/cells/decidim/consultations/content_blocks/highlighted_consultations/show.erb +3 -3
  12. data/app/commands/decidim/consultations/admin/create_response.rb +2 -1
  13. data/app/commands/decidim/consultations/admin/create_response_group.rb +40 -0
  14. data/app/commands/decidim/consultations/admin/destroy_response_group.rb +39 -0
  15. data/app/commands/decidim/consultations/admin/update_consultation.rb +9 -4
  16. data/app/commands/decidim/consultations/admin/update_response.rb +3 -2
  17. data/app/commands/decidim/consultations/admin/update_response_group.rb +46 -0
  18. data/app/controllers/concerns/decidim/consultations/admin/filterable.rb +27 -0
  19. data/app/controllers/decidim/consultations/admin/consultations_controller.rb +2 -1
  20. data/app/controllers/decidim/consultations/admin/response_groups_controller.rb +88 -0
  21. data/app/controllers/decidim/consultations/admin/responses_controller.rb +1 -0
  22. data/app/forms/decidim/consultations/admin/consultation_form.rb +5 -6
  23. data/app/forms/decidim/consultations/admin/question_form.rb +5 -6
  24. data/app/forms/decidim/consultations/admin/response_form.rb +5 -0
  25. data/app/forms/decidim/consultations/admin/response_group_form.rb +18 -0
  26. data/app/helpers/decidim/consultations/admin/questions_helper.rb +11 -0
  27. data/app/models/decidim/consultation.rb +25 -0
  28. data/app/models/decidim/consultations/question.rb +34 -1
  29. data/app/models/decidim/consultations/response.rb +11 -0
  30. data/app/models/decidim/consultations/response_group.rb +23 -0
  31. data/app/permissions/decidim/consultations/admin/permissions.rb +16 -0
  32. data/app/permissions/decidim/consultations/permissions.rb +2 -0
  33. data/app/presenters/decidim/consultations/question_stats_presenter.rb +1 -1
  34. data/app/types/decidim/consultations/consultation_question_type.rb +57 -0
  35. data/app/types/decidim/consultations/consultation_type.rb +32 -0
  36. data/app/views/decidim/consultations/admin/consultations/index.html.erb +3 -2
  37. data/app/views/decidim/consultations/admin/response_groups/_form.html.erb +11 -0
  38. data/app/views/decidim/consultations/admin/response_groups/edit.html.erb +18 -0
  39. data/app/views/decidim/consultations/admin/response_groups/index.html.erb +56 -0
  40. data/app/views/decidim/consultations/admin/response_groups/new.html.erb +13 -0
  41. data/app/views/decidim/consultations/admin/responses/_form.html.erb +3 -0
  42. data/app/views/decidim/consultations/admin/responses/index.html.erb +12 -1
  43. data/app/views/decidim/consultations/consultations/_consultation_card.html.erb +3 -3
  44. data/app/views/decidim/consultations/consultations/_consultation_details.html.erb +2 -2
  45. data/app/views/decidim/consultations/consultations/_filters.html.erb +9 -4
  46. data/app/views/decidim/consultations/consultations/_question.html.erb +2 -2
  47. data/app/views/decidim/consultations/consultations/index.html.erb +3 -3
  48. data/app/views/decidim/consultations/question_multiple_votes/_form.html.erb +14 -10
  49. data/app/views/decidim/consultations/question_multiple_votes/show.html.erb +8 -2
  50. data/app/views/decidim/consultations/questions/_vote_button.html.erb +70 -67
  51. data/app/views/decidim/consultations/questions/_vote_modal.html.erb +1 -1
  52. data/app/views/decidim/consultations/questions/_vote_modal_confirm.html.erb +1 -1
  53. data/app/views/decidim/consultations/questions/show.html.erb +4 -4
  54. data/app/views/layouts/decidim/_question_components.html.erb +3 -3
  55. data/app/views/layouts/decidim/_question_header.html.erb +1 -1
  56. data/app/views/layouts/decidim/admin/question.html.erb +1 -1
  57. data/app/views/layouts/decidim/consultation.html.erb +1 -0
  58. data/config/locales/am-ET.yml +1 -0
  59. data/config/locales/ar.yml +29 -1
  60. data/config/locales/bg-BG.yml +1 -0
  61. data/config/locales/bg.yml +1 -0
  62. data/config/locales/ca.yml +29 -1
  63. data/config/locales/cs.yml +37 -9
  64. data/config/locales/da-DK.yml +1 -0
  65. data/config/locales/da.yml +1 -0
  66. data/config/locales/de.yml +82 -1
  67. data/config/locales/el-GR.yml +1 -0
  68. data/config/locales/el.yml +377 -0
  69. data/config/locales/en.yml +29 -1
  70. data/config/locales/eo.yml +1 -0
  71. data/config/locales/es-MX.yml +29 -1
  72. data/config/locales/es-PY.yml +29 -1
  73. data/config/locales/es.yml +29 -1
  74. data/config/locales/et-EE.yml +1 -0
  75. data/config/locales/et.yml +1 -0
  76. data/config/locales/eu.yml +0 -1
  77. data/config/locales/fi-plain.yml +29 -1
  78. data/config/locales/fi.yml +38 -10
  79. data/config/locales/fr-CA.yml +377 -0
  80. data/config/locales/fr.yml +30 -2
  81. data/config/locales/ga-IE.yml +1 -0
  82. data/config/locales/gl.yml +0 -1
  83. data/config/locales/hr-HR.yml +1 -0
  84. data/config/locales/hr.yml +1 -0
  85. data/config/locales/hu.yml +25 -1
  86. data/config/locales/id-ID.yml +0 -1
  87. data/config/locales/is-IS.yml +185 -0
  88. data/config/locales/is.yml +185 -0
  89. data/config/locales/it.yml +82 -54
  90. data/config/locales/ja-JP.yml +367 -0
  91. data/config/locales/ja.yml +367 -0
  92. data/config/locales/ko-KR.yml +1 -0
  93. data/config/locales/ko.yml +1 -0
  94. data/config/locales/lt-LT.yml +1 -0
  95. data/config/locales/lt.yml +1 -0
  96. data/config/locales/lv.yml +383 -0
  97. data/config/locales/mt-MT.yml +1 -0
  98. data/config/locales/mt.yml +1 -0
  99. data/config/locales/nl.yml +29 -1
  100. data/config/locales/no.yml +312 -1
  101. data/config/locales/om-ET.yml +1 -0
  102. data/config/locales/pl.yml +183 -102
  103. data/config/locales/pt-BR.yml +1 -2
  104. data/config/locales/pt.yml +156 -75
  105. data/config/locales/ro-RO.yml +338 -0
  106. data/config/locales/ru.yml +0 -1
  107. data/config/locales/sk-SK.yml +394 -0
  108. data/config/locales/sk.yml +393 -0
  109. data/config/locales/sl.yml +9 -0
  110. data/config/locales/so-SO.yml +1 -0
  111. data/config/locales/sr-CS.yml +1 -0
  112. data/config/locales/sv.yml +60 -11
  113. data/config/locales/ti-ER.yml +1 -0
  114. data/config/locales/tr-TR.yml +0 -1
  115. data/config/locales/uk.yml +0 -1
  116. data/config/locales/vi-VN.yml +1 -0
  117. data/config/locales/vi.yml +1 -0
  118. data/config/locales/zh-CN.yml +367 -0
  119. data/config/locales/zh-TW.yml +1 -0
  120. data/db/migrate/20190708114204_create_decidim_consultations_response_groups.rb +16 -0
  121. data/db/migrate/20190708120345_add_response_groups_count_to_decidim_consultations_questions.rb +7 -0
  122. data/db/migrate/20190708121643_add_response_groups_to_decidim_consultations_responses.rb +10 -0
  123. data/db/migrate/20200320105916_index_foreign_keys_in_decidim_consultations_votes.rb +7 -0
  124. data/db/migrate/20200827154143_add_commentable_counter_cache_to_consultations.rb +9 -0
  125. data/db/seeds/city.jpeg +0 -0
  126. data/db/seeds/city2.jpeg +0 -0
  127. data/lib/decidim/consultations/admin_engine.rb +2 -0
  128. data/lib/decidim/consultations/participatory_space.rb +23 -17
  129. data/lib/decidim/consultations/test/factories.rb +6 -0
  130. data/lib/decidim/consultations/version.rb +1 -1
  131. metadata +67 -11
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Consultations
5
+ module Admin
6
+ # Controller that manages responses for a question
7
+ class ResponseGroupsController < Decidim::Consultations::Admin::ApplicationController
8
+ include QuestionAdmin
9
+
10
+ helper_method :current_response_group
11
+
12
+ def index
13
+ enforce_permission_to :read, :response_group, question: current_question
14
+ end
15
+
16
+ def new
17
+ enforce_permission_to :create, :response_group, question: current_question
18
+ @form = response_group_form.instance
19
+ end
20
+
21
+ def create
22
+ enforce_permission_to :create, :response_group, question: current_question
23
+ @form = response_group_form.from_params(params, current_question: current_question)
24
+
25
+ CreateResponseGroup.call(@form) do
26
+ on(:ok) do
27
+ flash[:notice] = I18n.t("response_groups.create.success", scope: "decidim.admin")
28
+ redirect_to response_groups_path(current_question)
29
+ end
30
+
31
+ on(:invalid) do
32
+ flash.now[:alert] = I18n.t("response_groups.create.error", scope: "decidim.admin")
33
+ render :new
34
+ end
35
+ end
36
+ end
37
+
38
+ def edit
39
+ enforce_permission_to :update, :response_group, response_group: current_response_group
40
+ @form = response_group_form.from_model(current_response_group)
41
+ end
42
+
43
+ def update
44
+ enforce_permission_to :update, :response_group, response_group: current_response_group
45
+
46
+ @form = response_group_form.from_params(params)
47
+ UpdateResponseGroup.call(current_response_group, @form) do
48
+ on(:ok) do
49
+ flash[:notice] = I18n.t("response_groups.update.success", scope: "decidim.admin")
50
+ redirect_to response_groups_path(current_question)
51
+ end
52
+
53
+ on(:invalid) do
54
+ flash.now[:alert] = I18n.t("response_groups.update.error", scope: "decidim.admin")
55
+ render :edit
56
+ end
57
+ end
58
+ end
59
+
60
+ def destroy
61
+ enforce_permission_to :destroy, :response_group, response_group: current_response_group
62
+
63
+ DestroyResponseGroup.call(current_response_group) do
64
+ on(:ok) do
65
+ flash[:notice] = I18n.t("response_groups.destroy.success", scope: "decidim.admin")
66
+ end
67
+
68
+ on(:invalid) do
69
+ flash[:alert] = I18n.t("response_groups.destroy.error", scope: "decidim.admin")
70
+ end
71
+
72
+ redirect_to response_groups_path(current_question)
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def current_response_group
79
+ @current_response_group ||= ResponseGroup.find_by(id: params[:id])
80
+ end
81
+
82
+ def response_group_form
83
+ form(ResponseGroupForm)
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -7,6 +7,7 @@ module Decidim
7
7
  class ResponsesController < Decidim::Consultations::Admin::ApplicationController
8
8
  include QuestionAdmin
9
9
 
10
+ helper Admin::QuestionsHelper
10
11
  helper_method :current_response
11
12
 
12
13
  def index
@@ -6,6 +6,7 @@ module Decidim
6
6
  # A form object used to create consultations from the admin dashboard.
7
7
  class ConsultationForm < Form
8
8
  include TranslatableAttributes
9
+ include Decidim::HasUploadValidations
9
10
 
10
11
  mimic :consultation
11
12
 
@@ -29,12 +30,10 @@ module Decidim
29
30
  validates :end_voting_date, presence: true, date: { after_or_equal_to: :start_voting_date }
30
31
  validate :slug_uniqueness
31
32
 
32
- validates :banner_image,
33
- file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } },
34
- file_content_type: { allow: ["image/jpeg", "image/png"] }
35
- validates :introductory_image,
36
- file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } },
37
- file_content_type: { allow: ["image/jpeg", "image/png"] }
33
+ validates :banner_image, passthru: { to: Decidim::Consultation }
34
+ validates :introductory_image, passthru: { to: Decidim::Consultation }
35
+
36
+ alias organization current_organization
38
37
 
39
38
  def highlighted_scope
40
39
  @highlighted_scope ||= current_organization.scopes.find_by(id: decidim_highlighted_scope_id)
@@ -6,6 +6,7 @@ module Decidim
6
6
  # A form object used to create questions for a consultation from the admin dashboard.
7
7
  class QuestionForm < Form
8
8
  include TranslatableAttributes
9
+ include Decidim::HasUploadValidations
9
10
 
10
11
  mimic :question
11
12
 
@@ -32,17 +33,15 @@ module Decidim
32
33
  validates :slug, presence: true, format: { with: Decidim::Consultations::Question.slug_format }
33
34
  validates :title, :promoter_group, :participatory_scope, :subtitle, :what_is_decided, translatable_presence: true
34
35
  validates :decidim_scope_id, presence: true
35
- validates :hero_image,
36
- file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } },
37
- file_content_type: { allow: ["image/jpeg", "image/png"] }
38
- validates :banner_image,
39
- file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } },
40
- file_content_type: { allow: ["image/jpeg", "image/png"] }
36
+ validates :hero_image, passthru: { to: Decidim::Consultations::Question }
37
+ validates :banner_image, passthru: { to: Decidim::Consultations::Question }
41
38
  validate :slug_uniqueness
42
39
  validates :origin_scope, :origin_title, translatable_presence: true, if: :has_origin_data?
43
40
  validates :i_frame_url, presence: true, if: :external_voting
44
41
  validates :order, numericality: { only_integer: true, allow_nil: true, allow_blank: true }
45
42
 
43
+ alias organization current_organization
44
+
46
45
  private
47
46
 
48
47
  def slug_uniqueness
@@ -10,8 +10,13 @@ module Decidim
10
10
  mimic :response
11
11
 
12
12
  translatable_attribute :title, String
13
+ attribute :decidim_consultations_response_group_id, Integer
13
14
 
14
15
  validates :title, translatable_presence: true
16
+
17
+ def response_group
18
+ ResponseGroup.find_by(id: decidim_consultations_response_group_id) if decidim_consultations_response_group_id
19
+ end
15
20
  end
16
21
  end
17
22
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Consultations
5
+ module Admin
6
+ # A form object used to create responses for a question from the admin dashboard.
7
+ class ResponseGroupForm < Form
8
+ include TranslatableAttributes
9
+
10
+ mimic :response_group
11
+
12
+ translatable_attribute :title, String
13
+
14
+ validates :title, translatable_presence: true
15
+ end
16
+ end
17
+ end
18
+ end
@@ -5,9 +5,20 @@ module Decidim
5
5
  module Admin
6
6
  # Helper for questions controller
7
7
  module QuestionsHelper
8
+ include Decidim::TranslationsHelper
9
+
10
+ Option = Struct.new(:id, :title)
11
+
8
12
  def question_example_slug
9
13
  "question-#{Time.now.utc.year}-#{Time.now.utc.month}-1"
10
14
  end
15
+
16
+ def question_response_groups(question = current_question)
17
+ [Option.new("", "-")] +
18
+ question.response_groups.map do |group|
19
+ Option.new(group.id, translated_attribute(group.title))
20
+ end
21
+ end
11
22
  end
12
23
  end
13
24
  end
@@ -11,6 +11,11 @@ module Decidim
11
11
  include Decidim::Loggable
12
12
  include Decidim::ParticipatorySpaceResourceable
13
13
  include Decidim::Randomable
14
+ include Decidim::Searchable
15
+ include Decidim::HasUploadValidations
16
+ include Decidim::TranslatableResource
17
+
18
+ translatable_fields :title, :subtitle, :description
14
19
 
15
20
  belongs_to :organization,
16
21
  foreign_key: "decidim_organization_id",
@@ -26,10 +31,15 @@ module Decidim
26
31
  inverse_of: :consultation,
27
32
  dependent: :destroy
28
33
 
34
+ alias component_ids question_ids
35
+
29
36
  validates :slug, uniqueness: { scope: :organization }
30
37
  validates :slug, presence: true, format: { with: Decidim::Consultation.slug_format }
31
38
 
39
+ validates_upload :banner_image
32
40
  mount_uploader :banner_image, Decidim::BannerImageUploader
41
+
42
+ validates_upload :introductory_image
33
43
  mount_uploader :introductory_image, Decidim::BannerImageUploader
34
44
 
35
45
  scope :upcoming, -> { published.where("start_voting_date > ?", Time.now.utc) }
@@ -41,6 +51,16 @@ module Decidim
41
51
  scope :finished, -> { published.where("end_voting_date < ?", Time.now.utc) }
42
52
  scope :order_by_most_recent, -> { order(created_at: :desc) }
43
53
 
54
+ searchable_fields({
55
+ participatory_space: :itself,
56
+ A: :title,
57
+ B: :subtitle,
58
+ D: :description,
59
+ datetime: :published_at
60
+ },
61
+ index_on_create: ->(_process) { false },
62
+ index_on_update: ->(process) { process.visible? })
63
+
44
64
  def to_param
45
65
  slug
46
66
  end
@@ -85,5 +105,10 @@ module Decidim
85
105
  def closed?
86
106
  !active?
87
107
  end
108
+
109
+ # Allow ransacker to search for a key in a hstore column (`title`.`en`)
110
+ ransacker :title do |parent|
111
+ Arel::Nodes::InfixOperation.new("->>", parent.table[:title], Arel::Nodes.build_quoted(I18n.locale.to_s))
112
+ end
88
113
  end
89
114
  end
@@ -7,7 +7,7 @@ module Decidim
7
7
  include Decidim::HasResourcePermission
8
8
  include Decidim::Participable
9
9
  include Decidim::Publicable
10
- include Decidim::Scopable
10
+ include Decidim::ScopableParticipatorySpace
11
11
  include Decidim::Comments::Commentable
12
12
  include Decidim::Followable
13
13
  include Decidim::HasAttachments
@@ -16,6 +16,10 @@ module Decidim
16
16
  include Decidim::Loggable
17
17
  include Decidim::ParticipatorySpaceResourceable
18
18
  include Decidim::Randomable
19
+ include Decidim::HasUploadValidations
20
+ include Decidim::TranslatableResource
21
+
22
+ translatable_fields :title, :subtitle, :what_is_decided, :promoter_group, :participatory_scope, :question_context, :origin_scope, :origin_title, :instructions
19
23
 
20
24
  belongs_to :consultation,
21
25
  foreign_key: "decidim_consultation_id",
@@ -39,13 +43,22 @@ module Decidim
39
43
  inverse_of: :question,
40
44
  dependent: :destroy
41
45
 
46
+ has_many :response_groups,
47
+ foreign_key: "decidim_consultations_questions_id",
48
+ class_name: "Decidim::Consultations::ResponseGroup",
49
+ inverse_of: :question,
50
+ dependent: :destroy
51
+
42
52
  has_many :categories,
43
53
  foreign_key: "decidim_participatory_space_id",
44
54
  foreign_type: "decidim_participatory_space_type",
45
55
  dependent: :destroy,
46
56
  as: :participatory_space
47
57
 
58
+ validates_upload :hero_image
48
59
  mount_uploader :hero_image, Decidim::HeroImageUploader
60
+
61
+ validates_upload :banner_image
49
62
  mount_uploader :banner_image, Decidim::BannerImageUploader
50
63
 
51
64
  default_scope { order(order: :asc) }
@@ -88,6 +101,22 @@ module Decidim
88
101
  max_votes > 1
89
102
  end
90
103
 
104
+ # Sorted responses by date so admins have a way to predict it
105
+ def sorted_responses
106
+ @sorted_responses ||= responses.sort_by(&:created_at)
107
+ end
108
+
109
+ # matrix of responses by group (sorted by configuration)
110
+ def grouped_responses
111
+ @grouped_responses ||= sorted_responses.group_by(&:response_group)
112
+ end
113
+
114
+ def grouped?
115
+ return false unless multiple?
116
+
117
+ response_groups_count.positive?
118
+ end
119
+
91
120
  # Public: Overrides the `comments_have_alignment?` Commentable concern method.
92
121
  def comments_have_alignment?
93
122
  true
@@ -171,6 +200,10 @@ module Decidim
171
200
  def allow_resource_permissions?
172
201
  true
173
202
  end
203
+
204
+ def attachment_context
205
+ :admin
206
+ end
174
207
  end
175
208
  end
176
209
  end
@@ -3,6 +3,10 @@
3
3
  module Decidim
4
4
  module Consultations
5
5
  class Response < ApplicationRecord
6
+ include Decidim::TranslatableResource
7
+
8
+ translatable_fields :title
9
+
6
10
  belongs_to :question,
7
11
  foreign_key: "decidim_consultations_questions_id",
8
12
  class_name: "Decidim::Consultations::Question",
@@ -14,6 +18,13 @@ module Decidim
14
18
  class_name: "Decidim::Consultations::Vote",
15
19
  inverse_of: :response,
16
20
  dependent: :restrict_with_error
21
+
22
+ belongs_to :response_group,
23
+ foreign_key: "decidim_consultations_response_group_id",
24
+ class_name: "Decidim::Consultations::ResponseGroup",
25
+ inverse_of: :responses,
26
+ counter_cache: :responses_count,
27
+ optional: true
17
28
  end
18
29
  end
19
30
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Consultations
5
+ class ResponseGroup < ApplicationRecord
6
+ include Decidim::TranslatableResource
7
+
8
+ translatable_fields :title
9
+
10
+ belongs_to :question,
11
+ foreign_key: "decidim_consultations_questions_id",
12
+ class_name: "Decidim::Consultations::Question",
13
+ counter_cache: :response_groups_count,
14
+ inverse_of: :response_groups
15
+
16
+ has_many :responses,
17
+ foreign_key: "decidim_consultations_response_group_id",
18
+ class_name: "Decidim::Consultations::Response",
19
+ inverse_of: :response_group,
20
+ dependent: :restrict_with_error
21
+ end
22
+ end
23
+ end
@@ -27,6 +27,7 @@ module Decidim
27
27
  allowed_consultation_action?
28
28
  allowed_question_action?
29
29
  allowed_response_action?
30
+ allowed_response_group_action?
30
31
 
31
32
  permission_action
32
33
  end
@@ -45,6 +46,10 @@ module Decidim
45
46
  @response ||= context.fetch(:response, nil)
46
47
  end
47
48
 
49
+ def response_group
50
+ @response_group ||= context.fetch(:response_group, nil)
51
+ end
52
+
48
53
  def allowed_action_on_component?
49
54
  return unless permission_action.subject == :component
50
55
 
@@ -90,6 +95,17 @@ module Decidim
90
95
  end
91
96
  end
92
97
 
98
+ def allowed_response_group_action?
99
+ return unless permission_action.subject == :response_group
100
+
101
+ case permission_action.action
102
+ when :create, :read
103
+ toggle_allow(question&.multiple?)
104
+ when :update, :destroy
105
+ toggle_allow(response_group.present?)
106
+ end
107
+ end
108
+
93
109
  # Only admin users can enter the consultations area.
94
110
  def user_can_enter_space_area?
95
111
  return unless permission_action.action == :enter &&
@@ -42,6 +42,8 @@ module Decidim
42
42
  toggle_allow(consultation.published? || user&.admin?)
43
43
  when :question
44
44
  toggle_allow(question.published? || user&.admin?)
45
+ when :participatory_space
46
+ allow!
45
47
  end
46
48
  end
47
49
 
@@ -15,7 +15,7 @@ module Decidim
15
15
  "question/#{question.id}/comments_count",
16
16
  expires_in: Decidim::Consultations.stats_cache_expiration_time
17
17
  ) do
18
- Decidim::Comments::Comment.where(root_commentable: question).count
18
+ question.comments_count
19
19
  end
20
20
  end
21
21
 
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Consultations
5
+ # This type represents a consultation.
6
+ ConsultationQuestionType = GraphQL::ObjectType.define do
7
+ interfaces [
8
+ -> { Decidim::Core::ScopableInterface },
9
+ -> { Decidim::Core::AttachableInterface },
10
+ -> { Decidim::Comments::CommentableInterface }
11
+ ]
12
+
13
+ name "ConsultationQuestion"
14
+ description "A consultation question"
15
+
16
+ field :id, !types.ID, "Internal ID of the question"
17
+ field :title, Decidim::Core::TranslatedFieldType, "Title of the question"
18
+ field :subtitle, Decidim::Core::TranslatedFieldType, "The subtitle of this question"
19
+ field :slug, !types.String, "Slug of the question"
20
+ field :createdAt, !Decidim::Core::DateTimeType, "The time this question was created", property: :created_at
21
+ field :updatedAt, !Decidim::Core::DateTimeType, "The time this question was updated", property: :updated_at
22
+ field :publishedAt, !Decidim::Core::DateTimeType, "The time this question was published", property: :published_at
23
+
24
+ field :components, types[Decidim::Core::ComponentInterface] do
25
+ description "Lists the components this space contains."
26
+
27
+ resolve ->(participatory_space, _args, _ctx) {
28
+ Decidim::Component.where(
29
+ participatory_space: participatory_space
30
+ ).published
31
+ }
32
+ end
33
+
34
+ field :bannerImage, types.String, "The banner image for this question", property: :banner_image
35
+ field :heroImage, types.String, "The hero image for this question", property: :hero_image
36
+
37
+ field :whatIsDecided, Decidim::Core::TranslatedFieldType, "What is decided in this question", property: :what_is_decided
38
+ field :promoterGroup, Decidim::Core::TranslatedFieldType, "The promoter group of this question", property: :promoter_group
39
+ field :participatoryScope, Decidim::Core::TranslatedFieldType, "The participatory scope of this question", property: :participatory_scope
40
+ field :questionContext, Decidim::Core::TranslatedFieldType, "The context for this question", property: :question_context
41
+ field :reference, types.String, "The reference for this question", property: :reference
42
+ field :hashtag, types.String, "The hashtag of this question", property: :hashtag
43
+ field :votesCount, types.Int, "The number of votes in this question", property: :votes_count
44
+ field :originScope, Decidim::Core::TranslatedFieldType, "The origin scope of this question", property: :origin_scope
45
+ field :originTitle, Decidim::Core::TranslatedFieldType, "The origin title of this question", property: :origin_title
46
+ field :originUrl, types.String, "The origin URL for this question", property: :origin_url
47
+ field :iFrameUrl, types.String, "The iframe URL for this question", property: :i_frame_url
48
+ field :externalVoting, types.Boolean, "If the question has external voting", property: :external_voting
49
+ field :responsesCount, types.Int, "The number of responses for this question", property: :responses_count
50
+ field :order, types.Int, "The order in which the question should be represented", property: :order
51
+ field :maxVotes, types.Int, "The maximum number of votes in this question", property: :max_votes
52
+ field :minVotes, types.Int, "The minimum number of votes in this question", property: :min_votes
53
+ field :responseGroupsCount, types.Int, "The number of group responses for this question", property: :response_groups_count
54
+ field :instructions, Decidim::Core::TranslatedFieldType, "Instructions for this question", property: :instructions
55
+ end
56
+ end
57
+ end