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