discourse/app/models/concerns/limited_edit.rb
Blake Erickson 241d8f6452 FIX: Edit title respects min trust to edit post
This fix ensures that the site setting `post_edit_time_limit` does not
bypass the limit of the site setting `min_trust_to_edit_post`. This
prevents a bug where users that did not meet the minimum trust level to
edit could edit the title of topics.
2020-02-04 16:31:16 -07:00

27 lines
534 B
Ruby

# frozen_string_literal: true
module LimitedEdit
extend ActiveSupport::Concern
def edit_time_limit_expired?(user)
time_limit = user_time_limit(user)
if user.trust_level < SiteSetting.min_trust_to_edit_post
true
elsif created_at && time_limit > 0
created_at < time_limit.minutes.ago
else
false
end
end
private
def user_time_limit(user)
if user.trust_level < 2
SiteSetting.post_edit_time_limit.to_i
else
SiteSetting.tl2_post_edit_time_limit.to_i
end
end
end