Skip to content
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
2 changes: 1 addition & 1 deletion .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -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://<ENDPOINT_URL>"
Expand Down
5 changes: 1 addition & 4 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

Expand Down Expand Up @@ -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.
10 changes: 0 additions & 10 deletions .github/ISSUE_TEMPLATE/tracking.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions config/initializers/decidim_ai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br><br>
Reports summary for %{organization}: %{count} items were flagged %{frequency_label}.<br><br>
<a href="%{moderations_url}" target="_blank">View detected spams</a>.
authorization_handlers:
data_authorization_handler:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br><br>
Résumé anti-spam pour %{organization} : %{count} contenus ont été signalés %{frequency_label}.<br><br>
<a href="%{moderations_url}" target="_blank">Voir les spams détectés</a>.
authorization_handlers:
data_authorization_handler:
Expand Down
2 changes: 1 addition & 1 deletion config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
Loading