From 1e794b11d84e70f3ce8c6ae3203b950eeb05166c Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Wed, 29 Apr 2020 23:35:05 -0400 Subject: [PATCH] fixes #106: prevent renaming the default filter --- lib/philomena/filters/filter.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/philomena/filters/filter.ex b/lib/philomena/filters/filter.ex index b59aa9a5..b72ae9ea 100644 --- a/lib/philomena/filters/filter.ex +++ b/lib/philomena/filters/filter.ex @@ -59,7 +59,7 @@ defmodule Philomena.Filters.Filter do end def update_changeset(filter, attrs) do - changeset(filter, attrs) + changeset(filter, strip_name_if_default(filter, attrs)) end def deletion_changeset(filter) do @@ -86,4 +86,9 @@ defmodule Philomena.Filters.Filter do changeset end end + + defp strip_name_if_default(%{system: true, name: "Default"}, attrs), + do: Map.delete(attrs, "name") + + defp strip_name_if_default(_filter, attrs), do: attrs end