2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-02-26 03:53:21 +08:00
|
|
|
module LimitedEdit
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2019-09-06 19:44:12 +08:00
|
|
|
def edit_time_limit_expired?(user)
|
2023-12-13 13:25:13 +08:00
|
|
|
return true if !trusted_with_edits?(user)
|
2019-09-06 19:44:12 +08:00
|
|
|
time_limit = user_time_limit(user)
|
2020-02-06 01:23:29 +08:00
|
|
|
created_at && (time_limit > 0) && (created_at < time_limit.minutes.ago)
|
2015-02-26 03:53:21 +08:00
|
|
|
end
|
2019-09-06 19:44:12 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2023-12-13 13:25:13 +08:00
|
|
|
# TODO: This duplicates some functionality from PostGuardian. This should
|
|
|
|
# probably be checked there instead, because this has nothing to do
|
|
|
|
# with time limits.
|
|
|
|
#
|
|
|
|
def trusted_with_edits?(user)
|
|
|
|
user.trust_level >= SiteSetting.min_trust_to_edit_post ||
|
|
|
|
user.in_any_groups?(SiteSetting.edit_post_allowed_groups_map)
|
|
|
|
end
|
|
|
|
|
2019-09-06 19:44:12 +08:00
|
|
|
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
|
2015-02-26 03:53:21 +08:00
|
|
|
end
|