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