FIX: Send request membership PM to last 5 active group owner.

This commit is contained in:
Guo Xiang Tan 2017-06-15 11:36:09 +08:00
parent b98a930364
commit b5249fb4ca
2 changed files with 14 additions and 5 deletions

View File

@ -238,14 +238,19 @@ class GroupsController < ApplicationController
group = find_group(:id)
group_name = group.name
username = current_user.username
usernames = [current_user.username].concat(
group.users.where('group_users.owner')
.order("users.last_seen_at DESC")
.limit(5)
.pluck("users.username")
)
post = PostCreator.new(current_user,
title: I18n.t('groups.request_membership_pm.title', group_name: group_name),
raw: I18n.t('groups.request_membership_pm.body', group_name: group_name),
archetype: Archetype.private_message,
target_usernames: username,
target_group_names: group_name,
target_usernames: usernames.join(','),
skip_validations: true
).create!

View File

@ -546,6 +546,10 @@ describe "Groups" do
end
it 'should create the right PM' do
owner1 = Fabricate(:user, last_seen_at: Time.zone.now)
owner2 = Fabricate(:user, last_seen_at: Time.zone.now - 1 .day)
[owner1, owner2].each { |owner| group.add_owner(owner) }
sign_in(user)
xhr :post, "/groups/#{group.name}/request_membership"
@ -568,8 +572,8 @@ describe "Groups" do
))
expect(topic.archetype).to eq(Archetype.private_message)
expect(topic.allowed_users).to eq([user])
expect(topic.allowed_groups).to eq([group])
expect(topic.allowed_users).to contain_exactly(user, owner1, owner2)
expect(topic.allowed_groups).to eq([])
end
end
end