Skip to content

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.rb
index 4830b3b9795..4ee3b294af8 100644
--- a/app/controllers/posts_controller.rb
+++ b/app/controllers/posts_controller.rb
@@ -748,7 +748,7 @@ class PostsController < ApplicationController
if recipients
recipients = 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 -= groups
emails = recipients.select { |user| user.match(/@/) }
recipients -= emails
diff --git a/lib/topic_creator.rb b/lib/topic_creator.rb
index d86f1c461ae..c52396b8f64 100644
--- a/lib/topic_creator.rb
+++ b/lib/topic_creator.rb
@@ -246,10 +246,10 @@ class TopicCreator
def 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 += 1
diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rb
index 910cb5b95df..e9ed6c4d17a 100644
--- a/spec/requests/posts_controller_spec.rb
+++ b/spec/requests/posts_controller_spec.rb
@@ -838,6 +838,30 @@ describe PostsController do
expect(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" do
post "/posts.json", params: {
raw: 'this is the test content',