mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 18:03:42 +08:00
720e896e17
It also exposed a bug in the EmailReceiver spec, where a test had a user liking their own post and was not failing.
24 lines
455 B
Ruby
24 lines
455 B
Ruby
# 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, PostActionType.types[action], opts: {
|
|
taken_actions: PostAction.counts_for([@post].compact, @user)[@post&.id]
|
|
})
|
|
|
|
PostAction.act(@user, @post, action)
|
|
end
|
|
|
|
private
|
|
|
|
def guardian
|
|
@guardian ||= Guardian.new(@user)
|
|
end
|
|
|
|
end
|