Rename comment-mentioned-user class added by Html::Parser (#13263)
* Rename comment-mentioned-user class added by Html::Parser * Add DataUpdateScripts for resaving articles, comments, and messages * Swap order of messages and articles DUS
This commit is contained in:
parent
e6dcfb62ae
commit
956caf69c7
10 changed files with 39 additions and 12 deletions
|
|
@ -1114,7 +1114,7 @@
|
|||
color: gray;
|
||||
width: max-content;
|
||||
}
|
||||
.comment-mentioned-all {
|
||||
.mentioned-all {
|
||||
color: rgb(213, 138, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -689,8 +689,8 @@ class Article < ApplicationRecord
|
|||
def user_mentions_in_markdown
|
||||
return if created_at.present? && created_at.before?(MAX_USER_MENTION_LIVE_AT)
|
||||
|
||||
# The "comment-mentioned-user" css is added by Html::Parser#user_link_if_exists
|
||||
mentions_count = Nokogiri::HTML(processed_html).css(".comment-mentioned-user").size
|
||||
# The "mentioned-user" css is added by Html::Parser#user_link_if_exists
|
||||
mentions_count = Nokogiri::HTML(processed_html).css(".mentioned-user").size
|
||||
return if mentions_count <= MAX_USER_MENTIONS
|
||||
|
||||
errors.add(:base, "You cannot mention more than #{MAX_USER_MENTIONS} users in a post!")
|
||||
|
|
|
|||
|
|
@ -313,8 +313,8 @@ class Comment < ApplicationRecord
|
|||
def user_mentions_in_markdown
|
||||
return if created_at.present? && created_at.before?(MAX_USER_MENTION_LIVE_AT)
|
||||
|
||||
# The "comment-mentioned-user" css is added by Html::Parser#user_link_if_exists
|
||||
mentions_count = Nokogiri::HTML(processed_html).css(".comment-mentioned-user").size
|
||||
# The "mentioned-user" css is added by Html::Parser#user_link_if_exists
|
||||
mentions_count = Nokogiri::HTML(processed_html).css(".mentioned-user").size
|
||||
return if mentions_count <= MAX_USER_MENTIONS
|
||||
|
||||
errors.add(:base, "You cannot mention more than #{MAX_USER_MENTIONS} users in a comment!")
|
||||
|
|
|
|||
|
|
@ -86,11 +86,11 @@ class Message < ApplicationRecord
|
|||
username = mention.delete("@").downcase
|
||||
if User.find_by(username: username) && chat_channel.group?
|
||||
<<~HTML
|
||||
<a class='comment-mentioned-user' data-content="sidecar-user" href='/#{username}' target="_blank" rel="noopener">@#{username}</a>
|
||||
<a class='mentioned-user' data-content="sidecar-user" href='/#{username}' target="_blank" rel="noopener">@#{username}</a>
|
||||
HTML
|
||||
elsif username == "all" && chat_channel.channel_type == "invite_only"
|
||||
<<~HTML
|
||||
<a class='comment-mentioned-user comment-mentioned-all' data-content="chat_channel_setting" href="#">@#{username}</a>
|
||||
<a class='mentioned-user mentioned-all' data-content="chat_channel_setting" href="#">@#{username}</a>
|
||||
HTML
|
||||
else
|
||||
mention
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ module Html
|
|||
username = mention.delete("@").downcase
|
||||
if User.find_by(username: username)
|
||||
<<~HTML
|
||||
<a class='comment-mentioned-user' href='#{ApplicationConfig['APP_PROTOCOL']}#{SiteConfig.app_domain}/#{username}'>@#{username}</a>
|
||||
<a class='mentioned-user' href='#{ApplicationConfig['APP_PROTOCOL']}#{SiteConfig.app_domain}/#{username}'>@#{username}</a>
|
||||
HTML
|
||||
else
|
||||
mention
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ module Mentions
|
|||
end
|
||||
|
||||
def extract_usernames_from_mentions_in_text
|
||||
# The "comment-mentioned-user" css is added by Html::Parser#user_link_if_exists
|
||||
# The "mentioned-user" css is added by Html::Parser#user_link_if_exists
|
||||
doc = Nokogiri::HTML(notifiable.processed_html)
|
||||
doc.css(".comment-mentioned-user").map do |link|
|
||||
doc.css(".mentioned-user").map do |link|
|
||||
link.text.delete("@").downcase
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
module DataUpdateScripts
|
||||
class ResaveAllCommentMentionedMessages
|
||||
def run
|
||||
# Resave all Messages that previously relied upon the `.comment-mentioned-user` CSS,
|
||||
# which was renamed in https://github.com/forem/forem/pull/13263 to `.mentioned-user`.
|
||||
Message.find_each(&:save)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
module DataUpdateScripts
|
||||
class ResaveAllCommentMentionedComments
|
||||
def run
|
||||
# Resave all Comments that previously relied upon the `.comment-mentioned-user` CSS,
|
||||
# which was renamed in https://github.com/forem/forem/pull/13263 to `.mentioned-user`.
|
||||
Comment.find_each(&:save)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
module DataUpdateScripts
|
||||
class ResaveAllCommentMentionedArticles
|
||||
def run
|
||||
# Resave all Articles that previously relied upon the `.comment-mentioned-user` CSS,
|
||||
# which was renamed in https://github.com/forem/forem/pull/13263 to `.mentioned-user`.
|
||||
Article.published.find_each(&:save)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -190,7 +190,7 @@ RSpec.describe MarkdownProcessor::Parser, type: :service do
|
|||
DOC
|
||||
result = generate_and_parse_markdown(mention)
|
||||
|
||||
expected_result = "<p><code>@#{user.username}</code> one two, <a class=\"comment-mentioned-user\" " \
|
||||
expected_result = "<p><code>@#{user.username}</code> one two, <a class=\"mentioned-user\" " \
|
||||
"href=\"#{ApplicationConfig['APP_PROTOCOL']}#{ApplicationConfig['APP_DOMAIN']}/#{user.username}\">" \
|
||||
"@#{user.username}</a>\n three four:</p>\n\n<ul>\n<li><code>@#{user.username}</code></li>\n</ul>\n\n"
|
||||
expect(result).to eq(expected_result)
|
||||
|
|
@ -206,7 +206,7 @@ RSpec.describe MarkdownProcessor::Parser, type: :service do
|
|||
it "works with markdown heavy contents" do
|
||||
mention = "test **[link?](https://dev.to/ben/)** thread, @#{user.username} talks :"
|
||||
result = generate_and_parse_markdown(mention)
|
||||
expect(result).to include "<a class=\"comment-mentioned-user\""
|
||||
expect(result).to include "<a class=\"mentioned-user\""
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue