REFACTOR: separate post_can_act logic in post action creator (#9103)

Package logic of the post can act a little bit better so that overriding
methods can easily reuse the logic.
This commit is contained in:
Jeff Wong 2020-03-03 14:56:37 -10:00 committed by GitHub
parent 3e54e0191e
commit 97545ee4a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,10 +48,8 @@ class PostActionCreator
@meta_post = nil
end
def perform
result = CreateResult.new
unless guardian.post_can_act?(
def post_can_act?
guardian.post_can_act?(
@post,
@post_action_name,
opts: {
@ -59,6 +57,12 @@ class PostActionCreator
taken_actions: PostAction.counts_for([@post].compact, @created_by)[@post&.id]
}
)
end
def perform
result = CreateResult.new
unless post_can_act?
result.forbidden = true
result.add_error(I18n.t("invalid_access"))
return result