2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-04-05 01:06:06 -04:00
|
|
|
module UserWarnable
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2024-04-21 12:14:01 -04:00
|
|
|
enum :warning_type, {
|
2022-09-26 14:15:35 -04:00
|
|
|
warning: 1,
|
|
|
|
record: 2,
|
|
|
|
ban: 3,
|
|
|
|
}
|
|
|
|
|
|
|
|
scope :user_warned, -> { where("warning_type IS NOT NULL") }
|
2021-04-05 01:06:06 -04:00
|
|
|
end
|
|
|
|
|
2022-09-26 14:15:35 -04:00
|
|
|
def user_warned!(type, user)
|
2023-12-04 14:19:49 -05:00
|
|
|
update(warning_type: type, warning_user_id: user.id)
|
2021-04-05 01:06:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove_user_warning!
|
2023-12-04 14:19:49 -05:00
|
|
|
update(warning_type: nil, warning_user_id: nil)
|
2021-04-05 01:06:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def was_warned?
|
|
|
|
!warning_type.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def warning_type_string
|
|
|
|
case warning_type
|
2022-09-26 14:15:35 -04:00
|
|
|
when "warning"
|
2023-12-04 14:19:49 -05:00
|
|
|
"User received a warning for the contents of this message"
|
2022-09-26 14:15:35 -04:00
|
|
|
when "record"
|
2023-12-04 14:19:49 -05:00
|
|
|
"User received a record for the contents of this message"
|
2022-09-26 14:15:35 -04:00
|
|
|
when "ban"
|
2023-12-04 14:19:49 -05:00
|
|
|
"User was banned for the contents of this message"
|
2021-04-05 01:06:06 -04:00
|
|
|
else
|
|
|
|
"[This is a bug with the website. Woo!]"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|