Add post action creator

This commit is contained in:
James Kiesel
2015-12-30 20:04:05 +01:00
parent 86da47880a
commit a559754db3
2 changed files with 22 additions and 1 deletions

View 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