decidim-proposals 0.26.5 → 0.26.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,19 +28,19 @@ Decidim.register_component(:proposals) do |component|
28
28
  component.settings(:global) do |settings|
29
29
  settings.attribute :scopes_enabled, type: :boolean, default: false
30
30
  settings.attribute :scope_id, type: :scope
31
- settings.attribute :vote_limit, type: :integer, default: 0
32
- settings.attribute :minimum_votes_per_user, type: :integer, default: 0
33
- settings.attribute :proposal_limit, type: :integer, default: 0
31
+ settings.attribute :vote_limit, type: :integer, default: 0, required: true
32
+ settings.attribute :minimum_votes_per_user, type: :integer, default: 0, required: true
33
+ settings.attribute :proposal_limit, type: :integer, default: 0, required: true
34
34
  settings.attribute :proposal_length, type: :integer, default: 500
35
35
  settings.attribute :proposal_edit_time, type: :enum, default: "limited", choices: -> { %w(limited infinite) }
36
- settings.attribute :proposal_edit_before_minutes, type: :integer, default: 5
37
- settings.attribute :threshold_per_proposal, type: :integer, default: 0
36
+ settings.attribute :proposal_edit_before_minutes, type: :integer, default: 5, required: true
37
+ settings.attribute :threshold_per_proposal, type: :integer, default: 0, required: true
38
38
  settings.attribute :can_accumulate_supports_beyond_threshold, type: :boolean, default: false
39
39
  settings.attribute :proposal_answering_enabled, type: :boolean, default: true
40
40
  settings.attribute :default_sort_order, type: :select, default: "default", choices: -> { POSSIBLE_SORT_ORDERS }
41
41
  settings.attribute :official_proposals_enabled, type: :boolean, default: true
42
42
  settings.attribute :comments_enabled, type: :boolean, default: true
43
- settings.attribute :comments_max_length, type: :integer, required: false
43
+ settings.attribute :comments_max_length, type: :integer, required: true
44
44
  settings.attribute :geocoding_enabled, type: :boolean, default: false
45
45
  settings.attribute :attachments_allowed, type: :boolean, default: false
46
46
  settings.attribute :resources_permissions_enabled, type: :boolean, default: true
@@ -131,6 +131,7 @@ Decidim.register_component(:proposals) do |component|
131
131
 
132
132
  collection = Decidim::Proposals::Proposal
133
133
  .published
134
+ .not_hidden
134
135
  .where(component: component_instance)
135
136
  .includes(:scope, :category, :component)
136
137
 
@@ -32,34 +32,41 @@ module Decidim
32
32
  resource,
33
33
  current_user
34
34
  ) do
35
- resource.save!
35
+ resource.try(:save!)
36
36
  end
37
- notify(resource)
37
+
38
+ notify
38
39
  end
39
40
 
40
41
  private
41
42
 
43
+ attr_reader :initial_state
44
+
42
45
  def resource
43
- @resource ||= begin
44
- proposal = Decidim::Proposals::Proposal.find_by(id: id)
45
- return nil unless proposal
46
- return nil if proposal.emendation?
47
-
48
- if proposal.component != component
49
- proposal.errors.add(:component, :invalid)
50
- return proposal
51
- end
52
-
53
- proposal.answer = answer
54
- proposal.answered_at = Time.current
55
- if POSSIBLE_ANSWER_STATES.include?(state)
56
- proposal.state = state
57
- proposal.state_published_at = Time.current if component.current_settings.publish_answers_immediately?
58
- else
59
- proposal.errors.add(:state, :invalid)
60
- end
61
- proposal
46
+ @resource ||= fetch_resource
47
+ end
48
+
49
+ def fetch_resource
50
+ proposal = Decidim::Proposals::Proposal.find_by(id: id)
51
+ return nil unless proposal
52
+ return nil if proposal.emendation?
53
+
54
+ if proposal.component != component
55
+ proposal.errors.add(:component, :invalid)
56
+ return proposal
57
+ end
58
+
59
+ proposal.answer = answer
60
+ proposal.answered_at = Time.current
61
+ @initial_state = proposal.state
62
+
63
+ if POSSIBLE_ANSWER_STATES.include?(state)
64
+ proposal.state = state
65
+ proposal.state_published_at = Time.current if component.current_settings.publish_answers_immediately?
66
+ else
67
+ proposal.errors.add(:state, :invalid)
62
68
  end
69
+ proposal
63
70
  end
64
71
 
65
72
  def id
@@ -86,8 +93,9 @@ module Decidim
86
93
  context[:current_user]
87
94
  end
88
95
 
89
- def notify(proposal)
90
- ::Decidim::Proposals::Admin::NotifyProposalAnswer.call(proposal, proposal.state)
96
+ def notify
97
+ state = initial_state || resource.try(:state)
98
+ ::Decidim::Proposals::Admin::NotifyProposalAnswer.call(resource, state)
91
99
  end
92
100
  end
93
101
  end
@@ -8,6 +8,7 @@ module Decidim
8
8
  include Decidim::ApplicationHelper
9
9
  include Decidim::ResourceHelper
10
10
  include Decidim::TranslationsHelper
11
+ include HtmlToPlainText
11
12
 
12
13
  # Public: Initializes the serializer with a proposal.
13
14
  def initialize(proposal)
@@ -32,7 +33,7 @@ module Decidim
32
33
  },
33
34
  component: { id: component.id },
34
35
  title: proposal.title,
35
- body: proposal.body,
36
+ body: convert_to_plain_text(proposal.body),
36
37
  address: proposal.address,
37
38
  latitude: proposal.latitude,
38
39
  longitude: proposal.longitude,
@@ -93,6 +94,13 @@ module Decidim
93
94
 
94
95
  Decidim::ResourceLocatorPresenter.new(proposal.amendable).url
95
96
  end
97
+
98
+ # Recursively strips HTML tags from given Hash strings using convert_to_text from Premailer
99
+ def convert_to_plain_text(value)
100
+ return value.transform_values { |v| convert_to_plain_text(v) } if value.is_a?(Hash)
101
+
102
+ convert_to_text(value)
103
+ end
96
104
  end
97
105
  end
98
106
  end
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds decidim-proposals version.
5
5
  module Proposals
6
6
  def self.version
7
- "0.26.5"
7
+ "0.26.7"
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-proposals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.5
4
+ version: 0.26.7
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: 2023-02-13 00:00:00.000000000 Z
13
+ date: 2023-05-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: decidim-comments
@@ -18,28 +18,28 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.26.5
21
+ version: 0.26.7
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.26.5
28
+ version: 0.26.7
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: decidim-core
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - '='
34
34
  - !ruby/object:Gem::Version
35
- version: 0.26.5
35
+ version: 0.26.7
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.26.5
42
+ version: 0.26.7
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: doc2text
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -80,84 +80,84 @@ dependencies:
80
80
  requirements:
81
81
  - - '='
82
82
  - !ruby/object:Gem::Version
83
- version: 0.26.5
83
+ version: 0.26.7
84
84
  type: :development
85
85
  prerelease: false
86
86
  version_requirements: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - '='
89
89
  - !ruby/object:Gem::Version
90
- version: 0.26.5
90
+ version: 0.26.7
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: decidim-assemblies
93
93
  requirement: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - '='
96
96
  - !ruby/object:Gem::Version
97
- version: 0.26.5
97
+ version: 0.26.7
98
98
  type: :development
99
99
  prerelease: false
100
100
  version_requirements: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - '='
103
103
  - !ruby/object:Gem::Version
104
- version: 0.26.5
104
+ version: 0.26.7
105
105
  - !ruby/object:Gem::Dependency
106
106
  name: decidim-budgets
107
107
  requirement: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - '='
110
110
  - !ruby/object:Gem::Version
111
- version: 0.26.5
111
+ version: 0.26.7
112
112
  type: :development
113
113
  prerelease: false
114
114
  version_requirements: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - '='
117
117
  - !ruby/object:Gem::Version
118
- version: 0.26.5
118
+ version: 0.26.7
119
119
  - !ruby/object:Gem::Dependency
120
120
  name: decidim-dev
121
121
  requirement: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - '='
124
124
  - !ruby/object:Gem::Version
125
- version: 0.26.5
125
+ version: 0.26.7
126
126
  type: :development
127
127
  prerelease: false
128
128
  version_requirements: !ruby/object:Gem::Requirement
129
129
  requirements:
130
130
  - - '='
131
131
  - !ruby/object:Gem::Version
132
- version: 0.26.5
132
+ version: 0.26.7
133
133
  - !ruby/object:Gem::Dependency
134
134
  name: decidim-meetings
135
135
  requirement: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - '='
138
138
  - !ruby/object:Gem::Version
139
- version: 0.26.5
139
+ version: 0.26.7
140
140
  type: :development
141
141
  prerelease: false
142
142
  version_requirements: !ruby/object:Gem::Requirement
143
143
  requirements:
144
144
  - - '='
145
145
  - !ruby/object:Gem::Version
146
- version: 0.26.5
146
+ version: 0.26.7
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: decidim-participatory_processes
149
149
  requirement: !ruby/object:Gem::Requirement
150
150
  requirements:
151
151
  - - '='
152
152
  - !ruby/object:Gem::Version
153
- version: 0.26.5
153
+ version: 0.26.7
154
154
  type: :development
155
155
  prerelease: false
156
156
  version_requirements: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - '='
159
159
  - !ruby/object:Gem::Version
160
- version: 0.26.5
160
+ version: 0.26.7
161
161
  description: A proposals component for decidim's participatory spaces.
162
162
  email:
163
163
  - josepjaume@gmail.com
@@ -469,6 +469,7 @@ files:
469
469
  - config/locales/et-EE.yml
470
470
  - config/locales/et.yml
471
471
  - config/locales/eu.yml
472
+ - config/locales/fa-IR.yml
472
473
  - config/locales/fi-pl.yml
473
474
  - config/locales/fi-plain.yml
474
475
  - config/locales/fi.yml
@@ -487,6 +488,7 @@ files:
487
488
  - config/locales/it.yml
488
489
  - config/locales/ja.yml
489
490
  - config/locales/ka-GE.yml
491
+ - config/locales/kaa.yml
490
492
  - config/locales/ko-KR.yml
491
493
  - config/locales/ko.yml
492
494
  - config/locales/lb-LU.yml