mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
Merge pull request #3046 from gdpelican/feature/insensitive-group-names
Remove group name validation case sensitivity
This commit is contained in:
commit
768027f0e3
4 changed files with 31 additions and 2 deletions
|
@ -10,7 +10,7 @@ class Group < ActiveRecord::Base
|
|||
after_save :destroy_deletions
|
||||
|
||||
validate :name_format_validator
|
||||
validates_uniqueness_of :name
|
||||
validates_uniqueness_of :name, case_sensitive: false
|
||||
|
||||
AUTO_GROUPS = {
|
||||
:everyone => 0,
|
||||
|
|
|
@ -54,7 +54,7 @@ en:
|
|||
messages:
|
||||
too_long_validation: "is limited to %{max} characters; you entered %{length}."
|
||||
invalid_boolean: "Invalid boolean."
|
||||
taken: "has already been taken"
|
||||
taken: "has already been taken. (group names are case insensitive)"
|
||||
embed:
|
||||
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.valid?.should == false
|
||||
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
|
||||
|
||||
def real_admins
|
||||
|
|
Loading…
Reference in a new issue