mirror of
https://github.com/discourse/discourse.git
synced 2026-08-10 04:58:31 -05: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:
@@ -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)
|
||||
|
||||
+1
-6
@@ -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|
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user