Skip to content

Commit

Permalink
AO3-6792: fix logic to account for the fact that language_params can …
Browse files Browse the repository at this point in the history
…be blank (otwcode#4988)

* fix logic to account for the fact that language_params can be blank

* fix brackets that the linter messed up

* address PR comment
  • Loading branch information
Cesium-Ice authored Dec 15, 2024
1 parent 56ecdc6 commit 1375d27
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/controllers/languages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions features/admins/admin_languages.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 1375d27

Please sign in to comment.