diff --git a/app/controllers/languages_controller.rb b/app/controllers/languages_controller.rb index 13e5055c9e..122b49ab07 100644 --- a/app/controllers/languages_controller.rb +++ b/app/controllers/languages_controller.rb @@ -25,6 +25,10 @@ def create def edit @language = Language.find_by(short: params[:id]) authorize @language + return unless @language == Language.default + + flash[:error] = t("languages.cannot_edit_default") + redirect_to languages_path end def update diff --git a/config/locales/controllers/en.yml b/config/locales/controllers/en.yml index b310e50079..06869fe5e0 100644 --- a/config/locales/controllers/en.yml +++ b/config/locales/controllers/en.yml @@ -105,6 +105,7 @@ en: create: success: Thank you for leaving kudos! languages: + cannot_edit_default: Sorry, you can't edit the default language. successfully_added: Language was successfully added. successfully_updated: Language was successfully updated. update: diff --git a/spec/controllers/languages_controller_spec.rb b/spec/controllers/languages_controller_spec.rb index 2465a78995..ceab7e460a 100644 --- a/spec/controllers/languages_controller_spec.rb +++ b/spec/controllers/languages_controller_spec.rb @@ -140,14 +140,21 @@ end %w[translation superadmin support policy_and_abuse].each do |role| + Language.create(name: "Deutsch", short: "de") context "when logged in as an admin with #{role} role" do let(:admin) { create(:admin, roles: [role]) } - it "renders the edit template" do + it "renders the edit template for a non-default language" do fake_login_admin(admin) - get :edit, params: { id: "en" } + get :edit, params: { id: "de" } expect(response).to render_template("edit") end + + it "redirects for the default language" do + fake_login_admin(admin) + get :edit, params: { id: "en" } + it_redirects_to_with_error(languages_path, "Sorry, you can't edit the default language.") + end end end end