-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create solutions from public view (#71)
* Create solutions by users and manage in admin - Create solutions in public views - Publish and unpusblish in admin - Add settings to enable or disable this feature * Apply Rubocop * Add missing translations * Add and fix tests * Fix solutions test * Fix CI and solution tests * Remove simplecov * Refactor * Refactor * Bump module version
- Loading branch information
1 parent
2f3f8c9
commit c6bdbec
Showing
40 changed files
with
1,584 additions
and
895 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Solutions | ||
# A command with all the business logic when a user creates a new solution. | ||
class CreateSolution < Decidim::Command | ||
include ::Decidim::MultipleAttachmentsMethods | ||
include Decidim::Challenges | ||
include Decidim::CommandUtils | ||
|
||
# Public: Initializes the command. | ||
# | ||
# form - A form object with the params. | ||
def initialize(form) | ||
super() | ||
@form = form | ||
end | ||
|
||
# Executes the command. Broadcasts these events: | ||
# | ||
# - :ok when everything is valid, together with the solution. | ||
# - :invalid if the form wasn't valid and we couldn't proceed. | ||
# | ||
# Returns nothing. | ||
def call | ||
return broadcast(:invalid) if form.invalid? | ||
|
||
transaction do | ||
create_solution! | ||
|
||
if process_attachments? | ||
build_attachments | ||
create_attachments | ||
end | ||
end | ||
|
||
broadcast(:ok, solution) | ||
end | ||
|
||
private | ||
|
||
attr_reader :form, :solution, :attachment | ||
|
||
def create_solution! | ||
params = { | ||
title: parsed_attribute(:title), | ||
description: parsed_attribute(:description), | ||
component: form.current_component, | ||
decidim_challenges_challenge_id: challenge_id, | ||
project_status: parsed_attribute(:project_status), | ||
project_url: parsed_attribute(:project_url), | ||
coordinating_entity: parsed_attribute(:coordinating_entity), | ||
author_id: form.author_id, | ||
} | ||
|
||
@solution = Decidim.traceability.create!( | ||
Decidim::Solutions::Solution, | ||
form.current_user, | ||
params, | ||
visibility: "all" | ||
) | ||
|
||
@attached_to = @solution | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Solutions | ||
# A form object to be used when public users want to create a solution. | ||
# | ||
class SolutionsForm < Decidim::Form | ||
include Decidim::AttachmentAttributes | ||
include Decidim::HasUploadValidations | ||
|
||
mimic :solution | ||
|
||
attribute :title, String | ||
attribute :description, Decidim::Attributes::CleanString | ||
attribute :project_status, String | ||
attribute :project_url, String | ||
attribute :coordinating_entity, String | ||
attribute :decidim_challenges_challenge_id, Integer | ||
attribute :decidim_problems_problem_id, Integer | ||
attribute :author_id, Integer | ||
attribute :attachment, AttachmentForm | ||
|
||
attachments_attribute :documents | ||
|
||
validates :title, :description, presence: true, etiquette: true | ||
validates :project_status, :coordinating_entity, presence: true | ||
validates :decidim_challenges_challenge_id, :author_id, presence: true | ||
validates :decidim_problems_problem_id, presence: false | ||
|
||
def map_model(model) | ||
self.title = translated_attribute(model.title) | ||
self.description = translated_attribute(model.description) | ||
|
||
sefl.documents = model.attachments | ||
return unless model.categorization | ||
end | ||
|
||
# Finds the Challenge from the given decidim_challenges_challenge_id | ||
# | ||
# Returns a Decidim::Challenges::Challenge | ||
def challenge | ||
@challenge ||= @problem.present? ? Decidim::Challenges::Challenge.find(@problem.challenge.id) : Decidim::Challenges::Challenge.find(@decidim_challenges_challenge_id) | ||
end | ||
|
||
def author | ||
Decidim::User.find(author_id) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.