discourse/lib/post_action_creator.rb

21 lines
417 B
Ruby
Raw Normal View History

2015-12-30 14:04:05 -05:00
# creates post actions based on a post and a user
class PostActionCreator
def initialize(user, post)
@user = user
@post = post
end
def perform(action)
2015-12-30 14:52:36 -05:00
guardian.ensure_post_can_act!(@post, action, taken_actions: PostAction.counts_for([@post].compact, @user)[@post.try(:id)])
2015-12-30 14:04:05 -05:00
PostAction.act(@user, @post, action)
end
private
def guardian
@guardian ||= Guardian.new(@user)
end
end