diff --git a/app/labor/markdown_fixer.rb b/app/labor/markdown_fixer.rb index cdb2ef726..c3b94b08d 100644 --- a/app/labor/markdown_fixer.rb +++ b/app/labor/markdown_fixer.rb @@ -10,21 +10,24 @@ class MarkdownFixer end def add_quotes_to_title(markdown) - markdown.gsub(/title:\s?(.*?)(\r\n|\n)/m) do |target| - # $1 is the captured group (.*?) - captured_title = $1 - # The query below checks if the whole title is wrapped in - # either single or double quotes. - match = captured_title.scan(/(^".*"$|^'.*'$)/) - if match.empty? - # Double quotes that aren't already escaped will get esacped. - # Then the whole title get warped in double quotes. - parsed_title = captured_title.gsub(/(? 1 ? "#{m}-----" : m } + markdown.gsub(/-{3}.*?-{3}/m) do |front_matter| + front_matter.gsub(/^---/).with_index { |m, i| i > 1 ? "#{m}-----" : m } + end end def convert_new_lines(markdown) diff --git a/app/models/badge_achievement.rb b/app/models/badge_achievement.rb index f45ffe412..f8a6ee48a 100644 --- a/app/models/badge_achievement.rb +++ b/app/models/badge_achievement.rb @@ -48,7 +48,7 @@ class BadgeAchievement < ApplicationRecord def remove_from_feed super if user.class.name == "User" - User.find(user.id)&.touch(:last_notification_activity) + User.find_by(id: user.id)&.touch(:last_notification_activity) end end diff --git a/app/models/chat_channel.rb b/app/models/chat_channel.rb index 1ed72a532..4ea728cd4 100644 --- a/app/models/chat_channel.rb +++ b/app/models/chat_channel.rb @@ -3,9 +3,9 @@ class ChatChannel < ApplicationRecord attr_accessor :current_user has_many :messages - has_many :chat_channel_memberships + has_many :chat_channel_memberships, dependent: :destroy has_many :users, through: :chat_channel_memberships - + has_many :active_memberships, -> { where status: "active" }, class_name: 'ChatChannelMembership' has_many :pending_memberships, -> { where status: "pending" }, class_name: 'ChatChannelMembership' has_many :rejected_memberships, -> { where status: "rejected" }, class_name: 'ChatChannelMembership' diff --git a/app/models/comment.rb b/app/models/comment.rb index 2871d6e8b..3894f3a27 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -175,14 +175,14 @@ class Comment < ApplicationRecord def remove_from_feed super if ancestors.empty? && user != commentable.user - [User.find(commentable.user.id)&.touch(:last_notification_activity)] + [User.find_by(id: commentable.user.id)&.touch(:last_notification_activity)] elsif ancestors user_ids = ancestors.map { |comment| comment.user.id } user_ids = user_ids.uniq.reject { |uid| uid == commentable.user.id } user_ids = user_ids.uniq.reject { |uid| uid == self.user_id } # filters out article author and duplicate users user_ids.map do |id| - User.find(id)&.touch(:last_notification_activity) + User.find_by(id: id)&.touch(:last_notification_activity) end end end diff --git a/app/models/mention.rb b/app/models/mention.rb index 57814ff3d..b4a1e4f47 100644 --- a/app/models/mention.rb +++ b/app/models/mention.rb @@ -64,7 +64,7 @@ class Mention < ApplicationRecord def remove_from_feed super - User.find(user.id)&.touch(:last_notification_activity) + User.find_by(id: user.id)&.touch(:last_notification_activity) end def send_email_notification diff --git a/app/models/notification.rb b/app/models/notification.rb index 8762b8831..b427f7d6a 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -73,7 +73,6 @@ class Notification < ApplicationRecord def remove_from_feed super - User.find(user_id)&.touch(:last_notification_activity) + User.find_by(id: user_id)&.touch(:last_notification_activity) end - end diff --git a/app/models/reaction.rb b/app/models/reaction.rb index df28784c4..94b932c93 100644 --- a/app/models/reaction.rb +++ b/app/models/reaction.rb @@ -56,7 +56,7 @@ class Reaction < ApplicationRecord def remove_from_feed super - User.find(reactable.user.id)&.touch(:last_notification_activity) + User.find_by(id: reactable.user.id)&.touch(:last_notification_activity) end def self.cached_any_reactions_for?(reactable, user, category)