From 70970bb7915c1b3911dd72dda7b4a0c463241824 Mon Sep 17 00:00:00 2001 From: Daniel Waterworth Date: Mon, 29 Mar 2021 13:36:59 -0500 Subject: [PATCH] FIX: Show error messages when adding permalinks in the admin UI (#12545) Also, check for uniqueness of permalinks before attempting to save. --- .../javascripts/admin/addon/components/permalink-form.js | 8 ++++++-- app/models/permalink.rb | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admin/addon/components/permalink-form.js b/app/assets/javascripts/admin/addon/components/permalink-form.js index a5a8a95e35a..da8f947170c 100644 --- a/app/assets/javascripts/admin/addon/components/permalink-form.js +++ b/app/assets/javascripts/admin/addon/components/permalink-form.js @@ -69,9 +69,13 @@ export default Component.extend({ this.set("formSubmitted", false); let error; - if (e.responseJSON && e.responseJSON.errors) { + if ( + e.jqXHR && + e.jqXHR.responseJSON && + e.jqXHR.responseJSON.errors + ) { error = I18n.t("generic_error_with_reason", { - error: e.responseJSON.errors.join(". "), + error: e.jqXHR.responseJSON.errors.join(". "), }); } else { error = I18n.t("generic_error"); diff --git a/app/models/permalink.rb b/app/models/permalink.rb index 844678923d8..11ea908d9f6 100644 --- a/app/models/permalink.rb +++ b/app/models/permalink.rb @@ -8,6 +8,8 @@ class Permalink < ActiveRecord::Base before_validation :normalize_url + validates :url, uniqueness: true + class Normalizer attr_reader :source