2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-04 08:47:11 -05:00
|
|
|
module DiscoursePoll
|
|
|
|
class PostValidator
|
|
|
|
def initialize(post)
|
|
|
|
@post = post
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_post
|
|
|
|
min_trust_level = SiteSetting.poll_minimum_trust_level_to_create
|
|
|
|
|
2020-03-02 14:29:40 -05:00
|
|
|
if @post&.user&.staff? || @post&.user&.trust_level >= TrustLevel[min_trust_level] || @post&.topic&.pm_with_non_human_user?
|
2018-05-02 20:12:19 -04:00
|
|
|
true
|
|
|
|
else
|
|
|
|
@post.errors.add(:base, I18n.t("poll.insufficient_rights_to_create"))
|
|
|
|
false
|
2017-12-04 08:47:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|