mirror of
https://github.com/discourse/discourse.git
synced 2024-12-21 11:35:59 +08:00
23a74ecf8f
This commits adds a database migration to limit the user status to 100
characters, limits the user status in the UI and makes sure that the
emoji is valid.
Follow up to commit b6f75e231c
.
38 lines
955 B
Ruby
38 lines
955 B
Ruby
# frozen_string_literal: true
|
|
|
|
class UserStatus < ActiveRecord::Base
|
|
MAX_DESCRIPTION_LENGTH = 100
|
|
|
|
belongs_to :user
|
|
|
|
validate :emoji_exists
|
|
validates :description, length: { maximum: MAX_DESCRIPTION_LENGTH }
|
|
validate :ends_at_greater_than_set_at,
|
|
if: Proc.new { |t| t.will_save_change_to_set_at? || t.will_save_change_to_ends_at? }
|
|
|
|
def expired?
|
|
ends_at && ends_at < Time.zone.now
|
|
end
|
|
|
|
def emoji_exists
|
|
errors.add(:emoji, :invalid) if emoji && !Emoji.exists?(emoji)
|
|
end
|
|
|
|
def ends_at_greater_than_set_at
|
|
if ends_at && set_at > ends_at
|
|
errors.add(:ends_at, I18n.t("user_status.errors.ends_at_should_be_greater_than_set_at"))
|
|
end
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: user_statuses
|
|
#
|
|
# user_id :integer not null, primary key
|
|
# emoji :string not null
|
|
# description :string not null
|
|
# set_at :datetime not null
|
|
# ends_at :datetime
|
|
#
|