users: don't allow users to choose reserved names.

Don't allow users to choose names that conflict with search syntax, like `any` or `none`, or names
that impersonate user levels, like `Admin`, `Moderator`, `Anonymous`, etc.
This commit is contained in:
evazion
2022-11-06 15:46:38 -06:00
parent 8bd60e41a1
commit c133866cb7
6 changed files with 25 additions and 9 deletions

View File

@@ -102,7 +102,7 @@ class PostVoteTest < ActiveSupport::TestCase
context "deleting a vote by another user" do
should "leave a mod action" do
admin = create(:admin_user, name: "admin")
admin = create(:admin_user)
vote = create(:post_vote, post: @post, score: 1)
vote.soft_delete!(updater: admin)
@@ -114,7 +114,7 @@ class PostVoteTest < ActiveSupport::TestCase
context "undeleting a vote by another user" do
setup do
@admin = create(:admin_user, name: "admin")
@admin = create(:admin_user)
@vote = create(:post_vote, post: @post, score: 1)
@vote.soft_delete!(updater: @admin)

View File

@@ -205,6 +205,13 @@ class UserTest < ActiveSupport::TestCase
user.save
assert_equal(["Name is not allowed"], user.errors.full_messages)
end
should_not allow_value("any").for(:name)
should_not allow_value("none").for(:name)
should_not allow_value("new").for(:name)
should_not allow_value("admin").for(:name)
should_not allow_value("mod").for(:name)
should_not allow_value("moderator").for(:name)
end
context "searching for users by name" do