mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 19:14:01 +08:00
Merge pull request #3046 from gdpelican/feature/insensitive-group-names
Remove group name validation case sensitivity
This commit is contained in:
commit
768027f0e3
|
@ -10,7 +10,7 @@ class Group < ActiveRecord::Base
|
||||||
after_save :destroy_deletions
|
after_save :destroy_deletions
|
||||||
|
|
||||||
validate :name_format_validator
|
validate :name_format_validator
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name, case_sensitive: false
|
||||||
|
|
||||||
AUTO_GROUPS = {
|
AUTO_GROUPS = {
|
||||||
:everyone => 0,
|
:everyone => 0,
|
||||||
|
|
|
@ -54,7 +54,7 @@ en:
|
||||||
messages:
|
messages:
|
||||||
too_long_validation: "is limited to %{max} characters; you entered %{length}."
|
too_long_validation: "is limited to %{max} characters; you entered %{length}."
|
||||||
invalid_boolean: "Invalid boolean."
|
invalid_boolean: "Invalid boolean."
|
||||||
taken: "has already been taken"
|
taken: "has already been taken. (group names are case insensitive)"
|
||||||
embed:
|
embed:
|
||||||
load_from_remote: "There was an error loading that post."
|
load_from_remote: "There was an error loading that post."
|
||||||
|
|
||||||
|
|
23
db/migrate/20141216112341_resolve_duplicate_group_names.rb
Normal file
23
db/migrate/20141216112341_resolve_duplicate_group_names.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
class ResolveDuplicateGroupNames < ActiveRecord::Migration
|
||||||
|
|
||||||
|
def up
|
||||||
|
results = Group.exec_sql 'SELECT id FROM groups
|
||||||
|
WHERE name ILIKE
|
||||||
|
(SELECT lower(name)
|
||||||
|
FROM groups
|
||||||
|
GROUP BY lower(name)
|
||||||
|
HAVING count(*) > 1);'
|
||||||
|
|
||||||
|
groups = Group.where id: results.map { |r| r['id'] }
|
||||||
|
groups.group_by { |g| g.name.downcase }.each do |key, value|
|
||||||
|
value.each_with_index do |dup, index|
|
||||||
|
dup.update! name: "#{dup.name[0..18]}_#{index+1}" if index > 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
# does not reverse changes
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -27,6 +27,12 @@ describe Group do
|
||||||
group.name = "this is_a_name"
|
group.name = "this is_a_name"
|
||||||
group.valid?.should == false
|
group.valid?.should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "is invalid for case-insensitive existing names" do
|
||||||
|
build(:group, name: 'this_is_a_name').save
|
||||||
|
group.name = 'This_Is_A_Name'
|
||||||
|
group.valid?.should == false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def real_admins
|
def real_admins
|
||||||
|
|
Loading…
Reference in New Issue
Block a user