Better Error Msg when Listing URL embedded and Listings are disabled (#17116)
* complete implementations and specs * remove unused error msgs * add "listing" and "listings" as ReservedWords
This commit is contained in:
parent
73d6d9802e
commit
5cf2229b58
5 changed files with 25 additions and 2 deletions
|
|
@ -27,6 +27,10 @@ module UnifiedEmbed
|
|||
# Extract just the URL from the input, without any params, for validation
|
||||
actual_link = extract_only_url(stripped_input)
|
||||
|
||||
# When Listings are disabled, it makes little sense to perform a validate_link
|
||||
# network call.
|
||||
handle_listings_disabled!(actual_link)
|
||||
|
||||
# Before matching against the embed registry, we check if the link
|
||||
# is valid (e.g. no typos).
|
||||
# If the link is invalid, we raise an error encouraging the user to
|
||||
|
|
@ -66,6 +70,12 @@ module UnifiedEmbed
|
|||
raise StandardError, I18n.t("liquid_tags.unified_embed.tag.invalid_url")
|
||||
end
|
||||
|
||||
def self.handle_listings_disabled!(link)
|
||||
return unless link.start_with?("#{URL.url}/listings/") && !Listing.feature_enabled?
|
||||
|
||||
raise StandardError, I18n.t("liquid_tags.unified_embed.tag.listings_disabled")
|
||||
end
|
||||
|
||||
def self.extract_only_url(input)
|
||||
url_portion = input.split.length > 1 ? input.split[0] : input
|
||||
|
||||
|
|
|
|||
|
|
@ -116,6 +116,8 @@ class ReservedWords
|
|||
links
|
||||
linux
|
||||
listen
|
||||
listing
|
||||
listings
|
||||
live
|
||||
live_articles
|
||||
loop
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ en:
|
|||
tag:
|
||||
invalid_url: URL provided may have a typo or error; please check and try again
|
||||
not_found: URL provided was not found; please check and try again
|
||||
unsupported_url: Embeds for this URL are not supported
|
||||
listings_disabled: Listings are disabled on this Forem; cannot embed a listing URL
|
||||
user_subscription_tag:
|
||||
submit: Submit
|
||||
submitting: Submitting...
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ fr:
|
|||
tag:
|
||||
invalid_url: URL provided may have a typo or error; please check and try again
|
||||
not_found: URL provided was not found; please check and try again
|
||||
unsupported_url: Embeds for this URL are not supported
|
||||
listings_disabled: Listings are disabled on this Forem; cannot embed a listing URL
|
||||
user_subscription_tag:
|
||||
submit: Submit
|
||||
submitting: Submitting...
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe UnifiedEmbed::Tag, type: :liquid_tag do
|
||||
let(:listing) { create(:listing) }
|
||||
|
||||
it "delegates parsing to the link-matching class" do
|
||||
link = "https://gist.github.com/jeremyf/662585f5c4d22184a6ae133a71bf891a"
|
||||
|
||||
|
|
@ -72,4 +74,13 @@ RSpec.describe UnifiedEmbed::Tag, type: :liquid_tag do
|
|||
|
||||
expect(OpenGraphTag).to have_received(:new)
|
||||
end
|
||||
|
||||
it "raises an error when Listings are disabled and a listing URL is embedded" do
|
||||
allow(FeatureFlag).to receive(:accessible?).with(:listing_feature_enabled).and_return(false)
|
||||
listing_url = "#{URL.url}/listings/#{listing.slug}"
|
||||
|
||||
expect do
|
||||
Liquid::Template.parse("{% embed #{listing_url} %}")
|
||||
end.to raise_error(StandardError, "Listings are disabled on this Forem; cannot embed a listing URL")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue