diff --git a/.env-example b/.env-example index 3efc530ff4..f8cb29dbe2 100644 --- a/.env-example +++ b/.env-example @@ -50,7 +50,7 @@ GEOCODER_UNITS=km # Units for geocoder results (e.g., km or m # DECIDIM_CLEANER_DELETE_DELETED_AUTHORIZATIONS_DATA= #= Decidim AI -# DECIDIM_AI_ENABLED="true" Default: true +# DECIDIM_AI_ENABLED="false" Default: false # DECIDIM_AI_USER_SPAM_ANALYZER_ENABLED="true" Default: true # DECIDIM_AI_GENERIC_SPAM_ANALYZER_ENABLED="true" Default: true # DECIDIM_AI_ENDPOINT="https://" diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index b6d4f76cdb..603022c243 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,9 +1,6 @@ --- name: Bug report about: Create a report to help us improve -title: '' -labels: '' -assignees: '' --- @@ -34,4 +31,4 @@ If applicable, add the error stacktrace to help explain your problem. - Decidim installation: [e.g. Metadecidim] **Additional context** -Add any other context about the problem here. For instance, add Metadecidim link. +Add any other context about the problem here. For instance, add Metadecidim link. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/tracking.md b/.github/ISSUE_TEMPLATE/tracking.md deleted file mode 100644 index dd085525ea..0000000000 --- a/.github/ISSUE_TEMPLATE/tracking.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -name: Tracking -about: carte de suivi thématique -title: "[tracking]" -labels: '' -assignees: '' - ---- - - diff --git a/app/jobs/decidim/ai/spam_detection/spam_digest_generator_job.rb b/app/jobs/decidim/ai/spam_detection/spam_digest_generator_job.rb index a6251d5fdb..58cdaac7f9 100644 --- a/app/jobs/decidim/ai/spam_detection/spam_digest_generator_job.rb +++ b/app/jobs/decidim/ai/spam_detection/spam_digest_generator_job.rb @@ -14,6 +14,9 @@ class SpamDigestGeneratorJob < ApplicationJob }.freeze def perform(frequency) + # Stop if Decidim-AI is disabled + return unless decidim_ai_enabled? + # Skip validation if frequency is nil (called by Decidim core specs) return if frequency.nil? && Rails.env.test? raise ArgumentError, "Invalid frequency: #{frequency}" unless frequency && FREQUENCIES.has_key?(frequency.to_sym) @@ -37,6 +40,10 @@ def perform(frequency) private + def decidim_ai_enabled? + Rails.application.secrets.dig(:decidim, :ai, :enabled) == true + end + # Counts the spam reports for the given organization and frequency (daily/weekly) def count_spam(organization, frequency) since = frequency == :weekly ? 1.week.ago : 1.day.ago diff --git a/config/initializers/decidim_ai.rb b/config/initializers/decidim_ai.rb index 5088274deb..07df908537 100644 --- a/config/initializers/decidim_ai.rb +++ b/config/initializers/decidim_ai.rb @@ -65,6 +65,17 @@ Decidim::Ai::SpamDetection.user_spam_analyzer_job = "Decidim::Ai::SpamDetection::ThirdParty::UserSpamAnalyzerJob" Decidim::Ai::SpamDetection.generic_spam_analyzer_job = "Decidim::Ai::SpamDetection::ThirdParty::GenericSpamAnalyzerJob" else + analyzers = [ + { + name: :bayes, + strategy: Decidim::Ai::SpamDetection::Strategy::Bayes, + options: { + adapter: "memory" + } + } + ] + Decidim::Ai::SpamDetection.resource_analyzers = analyzers + Decidim::Ai::SpamDetection.user_analyzers = analyzers Rails.logger.warn "[decidim-ai] Initializer - AI module is not installed or spam detection is disabled. AI features will be disabled." Rails.logger.warn "[decidim-ai] Initializer - Spam detection enabled: #{Rails.application.secrets.dig(:decidim, :ai, :spam_detection, :enabled).presence || false}" end diff --git a/config/locales/en.yml b/config/locales/en.yml index c3eaaf25de..dc0d31831e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -58,9 +58,9 @@ en: frequency_label: daily: today weekly: this week - subject: AI spam detection summary - %{count} spam items detected (%{frequency_label}) + subject: Reports summary - %{count} spam (%{frequency_label}) summary: |- - AI anti-spam summary for %{organization}: %{count} items were automatically flagged %{frequency_label} by the Decidim AI system.

+ Reports summary for %{organization}: %{count} items were flagged %{frequency_label}.

View detected spams. authorization_handlers: data_authorization_handler: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index de319c03ae..1b95e2180c 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -68,7 +68,7 @@ fr: weekly: cette semaine subject: Résumé anti-spam, %{count} spams détectés (%{frequency_label}) summary: |- - Résumé IA anti-spam pour %{organization} : %{count} contenus ont été automatiquement signalés %{frequency_label} par le système Decidim AI.

+ Résumé anti-spam pour %{organization} : %{count} contenus ont été signalés %{frequency_label}.

Voir les spams détectés. authorization_handlers: data_authorization_handler: diff --git a/config/secrets.yml b/config/secrets.yml index c0479a2f82..f064c2f871 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -52,7 +52,7 @@ decidim_default: &decidim_default repetition_times: <%= Decidim::Env.new("DECIDIM_ADMIN_PASSWORD_REPETITION_TIMES", 5).to_i %> strong: <%= Decidim::Env.new("DECIDIM_ADMIN_PASSWORD_STRONG", true).to_boolean_string %> ai: - enabled: <%= Decidim::Env.new("DECIDIM_AI_ENABLED", true).to_boolean_string %> + enabled: <%= Decidim::Env.new("DECIDIM_AI_ENABLED", false).to_boolean_string %> user_spam_analyzer_enabled: <%= Decidim::Env.new("DECIDIM_AI_USER_SPAM_ANALYZER_ENABLED", true).to_boolean_string %> generic_spam_analyzer_enabled: <%= Decidim::Env.new("DECIDIM_AI_GENERIC_SPAM_ANALYZER_ENABLED", true).to_boolean_string %> endpoint: <%= Decidim::Env.new("DECIDIM_AI_ENDPOINT").to_s %>