FIX: Various fixes to support posts with no user (#8877)
* Do not grant badges for posts with no user * Ensure instructions are correct in Change Owner modal * Hide user-dependent actions from posts with no user * Make PostRevisor work with posts with no user * Ensure posts with no user can be deleted * discourse-narrative-bot should ignore posts with no user * Skip TopicLink creation for posts with no user
This commit is contained in:
parent
6fdb4c33a6
commit
0754c7c404
app
assets/javascripts/discourse
models
config/locales
lib
plugins/discourse-narrative-bot
|
@ -1,6 +1,8 @@
|
|||
{{#d-modal-body class='change-ownership'}}
|
||||
<span>
|
||||
{{i18n 'topic.change_owner.instructions' count=selectedPostsCount old_user=selectedPostsUsername}}
|
||||
{{i18n (if selectedPostsUsername 'topic.change_owner.instructions' 'topic.change_owner.instructions_without_old_user')
|
||||
count=selectedPostsCount
|
||||
old_user=selectedPostsUsername}}
|
||||
</span>
|
||||
|
||||
<form>
|
||||
|
|
|
@ -73,7 +73,7 @@ export function buildManageButtons(attrs, currentUser, siteSettings) {
|
|||
});
|
||||
}
|
||||
|
||||
if (currentUser.staff) {
|
||||
if (attrs.user_id && currentUser.staff) {
|
||||
if (siteSettings.enable_badges) {
|
||||
contents.push({
|
||||
icon: "certificate",
|
||||
|
|
|
@ -108,7 +108,7 @@ class TopicLink < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.extract_from(post)
|
||||
return if post.blank? || post.whisper?
|
||||
return if post.blank? || post.whisper? || post.user_id.blank?
|
||||
|
||||
current_urls = []
|
||||
reflected_ids = []
|
||||
|
|
|
@ -2420,6 +2420,9 @@ en:
|
|||
instructions:
|
||||
one: "Please choose a new owner for the post by <b>@{{old_user}}</b>"
|
||||
other: "Please choose a new owner for the {{count}} posts by <b>@{{old_user}}</b>"
|
||||
instructions_without_old_user:
|
||||
one: "Please choose a new owner for the post"
|
||||
other: "Please choose a new owner for the {{count}} posts"
|
||||
|
||||
change_timestamp:
|
||||
title: "Change Timestamp..."
|
||||
|
|
|
@ -56,7 +56,7 @@ class CookedPostProcessor
|
|||
end
|
||||
|
||||
def grant_badges
|
||||
return unless Guardian.new.can_see?(@post)
|
||||
return if @post.user.blank? || !Guardian.new.can_see?(@post)
|
||||
|
||||
BadgeGranter.grant(Badge.find(Badge::FirstEmoji), @post.user, post_id: @post.id) if has_emoji?
|
||||
BadgeGranter.grant(Badge.find(Badge::FirstOnebox), @post.user, post_id: @post.id) if @has_oneboxes
|
||||
|
|
|
@ -30,7 +30,7 @@ module PostGuardian
|
|||
return false unless (can_see_post.nil? && can_see_post?(post)) || can_see_post
|
||||
|
||||
# no warnings except for staff
|
||||
return false if (action_key == :notify_user && !is_staff? && opts[:is_warning].present? && opts[:is_warning] == 'true')
|
||||
return false if action_key == :notify_user && (post.user.blank? || (!is_staff? && opts[:is_warning].present? && opts[:is_warning] == 'true'))
|
||||
|
||||
taken = opts[:taken_actions].try(:keys).to_a
|
||||
is_flag = PostActionType.notify_flag_types[action_key]
|
||||
|
@ -71,7 +71,7 @@ module PostGuardian
|
|||
not(post.trashed?) &&
|
||||
|
||||
# don't like your own stuff
|
||||
not(action_key == :like && is_my_own?(post))
|
||||
not(action_key == :like && (post.user.blank? || is_my_own?(post)))
|
||||
end
|
||||
|
||||
!!result
|
||||
|
|
|
@ -276,6 +276,8 @@ class PostDestroyer
|
|||
end
|
||||
|
||||
def notify_deletion(reviewable)
|
||||
return if @post.user.blank?
|
||||
|
||||
allowed_user = @user.human? && @user.staff?
|
||||
return unless allowed_user && rs = reviewable.reviewable_scores.order('created_at DESC').first
|
||||
|
||||
|
|
|
@ -180,13 +180,13 @@ class PostRevisor
|
|||
@fields.has_key?('raw') &&
|
||||
@editor.staff? &&
|
||||
@editor != Discourse.system_user &&
|
||||
!@post.user.staff?
|
||||
!@post.user&.staff?
|
||||
)
|
||||
PostLocker.new(@post, @editor).lock
|
||||
end
|
||||
|
||||
# We log staff edits to posts
|
||||
if @editor.staff? && @editor.id != @post.user.id && @fields.has_key?('raw') && !@opts[:skip_staff_log]
|
||||
if @editor.staff? && @editor.id != @post.user_id && @fields.has_key?('raw') && !@opts[:skip_staff_log]
|
||||
StaffActionLogger.new(@editor).log_post_edit(
|
||||
@post,
|
||||
old_raw: old_raw
|
||||
|
|
|
@ -178,7 +178,7 @@ after_initialize do
|
|||
self.on(:post_created) do |post, options|
|
||||
user = post.user
|
||||
|
||||
if user.enqueue_narrative_bot_job? && !options[:skip_bot]
|
||||
if user&.enqueue_narrative_bot_job? && !options[:skip_bot]
|
||||
Jobs.enqueue(:bot_input,
|
||||
user_id: user.id,
|
||||
post_id: post.id,
|
||||
|
@ -188,7 +188,7 @@ after_initialize do
|
|||
end
|
||||
|
||||
self.on(:post_edited) do |post|
|
||||
if post.user.enqueue_narrative_bot_job?
|
||||
if post.user&.enqueue_narrative_bot_job?
|
||||
Jobs.enqueue(:bot_input,
|
||||
user_id: post.user.id,
|
||||
post_id: post.id,
|
||||
|
@ -198,7 +198,7 @@ after_initialize do
|
|||
end
|
||||
|
||||
self.on(:post_destroyed) do |post, options, user|
|
||||
if user.enqueue_narrative_bot_job? && !options[:skip_bot]
|
||||
if user&.enqueue_narrative_bot_job? && !options[:skip_bot]
|
||||
Jobs.enqueue(:bot_input,
|
||||
user_id: user.id,
|
||||
post_id: post.id,
|
||||
|
@ -209,7 +209,7 @@ after_initialize do
|
|||
end
|
||||
|
||||
self.on(:post_recovered) do |post, _, user|
|
||||
if user.enqueue_narrative_bot_job?
|
||||
if user&.enqueue_narrative_bot_job?
|
||||
Jobs.enqueue(:bot_input,
|
||||
user_id: user.id,
|
||||
post_id: post.id,
|
||||
|
|
Loading…
Reference in New Issue