From 1375d27554e6a6074307ce8734724f55231ebf76 Mon Sep 17 00:00:00 2001 From: Cesium-Ice Date: Sun, 15 Dec 2024 03:48:34 -0800 Subject: [PATCH] AO3-6792: fix logic to account for the fact that language_params can be blank (#4988) * fix logic to account for the fact that language_params can be blank * fix brackets that the linter messed up * address PR comment --- app/controllers/languages_controller.rb | 4 ++-- features/admins/admin_languages.feature | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/languages_controller.rb b/app/controllers/languages_controller.rb index 13e5055c9ef..d56edce2313 100644 --- a/app/controllers/languages_controller.rb +++ b/app/controllers/languages_controller.rb @@ -31,13 +31,13 @@ def update @language = Language.find_by(short: params[:id]) authorize @language - if !policy(@language).can_edit_non_abuse_fields? && (@language.name != language_params[:name] || @language.short != language_params[:short] || @language.sortable_name != language_params[:sortable_name] || @language.support_available != (language_params[:support_available] == "1")) + if !policy(@language).can_edit_non_abuse_fields? && ((language_params[:name].present? && language_params[:name] != @language.name) || (language_params[:short].present? && @language.short != language_params[:short]) || (language_params[:sortable_name].present? && @language.sortable_name != language_params[:sortable_name]) || (language_params[:support_available].present? && @language.support_available != (language_params[:support_available] == "1"))) flash[:error] = t("languages.update.non_abuse_field_error") redirect_to languages_path return end - if !policy(@language).can_edit_abuse_fields? && (@language.abuse_support_available != (language_params[:abuse_support_available] == "1")) + if !policy(@language).can_edit_abuse_fields? && language_params[:abuse_support_available].present? && (@language.abuse_support_available != (language_params[:abuse_support_available] == "1")) flash[:error] = t("languages.update.abuse_field_error") redirect_to languages_path return diff --git a/features/admins/admin_languages.feature b/features/admins/admin_languages.feature index cda790115f0..83cdd68e72a 100644 --- a/features/admins/admin_languages.feature +++ b/features/admins/admin_languages.feature @@ -22,7 +22,7 @@ Scenario: Adding Abuse support for a language | name | short | | Arabic | ar | | Espanol | es | - When I am logged in as a "translation" admin + When I am logged in as a "policy_and_abuse" admin And I go to the languages page # Languages are sorted by short name, so the first "Edit" is for Arabic And I follow "Edit" @@ -39,7 +39,7 @@ Scenario: Adding a language to the Support form | name | short | | Sindarin | sj | | Klingon | tlh | - When I am logged in as a "translation" admin + When I am logged in as a "support" admin And I go to the languages page # Languages are sorted by short name, so the first "Edit" is for Sindarin And I follow "Edit"