mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 10:57:04 +08:00
FIX: Truncate existing user status to 100 chars (#20044)
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
.
This commit is contained in:
parent
9f14d643a5
commit
23a74ecf8f
|
@ -19,6 +19,7 @@
|
|||
<Input
|
||||
class="user-status-description"
|
||||
@value={{@status.description}}
|
||||
maxlength="100"
|
||||
placeholder={{i18n "user_status.what_are_you_doing"}}
|
||||
{{on "input" this.setDefaultEmoji}}
|
||||
{{on "focus" this.focus}}
|
||||
|
|
|
@ -15,7 +15,7 @@ class UserStatus < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def emoji_exists
|
||||
emoji && Emoji.exists?(emoji)
|
||||
errors.add(:emoji, :invalid) if emoji && !Emoji.exists?(emoji)
|
||||
end
|
||||
|
||||
def ends_at_greater_than_set_at
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TruncateUserStatusTo100Characters < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
execute "UPDATE user_statuses SET description = left(description, 100)"
|
||||
execute "UPDATE user_statuses SET emoji = left(emoji, 100)"
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
|
@ -76,8 +76,12 @@ RSpec.describe UserStatusController do
|
|||
end
|
||||
|
||||
it "validates emoji" do
|
||||
put "/user-status.json", params: { description: "invalid_emoji_name" }
|
||||
expect(response.status).to eq(400)
|
||||
put "/user-status.json",
|
||||
params: {
|
||||
emoji: "invalid_emoji_name",
|
||||
description: "off to dentist",
|
||||
}
|
||||
expect(response.status).to eq(422)
|
||||
end
|
||||
|
||||
it "limits description’s length" do
|
||||
|
|
|
@ -2871,7 +2871,7 @@ RSpec.describe UsersController do
|
|||
end
|
||||
|
||||
it "doesn't clear user status if it wasn't sent in the payload" do
|
||||
new_status = { emoji: "off to dentist", description: "tooth" }
|
||||
new_status = { emoji: "tooth", description: "off to dentist" }
|
||||
user.set_status!(new_status[:description], new_status[:emoji])
|
||||
user.reload
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user