FEATURE: New 'Reviewable' model to make reviewable items generic

Includes support for flags, reviewable users and queued posts, with REST API
backwards compatibility.

Co-Authored-By: romanrizzi <romanalejandro@gmail.com>
Co-Authored-By: jjaffeux <j.jaffeux@gmail.com>
This commit is contained in:
Robin Ward
2019-01-03 12:03:01 -05:00
parent 9a56b398a1
commit b58867b6e9
354 changed files with 8090 additions and 5225 deletions

View File

@ -596,12 +596,9 @@ class ImportScripts::Base
skipped += 1
puts "Skipping bookmark for user id #{params[:user_id]} and post id #{params[:post_id]}"
else
begin
PostAction.act(user, post, PostActionType.types[:bookmark])
created += 1
rescue PostAction::AlreadyActed
skipped += 1
end
result = PostActionCreator.create(user, post, :bookmark)
created += 1 if result.success?
skipped += 1 if result.failed?
end
end

View File

@ -398,7 +398,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
end
elsif (m['status'] & 2) >> 1 == 1 # waiting for approve
mapped[:post_create_action] = lambda do |action_post|
PostAction.act(Discourse.system_user, action_post, 6, take_action: false)
PostActionCreator.notify_user(Discourse.system_user, action_post)
end
end
skip ? nil : mapped

View File

@ -184,8 +184,7 @@ class ImportScripts::JiveApi < ImportScripts::Base
break if likes["error"]
likes["list"].each do |like|
next unless user_id = user_id_from_imported_user_id(like["id"])
next if PostAction.exists?(user_id: user_id, post_id: post_id, post_action_type_id: PostActionType.types[:like])
PostAction.act(User.find(user_id), Post.find(post_id), PostActionType.types[:like])
PostActionCreator.like(User.find(user_id), Post.find(post_id))
end
break if likes["list"].size < USER_COUNT || likes.dig("links", "next").blank?
@ -287,8 +286,7 @@ class ImportScripts::JiveApi < ImportScripts::Base
favorites["list"].each do |favorite|
next unless user_id = user_id_from_imported_user_id(favorite["author"]["id"])
next unless post_id = post_id_from_imported_post_id(favorite["favoriteObject"]["id"])
next if PostAction.exists?(user_id: user_id, post_id: post_id, post_action_type_id: PostActionType.types[:bookmark])
PostAction.act(User.find(user_id), Post.find(post_id), PostActionType.types[:bookmark])
PostActionCreator.create(User.find(user_id), Post.find(post_id), :bookmark)
end
break if favorites["list"].size < POST_COUNT || favorites.dig("links", "next").blank?

View File

@ -410,11 +410,7 @@ class ImportScripts::NodeBB < ImportScripts::Base
post["upvoted_by"].each do |upvoter_id|
user = User.new
user.id = user_id_from_imported_user_id(upvoter_id) || Discourse::SYSTEM_USER_ID
begin
PostAction.act(user, p, PostActionType.types[:like])
rescue PostAction::AlreadyActed
end
PostActionCreator.like(user, p)
end
end
}

View File

@ -310,7 +310,7 @@ EOM
post = Post.find_by(id: post_id_from_imported_post_id("thread-#{like['postid']}"))
user = User.find_by(id: user_id_from_imported_user_id(like["userid"]))
begin
PostAction.act(user, post, 2) if user && post
PostActionCreator.like(user, post) if user && post
rescue => e
puts "error acting on post #{e}"
end

View File

@ -165,8 +165,6 @@ class ImportScripts::StackOverflow < ImportScripts::Base
end
end
LIKE ||= PostActionType.types[:like]
def import_likes
puts "", "Importing post likes..."
@ -196,7 +194,7 @@ class ImportScripts::StackOverflow < ImportScripts::Base
next unless post_id = post_id_from_imported_post_id(l["PostId"])
next unless user = User.find_by(id: user_id)
next unless post = Post.find_by(id: post_id)
PostAction.act(user, post, LIKE) rescue nil
PostActionCreator.like(user, post) rescue nil
end
end
@ -229,7 +227,7 @@ class ImportScripts::StackOverflow < ImportScripts::Base
next unless post_id = post_id_from_imported_post_id(l["PostCommentId"])
next unless user = User.find_by(id: user_id)
next unless post = Post.find_by(id: post_id)
PostAction.act(user, post, LIKE) rescue nil
PostActionCreator.like(user, post) rescue nil
end
end
end