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.rbindex ce78ed1433a..6b89da4f873 100644--- a/app/models/topic.rb+++ b/app/models/topic.rb@@ -164,7 +164,6 @@ class Topic < ActiveRecord::Basetopic_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.ymlindex 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.rbindex 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_tokenif cookie = request&.cookies[Auth::DefaultCurrentUserProvider::TOKEN_COOKIE]UserAuthToken.hash_token(cookie)diff --git a/lib/post_revisor.rb b/lib/post_revisor.rbindex 1cfc60a8dc0..42b70d00380 100644--- a/lib/post_revisor.rb+++ b/lib/post_revisor.rb@@ -77,12 +77,7 @@ class PostRevisorendtrack_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, attributeendtrack_topic_field(:archetype) do |topic_changes, attribute|diff --git a/lib/url_helper.rb b/lib/url_helper.rbindex f55b40e02ab..b1f10df26cd 100644--- a/lib/url_helper.rb+++ b/lib/url_helper.rb@@ -65,11 +65,6 @@ class UrlHelperAddressable::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)).pathRails.application.routes.recognize_path(path)diff --git a/lib/validators/urls_in_topic_title_validator.rb b/lib/validators/urls_in_topic_title_validator.rbdeleted file mode 100644index 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-enddiff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rbindex 424fa1279f2..ec5bf414631 100644--- a/spec/requests/posts_controller_spec.rb+++ b/spec/requests/posts_controller_spec.rb@@ -1459,33 +1459,6 @@ describe PostsController doendend- 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" doit "allows to create topics with featured links" dosign_in(user_trust_level_1)diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex 9cd8c369c7b..0bbafc88900 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -1653,29 +1653,6 @@ RSpec.describe TopicsController doendend- 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" dodef fabricate_topic(user, category = nil)topic = Fabricate(:topic, user: user, category: category)