FIX: sending messages to groups with non-lowercase names
Fixes a regression in
e8fb9d4066
which caused a bug where you couldn't send a message to a group that
contained an Uppercase letter. Added a test case for this.
Bug report: https://meta.discourse.org/t/-/152999
This commit is contained in:
parent
75f46ca632
commit
6548cd1a96
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue