<commit_before># frozen_string_literal: true

require "decidim/components/namer"

Decidim.register_component(:surveys) do |component|
  component.engine = Decidim::Surveys::Engine
  component.admin_engine = Decidim::Surveys::AdminEngine
  component.icon = "decidim_surveys.svg"
  component.stylesheet = "decidim/surveys/surveys"
  component.permissions_class_name = "Decidim::Surveys::Permissions"
  component.serializes_specific_data = true
  component.specific_data_serializer_class_name = "Decidim::Surveys::DataSerializer"
  component.specific_data_importer_class_name = "Decidim::Surveys::DataImporter"
  component.query_type = "Decidim::Surveys::SurveysType"

  component.on(:copy) do |context|
    Decidim::Surveys::CreateSurvey.call(context[:new_component]) do
      on(:invalid) { raise "Can't create survey" }
    end
  end

  component.on(:create) do |instance|
    Decidim::Surveys::CreateSurvey.call(instance) do
      on(:invalid) { raise "Can't create survey" }
    end
  end

  component.data_portable_entities = ["Decidim::Forms::Answer"]

  component.newsletter_participant_entities = ["Decidim::Forms::Answer"]

  component.on(:before_destroy) do |instance|
    survey = Decidim::Surveys::Survey.find_by(decidim_component_id: instance.id)
    survey_answers_for_component = Decidim::Forms::Answer.where(questionnaire: survey.questionnaire)

    raise "Can't destroy this component when there are survey answers" if survey_answers_for_component.any?
  end

  component.register_stat :surveys_count do |components, start_at, end_at|<commit_msg>Fix notification after creating survey (#8463)<commit_after># frozen_string_literal: true

require "decidim/components/namer"

Decidim.register_component(:surveys) do |component|
  component.engine = Decidim::Surveys::Engine
  component.admin_engine = Decidim::Surveys::AdminEngine
  component.icon = "media/images/decidim_surveys.svg"
  component.stylesheet = "decidim/surveys/surveys"
  component.permissions_class_name = "Decidim::Surveys::Permissions"
  component.serializes_specific_data = true
  component.specific_data_serializer_class_name = "Decidim::Surveys::DataSerializer"
  component.specific_data_importer_class_name = "Decidim::Surveys::DataImporter"
  component.query_type = "Decidim::Surveys::SurveysType"

  component.on(:copy) do |context|
    Decidim::Surveys::CreateSurvey.call(context[:new_component]) do
      on(:invalid) { raise "Can't create survey" }
    end
  end

  component.on(:create) do |instance|
    Decidim::Surveys::CreateSurvey.call(instance) do
      on(:invalid) { raise "Can't create survey" }
    end
  end

  component.data_portable_entities = ["Decidim::Forms::Answer"]

  component.newsletter_participant_entities = ["Decidim::Forms::Answer"]

  component.on(:before_destroy) do |instance|
    survey = Decidim::Surveys::Survey.find_by(decidim_component_id: instance.id)
    survey_answers_for_component = Decidim::Forms::Answer.where(questionnaire: survey.questionnaire)

    raise "Can't destroy this component when there are survey answers" if survey_answers_for_component.any?
  end

  component.register_stat :surveys_count do |components, start_at, end_at|
{'fraction_non_alphanumeric': 0.11142676767676768, 'fraction_numerical': 0.0012626262626262627, 'mean_word_length': 6.369767441860465, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '407614', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1030, 'n_words': 168}