Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: revert disallowing putting URLs in titles for TL0 users (#13970)

Andrei Prigorshnev09ad3ed41d98
diff --git a/app/models/topic.rb b/app/models/topic.rb
index ce78ed1433a..6b89da4f873 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -164,7 +164,6 @@ class Topic < ActiveRecord::Base
topic_title_length: true,
censored_words: true,
watched_words: true,
- urls_in_topic_title: true,
quality_title: { unless: :private_message? },
max_emojis: true,
unique_among: { unless: Proc.new { |t| (SiteSetting.allow_duplicate_topic_titles? || t.private_message?) },
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index c5c22c7d75e..04e3d207084 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -358,7 +358,6 @@ en:
other: "Sorry, new users can only put %{count} attachments in a post."
no_links_allowed: "Sorry, new users can't put links in posts."
links_require_trust: "Sorry, you can't include links in your posts."
- urls_in_title_require_trust_level: "Sorry, new users can't include links in topic titles."
too_many_links:
one: "Sorry, new users can only put one link in a post."
other: "Sorry, new users can only put %{count} links in a post."
diff --git a/lib/guardian.rb b/lib/guardian.rb
index 77e32aa3d02..54822b95b92 100644
--- a/lib/guardian.rb
+++ b/lib/guardian.rb
@@ -540,10 +540,6 @@ class Guardian
!SiteSetting.login_required? || authenticated?
end
- def can_put_urls_in_topic_title?
- @user.trust_level >= TrustLevel.levels[:basic]
- end
-
def auth_token
if cookie = request&.cookies[Auth::DefaultCurrentUserProvider::TOKEN_COOKIE]
UserAuthToken.hash_token(cookie)
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index 1cfc60a8dc0..42b70d00380 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -77,12 +77,7 @@ class PostRevisor
end
track_topic_field(:title) do |topic_changes, attribute|
- if UrlHelper.contains_url?(attribute) && !topic_changes.guardian.can_put_urls_in_topic_title?
- topic_changes.topic.errors.add(:base, I18n.t("urls_in_title_require_trust_level"))
- topic_changes.check_result(false)
- else
- track_and_revise topic_changes, :title, attribute
- end
+ track_and_revise topic_changes, :title, attribute
end
track_topic_field(:archetype) do |topic_changes, attribute|
diff --git a/lib/url_helper.rb b/lib/url_helper.rb
index f55b40e02ab..b1f10df26cd 100644
--- a/lib/url_helper.rb
+++ b/lib/url_helper.rb
@@ -65,11 +65,6 @@ class UrlHelper
Addressable::URI.normalized_encode(uri)
end
- def self.contains_url?(string)
- uri_regexp = Discourse::Utils::URI_REGEXP
- uri_regexp.match?(string)
- end
-
def self.rails_route_from_url(url)
path = URI.parse(encode(url)).path
Rails.application.routes.recognize_path(path)
diff --git a/lib/validators/urls_in_topic_title_validator.rb b/lib/validators/urls_in_topic_title_validator.rb
deleted file mode 100644
index 1bb03bc95b1..00000000000
--- a/lib/validators/urls_in_topic_title_validator.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class UrlsInTopicTitleValidator < ActiveModel::Validator
- def validate(record)
- if UrlHelper.contains_url?(record.title) && !can_put_urls?(record)
- record.errors.add(:base, error_message)
- end
- end
-
- private
-
- def can_put_urls?(topic)
- guardian = Guardian.new(topic.acting_user)
- guardian.can_put_urls_in_topic_title?
- end
-
- def error_message
- I18n.t("urls_in_title_require_trust_level")
- end
-end
diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rb
index 424fa1279f2..ec5bf414631 100644
--- a/spec/requests/posts_controller_spec.rb
+++ b/spec/requests/posts_controller_spec.rb
@@ -1459,33 +1459,6 @@ describe PostsController do
end
end
- describe "urls in the title" do
- let!(:title_with_url) { "A title with the URL https://google.com" }
-
- it "doesn't allow TL0 users to put urls into the title" do
- sign_in(user_trust_level_0)
-
- post "/posts.json", params: {
- raw: 'this is the test content',
- title: title_with_url
- }
-
- expect(response.status).to eq(422)
- expect(response.body).to include(I18n.t('urls_in_title_require_trust_level'))
- end
-
- it "allows TL1 users to put urls into the title" do
- sign_in(user_trust_level_1)
-
- post "/posts.json", params: {
- raw: 'this is the test content',
- title: title_with_url
- }
-
- expect(response.status).to eq(200)
- end
- end
-
describe "featured links" do
it "allows to create topics with featured links" do
sign_in(user_trust_level_1)
diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb
index 9cd8c369c7b..0bbafc88900 100644
--- a/spec/requests/topics_controller_spec.rb
+++ b/spec/requests/topics_controller_spec.rb
@@ -1653,29 +1653,6 @@ RSpec.describe TopicsController do
end
end
- describe "urls in the title" do
- let!(:title_with_url) { "A title with the URL https://google.com" }
-
- it "doesn't allow TL0 users to put urls into the title" do
- sign_in(trust_level_0)
- topic = Fabricate(:topic, user: trust_level_0)
- Fabricate(:post, topic: topic)
- put "/t/#{topic.slug}/#{topic.id}.json", params: { title: title_with_url }
-
- expect(response.status).to eq(422)
- expect(response.body).to include(I18n.t('urls_in_title_require_trust_level'))
- end
-
- it "allows TL1 users to put urls into the title" do
- sign_in(trust_level_1)
- topic = Fabricate(:topic, user: trust_level_1)
- Fabricate(:post, topic: topic)
- put "/t/#{topic.slug}/#{topic.id}.json", params: { title: title_with_url }
-
- expect(response.status).to eq(200)
- end
- end
-
describe "featured links" do
def fabricate_topic(user, category = nil)
topic = Fabricate(:topic, user: user, category: category)