mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:16:38 -06:00
Add post action creator
This commit is contained in:
parent
86da47880a
commit
a559754db3
@ -1,5 +1,6 @@
|
||||
require_dependency 'new_post_manager'
|
||||
require_dependency 'email/html_cleaner'
|
||||
require_dependency 'post_action_creator'
|
||||
|
||||
module Email
|
||||
|
||||
@ -245,7 +246,7 @@ module Email
|
||||
end
|
||||
|
||||
def create_post_action(email_log, type)
|
||||
PostAction.act(email_log.user, email_log.post, type)
|
||||
PostActionCreator.new(email_log.user, email_log.post).perform(type)
|
||||
rescue PostAction::AlreadyActed => e
|
||||
raise InvalidPostAction.new(e)
|
||||
end
|
||||
|
20
lib/post_action_creator.rb
Normal file
20
lib/post_action_creator.rb
Normal file
@ -0,0 +1,20 @@
|
||||
# creates post actions based on a post and a user
|
||||
class PostActionCreator
|
||||
|
||||
def initialize(user, post)
|
||||
@user = user
|
||||
@post = post
|
||||
end
|
||||
|
||||
def perform(action)
|
||||
guardian.ensure_post_can_act!(@post, action, taken_actions: PostAction.counts_for([@post], @user)[@post.id])
|
||||
PostAction.act(@user, @post, action)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def guardian
|
||||
@guardian ||= Guardian.new(@user)
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user