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
|
|
|
|
|
2022-05-05 02:54:10 -04:00
|
|
|
if (
|
|
|
|
@post.acting_user &&
|
|
|
|
(
|
|
|
|
@post.acting_user.staff? ||
|
|
|
|
@post.acting_user.trust_level >= TrustLevel[min_trust_level]
|
2023-01-06 15:42:16 -05:00
|
|
|
)
|
2022-05-05 02:54:10 -04:00
|
|
|
) || @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
|