decidim-challenges 0.5.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/LICENSE-AGPLv3.txt +661 -0
- data/README.md +49 -0
- data/Rakefile +9 -0
- data/app/cells/decidim/challenges/challenge_cell.rb +21 -0
- data/app/cells/decidim/challenges/challenge_g/show.erb +47 -0
- data/app/cells/decidim/challenges/challenge_g_cell.rb +69 -0
- data/app/cells/decidim/problems/problem_cell.rb +21 -0
- data/app/cells/decidim/problems/problem_g/show.erb +35 -0
- data/app/cells/decidim/problems/problem_g_cell.rb +61 -0
- data/app/cells/decidim/solutions/solution_cell.rb +21 -0
- data/app/cells/decidim/solutions/solution_g/show.erb +30 -0
- data/app/cells/decidim/solutions/solution_g_cell.rb +84 -0
- data/app/commands/decidim/challenges/admin/create_challenge.rb +67 -0
- data/app/commands/decidim/challenges/admin/destroy_challenge.rb +49 -0
- data/app/commands/decidim/challenges/admin/export_challenge_surveys.rb +45 -0
- data/app/commands/decidim/challenges/admin/publish_challenge.rb +40 -0
- data/app/commands/decidim/challenges/admin/unpublish_challenge.rb +40 -0
- data/app/commands/decidim/challenges/admin/update_challenge.rb +72 -0
- data/app/commands/decidim/challenges/admin/update_surveys.rb +43 -0
- data/app/commands/decidim/challenges/survey_challenge.rb +67 -0
- data/app/commands/decidim/command_utils.rb +20 -0
- data/app/commands/decidim/problems/admin/create_problem.rb +66 -0
- data/app/commands/decidim/problems/admin/destroy_problem.rb +49 -0
- data/app/commands/decidim/problems/admin/publish_problem.rb +40 -0
- data/app/commands/decidim/problems/admin/unpublish_problem.rb +40 -0
- data/app/commands/decidim/problems/admin/update_problem.rb +69 -0
- data/app/commands/decidim/solutions/admin/create_solution.rb +65 -0
- data/app/commands/decidim/solutions/admin/destroy_solution.rb +43 -0
- data/app/commands/decidim/solutions/admin/publish_solution.rb +40 -0
- data/app/commands/decidim/solutions/admin/unpublish_solution.rb +40 -0
- data/app/commands/decidim/solutions/admin/update_solution.rb +67 -0
- data/app/commands/decidim/solutions/create_solution.rb +67 -0
- data/app/controllers/concerns/decidim/challenges/admin/filterable.rb +27 -0
- data/app/controllers/concerns/decidim/challenges/orderable_challenges.rb +37 -0
- data/app/controllers/concerns/decidim/problems/admin/filterable.rb +27 -0
- data/app/controllers/concerns/decidim/problems/orderable_problems.rb +37 -0
- data/app/controllers/concerns/decidim/solutions/admin/filterable.rb +27 -0
- data/app/controllers/concerns/decidim/solutions/orderable_solutions.rb +37 -0
- data/app/controllers/concerns/decidim/with_default_filters.rb +23 -0
- data/app/controllers/concerns/decidim/with_sdgs.rb +19 -0
- data/app/controllers/decidim/challenges/admin/application_controller.rb +15 -0
- data/app/controllers/decidim/challenges/admin/challenge_publications_controller.rb +53 -0
- data/app/controllers/decidim/challenges/admin/challenges_controller.rb +108 -0
- data/app/controllers/decidim/challenges/admin/survey_form_controller.rb +43 -0
- data/app/controllers/decidim/challenges/admin/surveys_controller.rb +104 -0
- data/app/controllers/decidim/challenges/application_controller.rb +13 -0
- data/app/controllers/decidim/challenges/challenges_controller.rb +70 -0
- data/app/controllers/decidim/challenges/surveys_controller.rb +61 -0
- data/app/controllers/decidim/problems/admin/application_controller.rb +15 -0
- data/app/controllers/decidim/problems/admin/problem_publications_controller.rb +53 -0
- data/app/controllers/decidim/problems/admin/problems_controller.rb +102 -0
- data/app/controllers/decidim/problems/application_controller.rb +13 -0
- data/app/controllers/decidim/problems/problems_controller.rb +62 -0
- data/app/controllers/decidim/sdgs/admin/application_controller.rb +15 -0
- data/app/controllers/decidim/sdgs/admin/sdgs_controller.rb +18 -0
- data/app/controllers/decidim/sdgs/application_controller.rb +13 -0
- data/app/controllers/decidim/sdgs/sdgs_controller.rb +24 -0
- data/app/controllers/decidim/solutions/admin/application_controller.rb +15 -0
- data/app/controllers/decidim/solutions/admin/solution_publications_controller.rb +53 -0
- data/app/controllers/decidim/solutions/admin/solutions_controller.rb +106 -0
- data/app/controllers/decidim/solutions/application_controller.rb +13 -0
- data/app/controllers/decidim/solutions/solutions_controller.rb +115 -0
- data/app/forms/decidim/challenges/admin/challenge_surveys_form.rb +35 -0
- data/app/forms/decidim/challenges/admin/challenges_form.rb +78 -0
- data/app/forms/decidim/problems/admin/problems_form.rb +90 -0
- data/app/forms/decidim/solutions/admin/solutions_form.rb +71 -0
- data/app/forms/decidim/solutions/solutions_form.rb +50 -0
- data/app/helpers/decidim/challenges/application_helper.rb +25 -0
- data/app/helpers/decidim/challenges/challenge_cells_helper.rb +57 -0
- data/app/helpers/decidim/challenges/challenges_helper.rb +39 -0
- data/app/helpers/decidim/problems/application_helper.rb +10 -0
- data/app/helpers/decidim/problems/problem_cells_helper.rb +23 -0
- data/app/helpers/decidim/problems/problems_helper.rb +24 -0
- data/app/helpers/decidim/sdgs/sdgs_helper.rb +28 -0
- data/app/helpers/decidim/show_filters_helper.rb +13 -0
- data/app/helpers/decidim/solutions/application_helper.rb +27 -0
- data/app/helpers/decidim/solutions/solution_cells_helper.rb +56 -0
- data/app/helpers/decidim/solutions/solutions_helper.rb +21 -0
- data/app/models/decidim/application_record.rb +8 -0
- data/app/models/decidim/challenges/challenge.rb +82 -0
- data/app/models/decidim/challenges/survey.rb +19 -0
- data/app/models/decidim/problems/problem.rb +118 -0
- data/app/models/decidim/sdgs/sdg.rb +47 -0
- data/app/models/decidim/solutions/application_record.rb +10 -0
- data/app/models/decidim/solutions/solution.rb +69 -0
- data/app/packs/entrypoints/decidim_challenges.js +4 -0
- data/app/packs/entrypoints/decidim_challenges.scss +1 -0
- data/app/packs/entrypoints/decidim_problems.js +1 -0
- data/app/packs/entrypoints/decidim_problems.scss +1 -0
- data/app/packs/entrypoints/decidim_sdgs.js +6 -0
- data/app/packs/entrypoints/decidim_sdgs.scss +3 -0
- data/app/packs/entrypoints/decidim_shared.js +1 -0
- data/app/packs/entrypoints/decidim_shared.scss +1 -0
- data/app/packs/entrypoints/decidim_solutions.js +4 -0
- data/app/packs/entrypoints/decidim_solutions.scss +1 -0
- data/app/packs/fonts/Oswald-Medium.ttf +0 -0
- data/app/packs/images/decidim/challenges/decidim_challenges_icon.svg +1 -0
- data/app/packs/images/decidim/sdgs/ods-01.svg +11 -0
- data/app/packs/images/decidim/sdgs/ods-02.svg +11 -0
- data/app/packs/images/decidim/sdgs/ods-03.svg +11 -0
- data/app/packs/images/decidim/sdgs/ods-04.svg +12 -0
- data/app/packs/images/decidim/sdgs/ods-05.svg +12 -0
- data/app/packs/images/decidim/sdgs/ods-06.svg +20 -0
- data/app/packs/images/decidim/sdgs/ods-07.svg +18 -0
- data/app/packs/images/decidim/sdgs/ods-08.svg +13 -0
- data/app/packs/images/decidim/sdgs/ods-09.svg +25 -0
- data/app/packs/images/decidim/sdgs/ods-10.svg +13 -0
- data/app/packs/images/decidim/sdgs/ods-11.svg +41 -0
- data/app/packs/images/decidim/sdgs/ods-12.svg +11 -0
- data/app/packs/images/decidim/sdgs/ods-13.svg +57 -0
- data/app/packs/images/decidim/sdgs/ods-14.svg +14 -0
- data/app/packs/images/decidim/sdgs/ods-15.svg +11 -0
- data/app/packs/images/decidim/sdgs/ods-16.svg +14 -0
- data/app/packs/images/decidim/sdgs/ods-17.svg +39 -0
- data/app/packs/images/decidim/sdgs/sdg-wheel.png +0 -0
- data/app/packs/images/decidim/sdgs/un_emblem_square.png +0 -0
- data/app/packs/src/decidim/challenges/add_challenge.js +3 -0
- data/app/packs/src/decidim/challenges/admin/challenges_form.js +3 -0
- data/app/packs/src/decidim/sdgs/filter.js +75 -0
- data/app/packs/stylesheets/decidim/challenges/challenges.scss +3 -0
- data/app/packs/stylesheets/decidim/problems/problems.scss +3 -0
- data/app/packs/stylesheets/decidim/sdgs/ods.scss +185 -0
- data/app/packs/stylesheets/decidim/sdgs/sdgs_filter/button.scss +27 -0
- data/app/packs/stylesheets/decidim/sdgs/sdgs_filter/modal.scss +60 -0
- data/app/packs/stylesheets/decidim/shared/_cards.scss +52 -0
- data/app/packs/stylesheets/decidim/shared/base.scss +9 -0
- data/app/packs/stylesheets/decidim/solutions/solutions.scss +3 -0
- data/app/permissions/decidim/challenges/admin/permissions.rb +88 -0
- data/app/permissions/decidim/challenges/permissions.rb +27 -0
- data/app/permissions/decidim/problems/admin/permissions.rb +52 -0
- data/app/permissions/decidim/problems/permissions.rb +16 -0
- data/app/permissions/decidim/solutions/admin/permissions.rb +58 -0
- data/app/permissions/decidim/solutions/permissions.rb +17 -0
- data/app/presenters/decidim/challenges/challenge_presenter.rb +134 -0
- data/app/presenters/decidim/problems/problem_presenter.rb +108 -0
- data/app/presenters/decidim/solutions/solution_presenter.rb +198 -0
- data/app/serializers/decidim/challenges/data_serializer.rb +46 -0
- data/app/serializers/decidim/challenges/survey_serializer.rb +37 -0
- data/app/types/decidim/challenges/challenge_type.rb +28 -0
- data/app/types/decidim/challenges/challenges_type.rb +32 -0
- data/app/types/decidim/problems/problem_type.rb +29 -0
- data/app/types/decidim/problems/problems_type.rb +32 -0
- data/app/types/decidim/solutions/solution_type.rb +25 -0
- data/app/types/decidim/solutions/solutions_type.rb +32 -0
- data/app/views/decidim/challenges/admin/challenges/_form.html.erb +78 -0
- data/app/views/decidim/challenges/admin/challenges/edit.html.erb +24 -0
- data/app/views/decidim/challenges/admin/challenges/index.html.erb +88 -0
- data/app/views/decidim/challenges/admin/challenges/new.html.erb +18 -0
- data/app/views/decidim/challenges/admin/surveys/_form.html.erb +9 -0
- data/app/views/decidim/challenges/admin/surveys/edit.html.erb +39 -0
- data/app/views/decidim/challenges/admin/surveys/index.html.erb +49 -0
- data/app/views/decidim/challenges/admin/surveys/show.html.erb +43 -0
- data/app/views/decidim/challenges/challenges/_challenge.html.erb +1 -0
- data/app/views/decidim/challenges/challenges/_challenges.html.erb +11 -0
- data/app/views/decidim/challenges/challenges/_related_problems.html.erb +14 -0
- data/app/views/decidim/challenges/challenges/_sidebar_data.html.erb +60 -0
- data/app/views/decidim/challenges/challenges/index.html.erb +29 -0
- data/app/views/decidim/challenges/challenges/index.js.erb +5 -0
- data/app/views/decidim/challenges/challenges/show.html.erb +41 -0
- data/app/views/decidim/problems/admin/problems/_form.html.erb +79 -0
- data/app/views/decidim/problems/admin/problems/edit.html.erb +24 -0
- data/app/views/decidim/problems/admin/problems/index.html.erb +93 -0
- data/app/views/decidim/problems/admin/problems/new.html.erb +18 -0
- data/app/views/decidim/problems/problems/_problem.html.erb +1 -0
- data/app/views/decidim/problems/problems/_problems.html.erb +11 -0
- data/app/views/decidim/problems/problems/_sidebar_data.html.erb +70 -0
- data/app/views/decidim/problems/problems/index.html.erb +28 -0
- data/app/views/decidim/problems/problems/index.js.erb +5 -0
- data/app/views/decidim/problems/problems/show.html.erb +38 -0
- data/app/views/decidim/sdgs/sdgs/_objectives.html.erb +320 -0
- data/app/views/decidim/sdgs/sdgs/_ods.html.erb +132 -0
- data/app/views/decidim/sdgs/sdgs/index.html.erb +64 -0
- data/app/views/decidim/sdgs/sdgs_filter/_filter_selector.html.erb +7 -0
- data/app/views/decidim/sdgs/sdgs_filter/_modal.html.erb +35 -0
- data/app/views/decidim/shared/_related_solutions.html.erb +14 -0
- data/app/views/decidim/solutions/admin/solutions/_documents.html.erb +13 -0
- data/app/views/decidim/solutions/admin/solutions/_form.html.erb +70 -0
- data/app/views/decidim/solutions/admin/solutions/_photos.html.erb +13 -0
- data/app/views/decidim/solutions/admin/solutions/edit.html.erb +24 -0
- data/app/views/decidim/solutions/admin/solutions/index.html.erb +97 -0
- data/app/views/decidim/solutions/admin/solutions/new.html.erb +18 -0
- data/app/views/decidim/solutions/admin/solutions/show.html.erb +114 -0
- data/app/views/decidim/solutions/solutions/_form.html.erb +22 -0
- data/app/views/decidim/solutions/solutions/_sidebar_data.html.erb +114 -0
- data/app/views/decidim/solutions/solutions/_solution.html.erb +1 -0
- data/app/views/decidim/solutions/solutions/_solutions.html.erb +13 -0
- data/app/views/decidim/solutions/solutions/index.html.erb +37 -0
- data/app/views/decidim/solutions/solutions/index.js.erb +5 -0
- data/app/views/decidim/solutions/solutions/new.html.erb +20 -0
- data/app/views/decidim/solutions/solutions/show.html.erb +72 -0
- data/config/assets.rb +27 -0
- data/config/i18n-tasks.yml +10 -0
- data/config/locales/ca.yml +1244 -0
- data/config/locales/cs.yml +668 -0
- data/config/locales/en.yml +1245 -0
- data/config/locales/es.yml +1250 -0
- data/config/locales/oc.yml +1229 -0
- data/db/migrate/20201014125000_create_decidim_challenges_challenges.rb +23 -0
- data/db/migrate/20201103155100_create_decidim_problems_problems.rb +25 -0
- data/db/migrate/20201116111200_create_decidim_solutions_solutions.rb +21 -0
- data/db/migrate/20210413083244_create_decidim_challenges_surveys.rb +14 -0
- data/db/migrate/20210413083507_add_survey_attributes_to_challenges.rb +7 -0
- data/db/migrate/20210413083604_add_questionnaire_to_existing_challenges.rb +15 -0
- data/db/migrate/20210413112229_add_challenge_reference_to_solutions.rb +7 -0
- data/db/migrate/20210427091033_remove_require_null_in_problems_for_solutions.rb +7 -0
- data/db/migrate/20220407110503_add_card_image_to_challenges.rb +7 -0
- data/db/migrate/20240919094714_add_public_fields_to_solutions.rb +10 -0
- data/lib/decidim/challenges/admin.rb +10 -0
- data/lib/decidim/challenges/admin_engine.rb +37 -0
- data/lib/decidim/challenges/component.rb +65 -0
- data/lib/decidim/challenges/engine.rb +39 -0
- data/lib/decidim/challenges/test/factories.rb +59 -0
- data/lib/decidim/challenges/version.rb +14 -0
- data/lib/decidim/challenges.rb +13 -0
- data/lib/decidim/problems/admin.rb +10 -0
- data/lib/decidim/problems/admin_engine.rb +25 -0
- data/lib/decidim/problems/component.rb +51 -0
- data/lib/decidim/problems/engine.rb +31 -0
- data/lib/decidim/problems/test/factories.rb +39 -0
- data/lib/decidim/sdgs/admin.rb +10 -0
- data/lib/decidim/sdgs/admin_engine.rb +28 -0
- data/lib/decidim/sdgs/component.rb +44 -0
- data/lib/decidim/sdgs/engine.rb +23 -0
- data/lib/decidim/sdgs/test/factories.rb +13 -0
- data/lib/decidim/solutions/admin.rb +10 -0
- data/lib/decidim/solutions/admin_engine.rb +25 -0
- data/lib/decidim/solutions/component.rb +52 -0
- data/lib/decidim/solutions/engine.rb +31 -0
- data/lib/decidim/solutions/test/factories.rb +28 -0
- metadata +316 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
module Admin
|
6
|
+
# A command that sets a challenge as unpublished.
|
7
|
+
class UnpublishChallenge < Decidim::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# challenge - A Challenge that will be published
|
11
|
+
# current_user - the user performing the action
|
12
|
+
def initialize(challenge, current_user)
|
13
|
+
super()
|
14
|
+
@challenge = challenge
|
15
|
+
@current_user = current_user
|
16
|
+
end
|
17
|
+
|
18
|
+
# Executes the command. Broadcasts these events:
|
19
|
+
#
|
20
|
+
# - :ok when everything is valid.
|
21
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
def call
|
25
|
+
return broadcast(:invalid) if challenge.nil? || !challenge.published?
|
26
|
+
|
27
|
+
Decidim.traceability.perform_action!("unpublish", challenge, current_user) do
|
28
|
+
challenge.unpublish!
|
29
|
+
end
|
30
|
+
|
31
|
+
broadcast(:ok)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :challenge, :current_user
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when a user updates a challenge.
|
7
|
+
class UpdateChallenge < Decidim::Command
|
8
|
+
include ::Decidim::AttachmentAttributesMethods
|
9
|
+
|
10
|
+
# Public: Initializes the command.
|
11
|
+
#
|
12
|
+
# form - A form object with the params.
|
13
|
+
# challenge - the challenge to update.
|
14
|
+
def initialize(form, challenge)
|
15
|
+
super()
|
16
|
+
@form = form
|
17
|
+
@challenge = challenge
|
18
|
+
end
|
19
|
+
|
20
|
+
# Executes the command. Broadcasts these events:
|
21
|
+
#
|
22
|
+
# - :ok when everything is valid, together with the challenge.
|
23
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
24
|
+
#
|
25
|
+
# Returns nothing.
|
26
|
+
def call
|
27
|
+
return broadcast(:invalid) if form.invalid?
|
28
|
+
|
29
|
+
transaction do
|
30
|
+
update_challenge
|
31
|
+
end
|
32
|
+
|
33
|
+
broadcast(:ok, challenge)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :form, :challenge
|
39
|
+
|
40
|
+
def update_challenge
|
41
|
+
Decidim.traceability.update!(
|
42
|
+
challenge,
|
43
|
+
form.current_user,
|
44
|
+
attributes:
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def attributes
|
49
|
+
parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite
|
50
|
+
parsed_local_description = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.local_description, current_organization: form.current_organization).rewrite
|
51
|
+
parsed_global_description = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.global_description, current_organization: form.current_organization).rewrite
|
52
|
+
{
|
53
|
+
title: parsed_title,
|
54
|
+
local_description: parsed_local_description,
|
55
|
+
global_description: parsed_global_description,
|
56
|
+
component: form.current_component,
|
57
|
+
tags: form.tags,
|
58
|
+
sdg_code: form.sdg_code,
|
59
|
+
scope: form.scope,
|
60
|
+
state: form.state,
|
61
|
+
start_date: form.start_date,
|
62
|
+
end_date: form.end_date,
|
63
|
+
coordinating_entities: form.coordinating_entities,
|
64
|
+
collaborating_entities: form.collaborating_entities,
|
65
|
+
}.merge(
|
66
|
+
attachment_attributes(:card_image)
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
module Admin
|
6
|
+
# This command is executed when the user updates the challenge survey,
|
7
|
+
class UpdateSurveys < Decidim::Command
|
8
|
+
# Initializes a UpdateSurveys Command.
|
9
|
+
#
|
10
|
+
# form - The form from which to get the data.
|
11
|
+
# challenge - The current instance of the challenge to be updated.
|
12
|
+
def initialize(form, challenge)
|
13
|
+
super()
|
14
|
+
@form = form
|
15
|
+
@challenge = challenge
|
16
|
+
end
|
17
|
+
|
18
|
+
# Updates the challenge if valid.
|
19
|
+
#
|
20
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
21
|
+
def call
|
22
|
+
return broadcast(:invalid) if form.invalid?
|
23
|
+
|
24
|
+
challenge.with_lock do
|
25
|
+
update_challenge_surveys
|
26
|
+
end
|
27
|
+
|
28
|
+
broadcast(:ok)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :form, :challenge
|
34
|
+
|
35
|
+
def update_challenge_surveys
|
36
|
+
challenge.survey_enabled = form.survey_enabled
|
37
|
+
|
38
|
+
challenge.save!
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Challenges
|
5
|
+
# This command is executed when the user answer a survey.
|
6
|
+
class SurveyChallenge < Decidim::Command
|
7
|
+
# Initializes a SurveyChallenge Command.
|
8
|
+
#
|
9
|
+
# challenge - The current instance of the challenge to be answer the survey.
|
10
|
+
# user - The user answering the survey.
|
11
|
+
# survey_form - A form object with params; can be a questionnaire.
|
12
|
+
def initialize(challenge, user, survey_form)
|
13
|
+
super()
|
14
|
+
@challenge = challenge
|
15
|
+
@user = user
|
16
|
+
@survey_form = survey_form
|
17
|
+
end
|
18
|
+
|
19
|
+
# Creates a challenge survey.
|
20
|
+
#
|
21
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
22
|
+
def call
|
23
|
+
return broadcast(:invalid) unless can_answer_survey?
|
24
|
+
return broadcast(:invalid_form) unless survey_form.valid?
|
25
|
+
|
26
|
+
challenge.with_lock do
|
27
|
+
answer_questionnaire
|
28
|
+
create_survey
|
29
|
+
end
|
30
|
+
|
31
|
+
broadcast(:ok)
|
32
|
+
rescue ActiveRecord::Rollback
|
33
|
+
form.errors.add(:base, :invalid)
|
34
|
+
broadcast(:invalid)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_reader :challenge, :user, :survey, :survey_form
|
40
|
+
|
41
|
+
def answer_questionnaire
|
42
|
+
return unless questionnaire?
|
43
|
+
|
44
|
+
Decidim::Forms::AnswerQuestionnaire.call(survey_form, user, challenge.questionnaire) do
|
45
|
+
on(:invalid) do
|
46
|
+
raise ActiveRecord::Rollback
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_survey
|
52
|
+
@survey = Decidim::Challenges::Survey.create!(
|
53
|
+
challenge:,
|
54
|
+
user:
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
def questionnaire?
|
59
|
+
survey_form.model_name.human == "Questionnaire"
|
60
|
+
end
|
61
|
+
|
62
|
+
def can_answer_survey?
|
63
|
+
Decidim::Challenges::Survey.where(decidim_user_id: user, decidim_challenge_id: challenge).none?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module CommandUtils
|
5
|
+
def parsed_attribute(attribute)
|
6
|
+
Decidim::ContentProcessor.parse_with_processor(:hashtag, form.send(attribute), current_organization: form.current_organization).rewrite
|
7
|
+
end
|
8
|
+
|
9
|
+
def challenge_id
|
10
|
+
challenge = form.decidim_challenges_challenge_id
|
11
|
+
problem = Decidim::Problems::Problem.find_by(id: form.decidim_problems_problem_id)
|
12
|
+
|
13
|
+
if challenge.present?
|
14
|
+
Decidim::Challenges::Challenge.find(form.decidim_challenges_challenge_id).id
|
15
|
+
else
|
16
|
+
problem&.decidim_challenges_challenge_id.presence
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Problems
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when a user creates a new problem.
|
7
|
+
class CreateProblem < Decidim::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# form - A form object with the params.
|
11
|
+
def initialize(form)
|
12
|
+
super()
|
13
|
+
@form = form
|
14
|
+
end
|
15
|
+
|
16
|
+
# Executes the command. Broadcasts these events:
|
17
|
+
#
|
18
|
+
# - :ok when everything is valid, together with the problem.
|
19
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
20
|
+
#
|
21
|
+
# Returns nothing.
|
22
|
+
def call
|
23
|
+
return broadcast(:invalid) if form.invalid?
|
24
|
+
|
25
|
+
transaction do
|
26
|
+
create_problem!
|
27
|
+
end
|
28
|
+
|
29
|
+
broadcast(:ok, problem)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :form, :problem
|
35
|
+
|
36
|
+
def create_problem!
|
37
|
+
parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite
|
38
|
+
parsed_description = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.description, current_organization: form.current_organization).rewrite
|
39
|
+
params = {
|
40
|
+
title: parsed_title,
|
41
|
+
description: parsed_description,
|
42
|
+
component: form.current_component,
|
43
|
+
decidim_challenges_challenge_id: form.decidim_challenges_challenge_id,
|
44
|
+
decidim_sectorial_scope_id: form.decidim_sectorial_scope_id,
|
45
|
+
decidim_technological_scope_id: form.decidim_technological_scope_id,
|
46
|
+
tags: form.tags,
|
47
|
+
causes: form.causes,
|
48
|
+
groups_affected: form.groups_affected,
|
49
|
+
state: form.state,
|
50
|
+
start_date: form.start_date,
|
51
|
+
end_date: form.end_date,
|
52
|
+
proposing_entities: form.proposing_entities,
|
53
|
+
collaborating_entities: form.collaborating_entities,
|
54
|
+
}
|
55
|
+
|
56
|
+
@problem = Decidim.traceability.create!(
|
57
|
+
Decidim::Problems::Problem,
|
58
|
+
form.current_user,
|
59
|
+
params,
|
60
|
+
visibility: "all"
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Problems
|
5
|
+
module Admin
|
6
|
+
# This command deals with destroying a Problem from the admin panel.
|
7
|
+
class DestroyProblem < Decidim::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# page - The Problem to be destroyed.
|
11
|
+
def initialize(problem, current_user)
|
12
|
+
super()
|
13
|
+
@problem = problem
|
14
|
+
@current_user = current_user
|
15
|
+
end
|
16
|
+
|
17
|
+
# Public: Executes the command.
|
18
|
+
#
|
19
|
+
# Broadcasts :ok if it got destroyed
|
20
|
+
# Broadcasts :has_solutions if not destroyed 'cause dependent
|
21
|
+
# Broadcasts :invalid if it not destroyed
|
22
|
+
def call
|
23
|
+
destroy_problem
|
24
|
+
broadcast(:ok)
|
25
|
+
rescue ActiveRecord::DeleteRestrictionError
|
26
|
+
broadcast(:has_solutions)
|
27
|
+
rescue ActiveRecord::RecordNotDestroyed
|
28
|
+
broadcast(:invalid)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :problem, :current_user
|
34
|
+
|
35
|
+
def destroy_problem
|
36
|
+
transaction do
|
37
|
+
Decidim.traceability.perform_action!(
|
38
|
+
"delete",
|
39
|
+
problem,
|
40
|
+
current_user
|
41
|
+
) do
|
42
|
+
problem.destroy!
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Problems
|
5
|
+
module Admin
|
6
|
+
# A command that sets a problem as published.
|
7
|
+
class PublishProblem < Decidim::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# problem - A Problem that will be published
|
11
|
+
# current_user - the user performing the action
|
12
|
+
def initialize(problem, current_user)
|
13
|
+
super()
|
14
|
+
@problem = problem
|
15
|
+
@current_user = current_user
|
16
|
+
end
|
17
|
+
|
18
|
+
# Executes the command. Broadcasts these events:
|
19
|
+
#
|
20
|
+
# - :ok when everything is valid.
|
21
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
def call
|
25
|
+
return broadcast(:invalid) if problem.nil? || problem.published?
|
26
|
+
|
27
|
+
Decidim.traceability.perform_action!("publish", problem, current_user, visibility: "all") do
|
28
|
+
problem.publish!
|
29
|
+
end
|
30
|
+
|
31
|
+
broadcast(:ok)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :problem, :current_user
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Problems
|
5
|
+
module Admin
|
6
|
+
# A command that sets a problem as unpublished.
|
7
|
+
class UnpublishProblem < Decidim::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# problem - A Problem that will be published
|
11
|
+
# current_user - the user performing the action
|
12
|
+
def initialize(problem, current_user)
|
13
|
+
super()
|
14
|
+
@problem = problem
|
15
|
+
@current_user = current_user
|
16
|
+
end
|
17
|
+
|
18
|
+
# Executes the command. Broadcasts these events:
|
19
|
+
#
|
20
|
+
# - :ok when everything is valid.
|
21
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
def call
|
25
|
+
return broadcast(:invalid) if problem.nil? || !problem.published?
|
26
|
+
|
27
|
+
Decidim.traceability.perform_action!("unpublish", problem, current_user) do
|
28
|
+
problem.unpublish!
|
29
|
+
end
|
30
|
+
|
31
|
+
broadcast(:ok)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :problem, :current_user
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Problems
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when a user updates a Problem.
|
7
|
+
class UpdateProblem < Decidim::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# form - A form object with the params.
|
11
|
+
# problem - the problem to update.
|
12
|
+
def initialize(form, problem)
|
13
|
+
super()
|
14
|
+
@form = form
|
15
|
+
@problem = problem
|
16
|
+
end
|
17
|
+
|
18
|
+
# Executes the command. Broadcasts these events:
|
19
|
+
#
|
20
|
+
# - :ok when everything is valid, together with the problem.
|
21
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
def call
|
25
|
+
return broadcast(:invalid) if form.invalid?
|
26
|
+
|
27
|
+
transaction do
|
28
|
+
update_problem
|
29
|
+
end
|
30
|
+
|
31
|
+
broadcast(:ok, problem)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :form, :problem
|
37
|
+
|
38
|
+
def update_problem
|
39
|
+
Decidim.traceability.update!(
|
40
|
+
problem,
|
41
|
+
form.current_user,
|
42
|
+
attributes:
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def attributes
|
47
|
+
parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite
|
48
|
+
parsed_description = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.description, current_organization: form.current_organization).rewrite
|
49
|
+
{
|
50
|
+
title: parsed_title,
|
51
|
+
description: parsed_description,
|
52
|
+
component: form.current_component,
|
53
|
+
decidim_challenges_challenge_id: form.decidim_challenges_challenge_id,
|
54
|
+
decidim_sectorial_scope_id: form.decidim_sectorial_scope_id,
|
55
|
+
decidim_technological_scope_id: form.decidim_technological_scope_id,
|
56
|
+
tags: form.tags,
|
57
|
+
causes: form.causes,
|
58
|
+
groups_affected: form.groups_affected,
|
59
|
+
state: form.state,
|
60
|
+
start_date: form.start_date,
|
61
|
+
end_date: form.end_date,
|
62
|
+
proposing_entities: form.proposing_entities,
|
63
|
+
collaborating_entities: form.collaborating_entities,
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Solutions
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when a user creates a new solution.
|
7
|
+
class CreateSolution < Decidim::Command
|
8
|
+
include Decidim::Challenges
|
9
|
+
include Decidim::CommandUtils
|
10
|
+
|
11
|
+
# Public: Initializes the command.
|
12
|
+
#
|
13
|
+
# form - A form object with the params.
|
14
|
+
def initialize(form)
|
15
|
+
super()
|
16
|
+
@form = form
|
17
|
+
end
|
18
|
+
|
19
|
+
# Executes the command. Broadcasts these events:
|
20
|
+
#
|
21
|
+
# - :ok when everything is valid, together with the solution.
|
22
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
23
|
+
#
|
24
|
+
# Returns nothing.
|
25
|
+
def call
|
26
|
+
return broadcast(:invalid) if form.invalid?
|
27
|
+
|
28
|
+
transaction do
|
29
|
+
create_solution!
|
30
|
+
end
|
31
|
+
|
32
|
+
broadcast(:ok, solution)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_reader :form, :solution
|
38
|
+
|
39
|
+
def create_solution!
|
40
|
+
params = {
|
41
|
+
title: parsed_attribute(:title),
|
42
|
+
description: parsed_attribute(:description),
|
43
|
+
component: form.current_component,
|
44
|
+
decidim_problems_problem_id: form.decidim_problems_problem_id,
|
45
|
+
decidim_challenges_challenge_id: challenge_id,
|
46
|
+
tags: form.tags,
|
47
|
+
objectives: parsed_attribute(:objectives),
|
48
|
+
indicators: parsed_attribute(:indicators),
|
49
|
+
beneficiaries: parsed_attribute(:beneficiaries),
|
50
|
+
requirements: parsed_attribute(:requirements),
|
51
|
+
financing_type: parsed_attribute(:financing_type),
|
52
|
+
author_id: form.author_id,
|
53
|
+
}
|
54
|
+
|
55
|
+
@solution = Decidim.traceability.create!(
|
56
|
+
Decidim::Solutions::Solution,
|
57
|
+
form.current_user,
|
58
|
+
params,
|
59
|
+
visibility: "all"
|
60
|
+
)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Solutions
|
5
|
+
module Admin
|
6
|
+
# This command deals with destroying a Solution from the admin panel.
|
7
|
+
class DestroySolution < Decidim::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# page - The Solution to be destroyed.
|
11
|
+
def initialize(solution, current_user)
|
12
|
+
super()
|
13
|
+
@solution = solution
|
14
|
+
@current_user = current_user
|
15
|
+
end
|
16
|
+
|
17
|
+
# Public: Executes the command.
|
18
|
+
#
|
19
|
+
# Broadcasts :ok if it got destroyed
|
20
|
+
def call
|
21
|
+
destroy_solution
|
22
|
+
broadcast(:ok)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :solution, :current_user
|
28
|
+
|
29
|
+
def destroy_solution
|
30
|
+
transaction do
|
31
|
+
Decidim.traceability.perform_action!(
|
32
|
+
"delete",
|
33
|
+
solution,
|
34
|
+
current_user
|
35
|
+
) do
|
36
|
+
solution.destroy!
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Solutions
|
5
|
+
module Admin
|
6
|
+
# A command that sets a solution as published.
|
7
|
+
class PublishSolution < Decidim::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# solution - A Solution that will be published
|
11
|
+
# current_user - the user performing the action
|
12
|
+
def initialize(solution, current_user)
|
13
|
+
super()
|
14
|
+
@solution = solution
|
15
|
+
@current_user = current_user
|
16
|
+
end
|
17
|
+
|
18
|
+
# Executes the command. Broadcasts these events:
|
19
|
+
#
|
20
|
+
# - :ok when everything is valid.
|
21
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
def call
|
25
|
+
return broadcast(:invalid) if solution.nil? || solution.published?
|
26
|
+
|
27
|
+
Decidim.traceability.perform_action!("publish", solution, current_user, visibility: "all") do
|
28
|
+
solution.publish!
|
29
|
+
end
|
30
|
+
|
31
|
+
broadcast(:ok)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :solution, :current_user
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|