Fix rule filename not updating when action changes

When editing a rule and changing its action (e.g. deny → allow),
the JSON content updates correctly but the rule name (used as
filename) retains the old action prefix, causing a mismatch
between the filename and the actual rule action.

Update save_rule() to detect auto-generated rule names and
replace the action prefix when the action has changed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Marc Pinol Piqué
2026-03-28 13:39:53 +01:00
parent f2ce074096
commit 91d9abe3a6
@@ -894,5 +894,13 @@ class RulesEditorDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
if self.ruleNameEdit.text() == "":
self.rule.name = slugify("%s %s %s" % (self.rule.action, self.rule.operator.type, self.rule.operator.data))
elif self._old_rule_name is not None:
# If the rule name was auto-generated (starts with an action prefix),
# and the action has changed, update the prefix to match the new action.
for old_action in (Config.ACTION_ALLOW, Config.ACTION_DENY, Config.ACTION_REJECT):
if self._old_rule_name.startswith(old_action + "-") and old_action != self.rule.action:
self.rule.name = self.rule.action + self._old_rule_name[len(old_action):]
self.ruleNameEdit.setText(self.rule.name)
break
return True, ""