A platform for community discussion. Free, open, simple.
FIX: sending messages to groups with non-lowercase names
Blake Erickson6548cd1a9697
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rbindex 4830b3b9795..4ee3b294af8 100644--- a/app/controllers/posts_controller.rb+++ b/app/controllers/posts_controller.rb@@ -748,7 +748,7 @@ class PostsController < ApplicationControllerif recipientsrecipients = recipients.split(",").map(&:downcase)- groups = Group.messageable(current_user).where('lower(name) in (?)', recipients).pluck('name')+ groups = Group.messageable(current_user).where('lower(name) in (?)', recipients).pluck('lower(name)')recipients -= groupsemails = recipients.select { |user| user.match(/@/) }recipients -= emailsdiff --git a/lib/topic_creator.rb b/lib/topic_creator.rbindex d86f1c461ae..c52396b8f64 100644--- a/lib/topic_creator.rb+++ b/lib/topic_creator.rb@@ -246,10 +246,10 @@ class TopicCreatordef add_groups(topic, groups)return unless groups- names = groups.split(',').flatten+ names = groups.split(',').flatten.map(&:downcase)len = 0- Group.where(name: names).each do |group|+ Group.where('lower(name) in (?)', names).each do |group|check_can_send_permission!(topic, group)topic.topic_allowed_groups.build(group_id: group.id)len += 1diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rbindex 910cb5b95df..e9ed6c4d17a 100644--- a/spec/requests/posts_controller_spec.rb+++ b/spec/requests/posts_controller_spec.rb@@ -838,6 +838,30 @@ describe PostsController doexpect(post.topic.topic_allowed_groups.length).to eq(1)end+ it "can send a message to a group with caps" do+ group = Group.create(name: 'Test_group', messageable_level: Group::ALIAS_LEVELS[:nobody])+ user1 = user+ group.add(user1)++ # allow pm to this group+ group.update_columns(messageable_level: Group::ALIAS_LEVELS[:everyone])++ post "/posts.json", params: {+ raw: 'I can haz a test',+ title: 'I loves my test',+ target_recipients: "test_Group",+ archetype: Archetype.private_message+ }++ expect(response.status).to eq(200)++ parsed = response.parsed_body+ post = Post.find(parsed['id'])++ expect(post.topic.topic_allowed_users.length).to eq(1)+ expect(post.topic.topic_allowed_groups.length).to eq(1)+ end+it "returns the nested post with a param" dopost "/posts.json", params: {raw: 'this is the test content',