mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 15:13:43 +08:00
63bab32816
* FEATURE: introduces minimum trust level for polls This commit makes `poll_enabled` less misleading and introduces `poll_minimum_trust_level_to_create`. If poll are enabled they will always be cooked, and if you have the required trust level you can create polls. As a side effect, it also fixes a bug where rebaking a post created by staff member when `poll_enabled=false` would end up not cooking it. It also adds more tests to ensure settings are respected. * admins should be whitelisted * checks for admin in post validation * test for >= instead of == trust level
26 lines
580 B
Ruby
26 lines
580 B
Ruby
module DiscoursePoll
|
|
class PostValidator
|
|
def initialize(post)
|
|
@post = post
|
|
end
|
|
|
|
def validate_post
|
|
min_trust_level = SiteSetting.poll_minimum_trust_level_to_create
|
|
trusted = @post&.user&.admin ||
|
|
@post&.user&.trust_level >= TrustLevel[min_trust_level]
|
|
|
|
if !trusted
|
|
message = I18n.t("poll.insufficient_trust_level_to_create",
|
|
current: @post&.user&.trust_level,
|
|
required: min_trust_level
|
|
)
|
|
|
|
@post.errors.add(:base, message)
|
|
return false
|
|
end
|
|
|
|
true
|
|
end
|
|
end
|
|
end
|