Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix form initiatives #600

Merged
merged 13 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions OVERLOADS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ This override the default `AssembliesHelpler` from `decidim-assemblies`, by addi
* `app/controllers/decidim/participatory_processes/participatory_processes_controller.rb`
This override the default `ParticipatoryProcessesController` from `decidim-participatory_processes`, by adding custom sort for participatory_processes

## Initiative form
* `lib/extends/forms/decidim/initiatives/initiative_form_extends.rb`
This adds a validation to form's description.

## Proposal's draft (Decidim awesome overrides 0.26.7)
* `app/views/decidim/proposals/collaborative_drafts/_edit_form_fields.html.erb`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def edit
initiative: current_initiative
)
@form.attachment = form_attachment_model
# "sanitize" the translated description, if the value is a hash (for machine_translation key) we don't modify it
@form.description.transform_values! { |v| v.instance_of?(String) ? v.gsub(/on\w+=("|')/, "nothing") : v }

render layout: "decidim/admin/initiative"
end
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Application < Rails::Application
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.

config.to_prepare do
require "extends/helpers/decidim/forms/application_helper_extends"
require "extends/cells/decidim/forms/step_navigation_cell_extends"
Expand All @@ -57,6 +56,7 @@ class Application < Rails::Application
require "extends/controllers/decidim/newsletters_controller_extends"
require "extends/commands/decidim/admin/destroy_participatory_space_private_user_extends"
require "extends/controllers/decidim/proposals/proposals_controller_extends"
require "extends/forms/decidim/initiatives/initiative_form_extends"

Decidim::GraphiQL::Rails.config.tap do |config|
config.initial_query = "{\n deployment {\n version\n branch\n remote\n upToDate\n currentCommit\n latestCommit\n locallyModified\n }\n}".html_safe
Expand Down
19 changes: 19 additions & 0 deletions lib/extends/forms/decidim/initiatives/initiative_form_extends.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require "active_support/concern"

module NoAdminInitiativeFormExtends
extend ActiveSupport::Concern

included do
validate :no_javascript_event_in_description

private

def no_javascript_event_in_description
errors.add :description, :invalid if description =~ /on\w+=/
end
end
end

Decidim::Initiatives::InitiativeForm.include(NoAdminInitiativeFormExtends)
Loading
Loading