Rules: Fix no action conditions (#447)

* Fix Rules page when no action on rule

* Reject new rules without actions

* Rule with no action translation

* Easy one to keep translations going

* Fix tests

* Learn something new every day

---------

Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
Dylan Corrales
2025-12-12 10:58:57 -05:00
committed by GitHub
parent 3e5dfc0263
commit 70b050e4a4
11 changed files with 40 additions and 25 deletions

View File

@@ -155,14 +155,14 @@ module LanguagesHelper
# Locales with complete/extensive translations
SUPPORTED_LOCALES = [
"en", # English - 61 translation files
"en", # English - 62 translation files
"de", # German - 62 translation files
"es", # Spanish - 60 translation files
"tr", # Turkish - 57 translation files
"nb", # Norwegian Bokmål - 56 translation files
"ca", # Catalan - 56 translation files
"ro", # Romanian - 61 translation files
"pt-BR" # Brazilian Portuguese - 60 translation files
"es", # Spanish - 61 translation files
"tr", # Turkish - 58 translation files
"nb", # Norwegian Bokmål - 57 translation files
"ca", # Catalan - 57 translation files
"ro", # Romanian - 62 translation files
"pt-BR" # Brazilian Portuguese - 60 translation files
].freeze
COUNTRY_MAPPING = {

View File

@@ -101,7 +101,7 @@ class Rule < ApplicationRecord
end
def min_actions
return if new_record? && actions.empty?
return if new_record? && !actions.empty?
if actions.reject(&:marked_for_destruction?).empty?
errors.add(:base, "must have at least one action")

View File

@@ -30,10 +30,14 @@
</div>
<p class="flex items-center flex-wrap gap-1.5 m-0">
<span class="px-2 py-1 border border-secondary rounded-full">
<% if rule.actions.first.value && rule.actions.first.options %>
<%= rule.actions.first.executor.label %> to <%= rule.actions.first.value_display %>
<% if rule.actions.first.nil? %>
<%= t("rules.no_action") %>
<% else %>
<%= rule.actions.first.executor.label %>
<% if rule.actions.first.value && rule.actions.first.options %>
<%= rule.actions.first.executor.label %> to <%= rule.actions.first.value_display %>
<% else %>
<%= rule.actions.first.executor.label %>
<% end %>
<% end %>
</span>
<% if rule.actions.count > 1 %>