mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FEATURE: revert disallowing putting URLs in titles for TL0 users (#13970)
This reverts a part of changes introduced by https://github.com/discourse/discourse/pull/13947 In that PR I: 1. Disallowed topic feature links for TL-0 users 2. Additionally, disallowed just putting any URL in topic titles for TL-0 users Actually, we don't need the second part. It introduced unnecessary complexity for no good reason. In fact, it tries to do the job that anti-spam plugins (like Akismet plugin) should be doing. This PR reverts this second change.
This commit is contained in:

committed by
GitHub

parent
0d8fd9ace6
commit
09ad3ed41d
@ -164,7 +164,6 @@ class Topic < ActiveRecord::Base
|
|||||||
topic_title_length: true,
|
topic_title_length: true,
|
||||||
censored_words: true,
|
censored_words: true,
|
||||||
watched_words: true,
|
watched_words: true,
|
||||||
urls_in_topic_title: true,
|
|
||||||
quality_title: { unless: :private_message? },
|
quality_title: { unless: :private_message? },
|
||||||
max_emojis: true,
|
max_emojis: true,
|
||||||
unique_among: { unless: Proc.new { |t| (SiteSetting.allow_duplicate_topic_titles? || t.private_message?) },
|
unique_among: { unless: Proc.new { |t| (SiteSetting.allow_duplicate_topic_titles? || t.private_message?) },
|
||||||
|
@ -358,7 +358,6 @@ en:
|
|||||||
other: "Sorry, new users can only put %{count} attachments in a post."
|
other: "Sorry, new users can only put %{count} attachments in a post."
|
||||||
no_links_allowed: "Sorry, new users can't put links in posts."
|
no_links_allowed: "Sorry, new users can't put links in posts."
|
||||||
links_require_trust: "Sorry, you can't include links in your 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:
|
too_many_links:
|
||||||
one: "Sorry, new users can only put one link in a post."
|
one: "Sorry, new users can only put one link in a post."
|
||||||
other: "Sorry, new users can only put %{count} links in a post."
|
other: "Sorry, new users can only put %{count} links in a post."
|
||||||
|
@ -540,10 +540,6 @@ class Guardian
|
|||||||
!SiteSetting.login_required? || authenticated?
|
!SiteSetting.login_required? || authenticated?
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_put_urls_in_topic_title?
|
|
||||||
@user.trust_level >= TrustLevel.levels[:basic]
|
|
||||||
end
|
|
||||||
|
|
||||||
def auth_token
|
def auth_token
|
||||||
if cookie = request&.cookies[Auth::DefaultCurrentUserProvider::TOKEN_COOKIE]
|
if cookie = request&.cookies[Auth::DefaultCurrentUserProvider::TOKEN_COOKIE]
|
||||||
UserAuthToken.hash_token(cookie)
|
UserAuthToken.hash_token(cookie)
|
||||||
|
@ -77,12 +77,7 @@ class PostRevisor
|
|||||||
end
|
end
|
||||||
|
|
||||||
track_topic_field(:title) do |topic_changes, attribute|
|
track_topic_field(:title) do |topic_changes, attribute|
|
||||||
if UrlHelper.contains_url?(attribute) && !topic_changes.guardian.can_put_urls_in_topic_title?
|
track_and_revise topic_changes, :title, attribute
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
track_topic_field(:archetype) do |topic_changes, attribute|
|
track_topic_field(:archetype) do |topic_changes, attribute|
|
||||||
|
@ -65,11 +65,6 @@ class UrlHelper
|
|||||||
Addressable::URI.normalized_encode(uri)
|
Addressable::URI.normalized_encode(uri)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.contains_url?(string)
|
|
||||||
uri_regexp = Discourse::Utils::URI_REGEXP
|
|
||||||
uri_regexp.match?(string)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.rails_route_from_url(url)
|
def self.rails_route_from_url(url)
|
||||||
path = URI.parse(encode(url)).path
|
path = URI.parse(encode(url)).path
|
||||||
Rails.application.routes.recognize_path(path)
|
Rails.application.routes.recognize_path(path)
|
||||||
|
@ -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
|
|
@ -1459,33 +1459,6 @@ describe PostsController do
|
|||||||
end
|
end
|
||||||
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
|
describe "featured links" do
|
||||||
it "allows to create topics with featured links" do
|
it "allows to create topics with featured links" do
|
||||||
sign_in(user_trust_level_1)
|
sign_in(user_trust_level_1)
|
||||||
|
@ -1653,29 +1653,6 @@ RSpec.describe TopicsController do
|
|||||||
end
|
end
|
||||||
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
|
describe "featured links" do
|
||||||
def fabricate_topic(user, category = nil)
|
def fabricate_topic(user, category = nil)
|
||||||
topic = Fabricate(:topic, user: user, category: category)
|
topic = Fabricate(:topic, user: user, category: category)
|
||||||
|
Reference in New Issue
Block a user