Simplify URL validation in related content
We were using `Setting["url"]` to verify the content belonged to the application URL, but we can use `root_url` instead. Note that means we need to include the port when filling in forms in the tests, since in tests URL helpers like `polymorphic_url` don't include the port, but a port is automatically added when actually making the request.
This commit is contained in:
@@ -18,7 +18,7 @@ class RelatedContentsController < ApplicationController
|
||||
elsif related_content.duplicate?
|
||||
flash[:error] = t("related_content.error_duplicate")
|
||||
else
|
||||
flash[:error] = t("related_content.error", url: Setting["url"])
|
||||
flash[:error] = t("related_content.error", url: root_url)
|
||||
end
|
||||
redirect_to polymorphic_path(related_content.parent_relationable)
|
||||
end
|
||||
@@ -41,7 +41,7 @@ class RelatedContentsController < ApplicationController
|
||||
end
|
||||
|
||||
def valid_url?
|
||||
params[:url].start_with?(Setting["url"])
|
||||
params[:url].start_with?(root_url)
|
||||
end
|
||||
|
||||
def child_relationable_params
|
||||
|
||||
Reference in New Issue
Block a user