decidim-elections 0.22.0
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 +7 -0
- data/README.md +31 -0
- data/Rakefile +3 -0
- data/app/assets/config/decidim_elections_manifest.js +0 -0
- data/app/assets/images/decidim/elections/icon.svg +1 -0
- data/app/commands/decidim/elections/admin/create_answer.rb +71 -0
- data/app/commands/decidim/elections/admin/create_election.rb +48 -0
- data/app/commands/decidim/elections/admin/create_question.rb +52 -0
- data/app/commands/decidim/elections/admin/destroy_answer.rb +50 -0
- data/app/commands/decidim/elections/admin/destroy_election.rb +46 -0
- data/app/commands/decidim/elections/admin/destroy_question.rb +46 -0
- data/app/commands/decidim/elections/admin/update_answer.rb +73 -0
- data/app/commands/decidim/elections/admin/update_election.rb +48 -0
- data/app/commands/decidim/elections/admin/update_question.rb +52 -0
- data/app/controllers/decidim/elections/admin/answers_controller.rb +92 -0
- data/app/controllers/decidim/elections/admin/application_controller.rb +15 -0
- data/app/controllers/decidim/elections/admin/elections_controller.rb +82 -0
- data/app/controllers/decidim/elections/admin/questions_controller.rb +86 -0
- data/app/controllers/decidim/elections/application_controller.rb +13 -0
- data/app/controllers/decidim/elections/elections_controller.rb +9 -0
- data/app/forms/decidim/elections/admin/answer_form.rb +53 -0
- data/app/forms/decidim/elections/admin/election_form.rb +24 -0
- data/app/forms/decidim/elections/admin/question_form.rb +26 -0
- data/app/helpers/decidim/elections/application_helper.rb +10 -0
- data/app/models/decidim/elections/answer.rb +26 -0
- data/app/models/decidim/elections/application_record.rb +10 -0
- data/app/models/decidim/elections/election.rb +22 -0
- data/app/models/decidim/elections/question.rb +20 -0
- data/app/permissions/decidim/elections/admin/permissions.rb +42 -0
- data/app/permissions/decidim/elections/permissions.rb +16 -0
- data/app/types/decidim/elections/election_answer_type.rb +24 -0
- data/app/types/decidim/elections/election_question_type.rb +25 -0
- data/app/types/decidim/elections/election_type.rb +26 -0
- data/app/types/decidim/elections/elections_type.rb +32 -0
- data/app/views/decidim/elections/admin/answers/_form.html.erb +25 -0
- data/app/views/decidim/elections/admin/answers/edit.html.erb +7 -0
- data/app/views/decidim/elections/admin/answers/index.html.erb +46 -0
- data/app/views/decidim/elections/admin/answers/new.html.erb +7 -0
- data/app/views/decidim/elections/admin/answers/proposals_picker.html.erb +1 -0
- data/app/views/decidim/elections/admin/elections/_form.html.erb +28 -0
- data/app/views/decidim/elections/admin/elections/edit.html.erb +7 -0
- data/app/views/decidim/elections/admin/elections/index.html.erb +54 -0
- data/app/views/decidim/elections/admin/elections/new.html.erb +7 -0
- data/app/views/decidim/elections/admin/questions/_form.html.erb +27 -0
- data/app/views/decidim/elections/admin/questions/edit.html.erb +7 -0
- data/app/views/decidim/elections/admin/questions/index.html.erb +53 -0
- data/app/views/decidim/elections/admin/questions/new.html.erb +7 -0
- data/app/views/decidim/elections/elections/index.html.erb +1 -0
- data/app/views/decidim/elections/elections/show.html.erb +0 -0
- data/config/i18n-tasks.yml +10 -0
- data/config/locales/ar.yml +1 -0
- data/config/locales/bg-BG.yml +7 -0
- data/config/locales/ca.yml +132 -0
- data/config/locales/cs.yml +138 -0
- data/config/locales/da-DK.yml +1 -0
- data/config/locales/de.yml +132 -0
- data/config/locales/el.yml +132 -0
- data/config/locales/en.yml +133 -0
- data/config/locales/eo-UY.yml +1 -0
- data/config/locales/es-MX.yml +132 -0
- data/config/locales/es-PY.yml +132 -0
- data/config/locales/es.yml +132 -0
- data/config/locales/et-EE.yml +1 -0
- data/config/locales/eu.yml +1 -0
- data/config/locales/fi-plain.yml +132 -0
- data/config/locales/fi.yml +132 -0
- data/config/locales/fr-CA.yml +132 -0
- data/config/locales/fr.yml +132 -0
- data/config/locales/ga-IE.yml +1 -0
- data/config/locales/gl.yml +1 -0
- data/config/locales/hr-HR.yml +1 -0
- data/config/locales/hu.yml +1 -0
- data/config/locales/id-ID.yml +1 -0
- data/config/locales/is-IS.yml +1 -0
- data/config/locales/it.yml +132 -0
- data/config/locales/ja-JP.yml +129 -0
- data/config/locales/lt-LT.yml +1 -0
- data/config/locales/lv-LV.yml +135 -0
- data/config/locales/mt-MT.yml +1 -0
- data/config/locales/nl.yml +132 -0
- data/config/locales/no.yml +9 -0
- data/config/locales/pl.yml +138 -0
- data/config/locales/pt-BR.yml +1 -0
- data/config/locales/pt.yml +132 -0
- data/config/locales/ro-RO.yml +135 -0
- data/config/locales/ru.yml +1 -0
- data/config/locales/sk.yml +1 -0
- data/config/locales/sl.yml +5 -0
- data/config/locales/sr-CS.yml +1 -0
- data/config/locales/sv.yml +132 -0
- data/config/locales/tr-TR.yml +1 -0
- data/config/locales/uk.yml +1 -0
- data/db/migrate/20200430083618_create_decidim_elections_elections.rb +15 -0
- data/db/migrate/20200518082327_create_decidim_elections_questions.rb +14 -0
- data/db/migrate/20200518084144_create_decidim_elections_answers.rb +12 -0
- data/lib/decidim/elections.rb +13 -0
- data/lib/decidim/elections/admin.rb +10 -0
- data/lib/decidim/elections/admin_engine.rb +29 -0
- data/lib/decidim/elections/component.rb +123 -0
- data/lib/decidim/elections/engine.rb +23 -0
- data/lib/decidim/elections/seeds/city.jpeg +0 -0
- data/lib/decidim/elections/test/factories.rb +52 -0
- data/lib/decidim/elections/version.rb +10 -0
- metadata +201 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c8ce79876fbac611d30571cad4cf2e451e774d757aef8db6ac626e1150cf7d1b
|
|
4
|
+
data.tar.gz: 4b323700709a0c42ca51269fefcb23bcfed7325075af7ea42ee7f7889ab19bc1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 0f252f309ef75a273938ac811d9b1ec6493b272ee3b9916debadf7d41e0f5b0c03ce2250128b46f615046a24c868bb3286316b930390261b19970f470fe8e68c
|
|
7
|
+
data.tar.gz: 54db270fd7447ab0d6f0e541b84766d23fa89beb05c37eebfb403a4b480c0c55b66b905a2a5815187ce352df5c959850bb24b96a1b3edc9f3331cc90d51a1789
|
data/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Decidim::Elections
|
|
2
|
+
|
|
3
|
+
:warning: This module is under development and is not ready to be used in production.
|
|
4
|
+
|
|
5
|
+
The Elections module adds elections to any participatory space.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
Elections will be available as a Component for a Participatory Space.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Add this line to your application's Gemfile:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem "decidim-elections"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
And then execute:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bundle
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
See [Decidim](https://github.com/decidim/decidim).
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
See [Decidim](https://github.com/decidim/decidim).
|
data/Rakefile
ADDED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 35 35"><path d="M17.5 35A17.5 17.5 0 1 1 35 17.5 17.52 17.52 0 0 1 17.5 35zm0-33.06A15.56 15.56 0 1 0 33.06 17.5 15.57 15.57 0 0 0 17.5 1.94zm9.5 13.7H8a1 1 0 0 1 0-1.94h19a1 1 0 0 1 0 1.94zm0 3.68H8a1 1 0 0 1 0-1.94h19a1 1 0 0 1 0 1.94zM22.26 23H8a1 1 0 0 1 0-1.94h14.26a1 1 0 0 1 0 1.94z"/></svg>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Elections
|
|
5
|
+
module Admin
|
|
6
|
+
# This command is executed when the user creates an Answer
|
|
7
|
+
# from the admin panel.
|
|
8
|
+
class CreateAnswer < Rectify::Command
|
|
9
|
+
include ::Decidim::AttachmentMethods
|
|
10
|
+
include ::Decidim::GalleryMethods
|
|
11
|
+
|
|
12
|
+
def initialize(form)
|
|
13
|
+
@form = form
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Creates the answer if valid.
|
|
17
|
+
#
|
|
18
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
|
19
|
+
def call
|
|
20
|
+
return broadcast(:invalid) if invalid?
|
|
21
|
+
|
|
22
|
+
if process_gallery?
|
|
23
|
+
build_gallery
|
|
24
|
+
return broadcast(:invalid) if gallery_invalid?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
transaction do
|
|
28
|
+
create_answer
|
|
29
|
+
link_proposals
|
|
30
|
+
create_gallery if process_gallery?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
broadcast(:ok, answer)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
attr_reader :form, :answer, :gallery
|
|
39
|
+
|
|
40
|
+
def invalid?
|
|
41
|
+
form.election.started? || form.invalid?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def create_answer
|
|
45
|
+
attributes = {
|
|
46
|
+
question: form.question,
|
|
47
|
+
title: form.title,
|
|
48
|
+
description: form.description,
|
|
49
|
+
weight: form.weight
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@answer = Decidim.traceability.create!(
|
|
53
|
+
Answer,
|
|
54
|
+
form.current_user,
|
|
55
|
+
attributes,
|
|
56
|
+
visibility: "all"
|
|
57
|
+
)
|
|
58
|
+
@attached_to = @answer
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def proposals
|
|
62
|
+
@proposals ||= answer.sibling_scope(:proposals).where(id: form.proposal_ids)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def link_proposals
|
|
66
|
+
answer.link_resources(proposals, "related_proposals")
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Elections
|
|
5
|
+
module Admin
|
|
6
|
+
# This command is executed when the user creates an Election
|
|
7
|
+
# from the admin panel.
|
|
8
|
+
class CreateElection < Rectify::Command
|
|
9
|
+
def initialize(form)
|
|
10
|
+
@form = form
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Creates the election if valid.
|
|
14
|
+
#
|
|
15
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
|
16
|
+
def call
|
|
17
|
+
return broadcast(:invalid) if form.invalid?
|
|
18
|
+
|
|
19
|
+
create_election!
|
|
20
|
+
|
|
21
|
+
broadcast(:ok, election)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
attr_reader :form, :election
|
|
27
|
+
|
|
28
|
+
def create_election!
|
|
29
|
+
attributes = {
|
|
30
|
+
title: form.title,
|
|
31
|
+
subtitle: form.subtitle,
|
|
32
|
+
description: form.description,
|
|
33
|
+
start_time: form.start_time,
|
|
34
|
+
end_time: form.end_time,
|
|
35
|
+
component: form.current_component
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@election = Decidim.traceability.create!(
|
|
39
|
+
Election,
|
|
40
|
+
form.current_user,
|
|
41
|
+
attributes,
|
|
42
|
+
visibility: "all"
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Elections
|
|
5
|
+
module Admin
|
|
6
|
+
# This command is executed when the user creates a Question
|
|
7
|
+
# from the admin panel.
|
|
8
|
+
class CreateQuestion < Rectify::Command
|
|
9
|
+
def initialize(form)
|
|
10
|
+
@form = form
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Creates the question if valid.
|
|
14
|
+
#
|
|
15
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
|
16
|
+
def call
|
|
17
|
+
return broadcast(:invalid) if invalid?
|
|
18
|
+
|
|
19
|
+
create_question!
|
|
20
|
+
|
|
21
|
+
broadcast(:ok, question)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
attr_reader :form, :question
|
|
27
|
+
|
|
28
|
+
def invalid?
|
|
29
|
+
form.election.started? || form.invalid?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def create_question!
|
|
33
|
+
attributes = {
|
|
34
|
+
election: form.election,
|
|
35
|
+
title: form.title,
|
|
36
|
+
description: form.description,
|
|
37
|
+
max_selections: form.max_selections,
|
|
38
|
+
weight: form.weight,
|
|
39
|
+
random_answers_order: form.random_answers_order
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@question = Decidim.traceability.create!(
|
|
43
|
+
Question,
|
|
44
|
+
form.current_user,
|
|
45
|
+
attributes,
|
|
46
|
+
visibility: "all"
|
|
47
|
+
)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Elections
|
|
5
|
+
module Admin
|
|
6
|
+
# This command is executed when the user destroys an Answer
|
|
7
|
+
# from the admin panel.
|
|
8
|
+
class DestroyAnswer < Rectify::Command
|
|
9
|
+
include ::Decidim::AttachmentMethods
|
|
10
|
+
include ::Decidim::GalleryMethods
|
|
11
|
+
|
|
12
|
+
def initialize(answer, current_user)
|
|
13
|
+
@answer = answer
|
|
14
|
+
@current_user = current_user
|
|
15
|
+
@attached_to = answer
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Destroys the answer if valid.
|
|
19
|
+
#
|
|
20
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
|
21
|
+
def call
|
|
22
|
+
return broadcast(:invalid) if invalid?
|
|
23
|
+
|
|
24
|
+
destroy_answer
|
|
25
|
+
|
|
26
|
+
broadcast(:ok, answer)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
attr_reader :answer, :current_user
|
|
32
|
+
|
|
33
|
+
def invalid?
|
|
34
|
+
answer.question.election.started?
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def destroy_answer
|
|
38
|
+
Decidim.traceability.perform_action!(
|
|
39
|
+
:delete,
|
|
40
|
+
answer,
|
|
41
|
+
current_user,
|
|
42
|
+
visibility: "all"
|
|
43
|
+
) do
|
|
44
|
+
answer.destroy!
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Elections
|
|
5
|
+
module Admin
|
|
6
|
+
# This command is executed when the user destroys an Election
|
|
7
|
+
# from the admin panel.
|
|
8
|
+
class DestroyElection < Rectify::Command
|
|
9
|
+
def initialize(election, current_user)
|
|
10
|
+
@election = election
|
|
11
|
+
@current_user = current_user
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Destroys the election if valid.
|
|
15
|
+
#
|
|
16
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
|
17
|
+
def call
|
|
18
|
+
return broadcast(:invalid) if invalid?
|
|
19
|
+
|
|
20
|
+
destroy_election!
|
|
21
|
+
|
|
22
|
+
broadcast(:ok, election)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
attr_reader :election, :current_user
|
|
28
|
+
|
|
29
|
+
def invalid?
|
|
30
|
+
election.started?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def destroy_election!
|
|
34
|
+
Decidim.traceability.perform_action!(
|
|
35
|
+
:delete,
|
|
36
|
+
election,
|
|
37
|
+
current_user,
|
|
38
|
+
visibility: "all"
|
|
39
|
+
) do
|
|
40
|
+
election.destroy!
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Elections
|
|
5
|
+
module Admin
|
|
6
|
+
# This command is executed when the user destroys a Question
|
|
7
|
+
# from the admin panel.
|
|
8
|
+
class DestroyQuestion < Rectify::Command
|
|
9
|
+
def initialize(question, current_user)
|
|
10
|
+
@question = question
|
|
11
|
+
@current_user = current_user
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Destroys the question if valid.
|
|
15
|
+
#
|
|
16
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
|
17
|
+
def call
|
|
18
|
+
return broadcast(:invalid) if invalid?
|
|
19
|
+
|
|
20
|
+
destroy_question!
|
|
21
|
+
|
|
22
|
+
broadcast(:ok, question)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
attr_reader :question, :current_user
|
|
28
|
+
|
|
29
|
+
def invalid?
|
|
30
|
+
question.election.started?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def destroy_question!
|
|
34
|
+
Decidim.traceability.perform_action!(
|
|
35
|
+
:delete,
|
|
36
|
+
question,
|
|
37
|
+
current_user,
|
|
38
|
+
visibility: "all"
|
|
39
|
+
) do
|
|
40
|
+
question.destroy!
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Elections
|
|
5
|
+
module Admin
|
|
6
|
+
# This command is executed when the user updates an Answer
|
|
7
|
+
# from the admin panel.
|
|
8
|
+
class UpdateAnswer < Rectify::Command
|
|
9
|
+
include ::Decidim::AttachmentMethods
|
|
10
|
+
include ::Decidim::GalleryMethods
|
|
11
|
+
|
|
12
|
+
def initialize(form, answer)
|
|
13
|
+
@form = form
|
|
14
|
+
@answer = answer
|
|
15
|
+
@attached_to = answer
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Updates the answer if valid.
|
|
19
|
+
#
|
|
20
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
|
21
|
+
def call
|
|
22
|
+
return broadcast(:invalid) if invalid?
|
|
23
|
+
|
|
24
|
+
if process_gallery?
|
|
25
|
+
build_gallery
|
|
26
|
+
return broadcast(:invalid) if gallery_invalid?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
transaction do
|
|
30
|
+
update_answer
|
|
31
|
+
link_proposals
|
|
32
|
+
create_gallery if process_gallery?
|
|
33
|
+
photo_cleanup!
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
broadcast(:ok, answer)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
attr_reader :form, :answer, :gallery
|
|
42
|
+
|
|
43
|
+
def invalid?
|
|
44
|
+
form.election.started? || form.invalid?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def update_answer
|
|
48
|
+
attributes = {
|
|
49
|
+
question: form.question,
|
|
50
|
+
title: form.title,
|
|
51
|
+
description: form.description,
|
|
52
|
+
weight: form.weight
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
Decidim.traceability.update!(
|
|
56
|
+
answer,
|
|
57
|
+
form.current_user,
|
|
58
|
+
attributes,
|
|
59
|
+
visibility: "all"
|
|
60
|
+
)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def proposals
|
|
64
|
+
@proposals ||= answer.sibling_scope(:proposals).where(id: form.proposal_ids)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def link_proposals
|
|
68
|
+
answer.link_resources(proposals, "related_proposals")
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Elections
|
|
5
|
+
module Admin
|
|
6
|
+
# This command is executed when the user updates an Election
|
|
7
|
+
# from the admin panel.
|
|
8
|
+
class UpdateElection < Rectify::Command
|
|
9
|
+
def initialize(form, election)
|
|
10
|
+
@form = form
|
|
11
|
+
@election = election
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Updates the election if valid.
|
|
15
|
+
#
|
|
16
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
|
17
|
+
def call
|
|
18
|
+
return broadcast(:invalid) if form.invalid?
|
|
19
|
+
|
|
20
|
+
update_election!
|
|
21
|
+
|
|
22
|
+
broadcast(:ok, election)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
attr_reader :form, :election
|
|
28
|
+
|
|
29
|
+
def update_election!
|
|
30
|
+
attributes = {
|
|
31
|
+
title: form.title,
|
|
32
|
+
subtitle: form.subtitle,
|
|
33
|
+
description: form.description,
|
|
34
|
+
start_time: form.start_time,
|
|
35
|
+
end_time: form.end_time
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Decidim.traceability.update!(
|
|
39
|
+
election,
|
|
40
|
+
form.current_user,
|
|
41
|
+
attributes,
|
|
42
|
+
visibility: "all"
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|