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
|
<Input
|
||||||
class="user-status-description"
|
class="user-status-description"
|
||||||
@value={{@status.description}}
|
@value={{@status.description}}
|
||||||
|
maxlength="100"
|
||||||
placeholder={{i18n "user_status.what_are_you_doing"}}
|
placeholder={{i18n "user_status.what_are_you_doing"}}
|
||||||
{{on "input" this.setDefaultEmoji}}
|
{{on "input" this.setDefaultEmoji}}
|
||||||
{{on "focus" this.focus}}
|
{{on "focus" this.focus}}
|
||||||
|
|
|
@ -15,7 +15,7 @@ class UserStatus < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def emoji_exists
|
def emoji_exists
|
||||||
emoji && Emoji.exists?(emoji)
|
errors.add(:emoji, :invalid) if emoji && !Emoji.exists?(emoji)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ends_at_greater_than_set_at
|
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
|
end
|
||||||
|
|
||||||
it "validates emoji" do
|
it "validates emoji" do
|
||||||
put "/user-status.json", params: { description: "invalid_emoji_name" }
|
put "/user-status.json",
|
||||||
expect(response.status).to eq(400)
|
params: {
|
||||||
|
emoji: "invalid_emoji_name",
|
||||||
|
description: "off to dentist",
|
||||||
|
}
|
||||||
|
expect(response.status).to eq(422)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "limits description’s length" do
|
it "limits description’s length" do
|
||||||
|
|
|
@ -2871,7 +2871,7 @@ RSpec.describe UsersController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't clear user status if it wasn't sent in the payload" do
|
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.set_status!(new_status[:description], new_status[:emoji])
|
||||||
user.reload
|
user.reload
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue