Arpit Jalan 2020-05-25 21:34:05 +05:30
parent 302b37c805
commit e8fb9d4066
3 changed files with 7 additions and 7 deletions

View File

@ -747,8 +747,8 @@ class PostsController < ApplicationController
end end
if recipients if recipients
recipients = recipients.split(",") recipients = recipients.split(",").map(&:downcase)
groups = Group.messageable(current_user).where('name in (?)', recipients).pluck('name') groups = Group.messageable(current_user).where('lower(name) in (?)', recipients).pluck('name')
recipients -= groups recipients -= groups
emails = recipients.select { |user| user.match(/@/) } emails = recipients.select { |user| user.match(/@/) }
recipients -= emails recipients -= emails

View File

@ -208,10 +208,10 @@ class TopicCreator
def add_users(topic, usernames) def add_users(topic, usernames)
return unless usernames return unless usernames
names = usernames.split(',').flatten names = usernames.split(',').flatten.map(&:downcase)
len = 0 len = 0
User.includes(:user_option).where(username: names).find_each do |user| User.includes(:user_option).where('lower(username) in (?)', names).find_each do |user|
check_can_send_permission!(topic, user) check_can_send_permission!(topic, user)
@added_users << user @added_users << user
topic.topic_allowed_users.build(user_id: user.id) topic.topic_allowed_users.build(user_id: user.id)

View File

@ -825,7 +825,7 @@ describe PostsController do
post "/posts.json", params: { post "/posts.json", params: {
raw: 'I can haz a test', raw: 'I can haz a test',
title: 'I loves my test', title: 'I loves my test',
target_recipients: group.name, target_recipients: "test_Group",
archetype: Archetype.private_message archetype: Archetype.private_message
} }
@ -965,13 +965,13 @@ describe PostsController do
it 'creates a private post' do it 'creates a private post' do
user_2 = Fabricate(:user) user_2 = Fabricate(:user)
user_3 = Fabricate(:user) user_3 = Fabricate(:user, username: "foo_bar")
post "/posts.json", params: { post "/posts.json", params: {
raw: 'this is the test content', raw: 'this is the test content',
archetype: 'private_message', archetype: 'private_message',
title: "this is some post", title: "this is some post",
target_recipients: "#{user_2.username},#{user_3.username}" target_recipients: "#{user_2.username},Foo_Bar"
} }
expect(response.status).to eq(200) expect(response.status).to eq(200)