From b5249fb4caf8eb4b96e9a383eeabca570c771606 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 15 Jun 2017 11:36:09 +0800 Subject: [PATCH] FIX: Send request membership PM to last 5 active group owner. --- app/controllers/groups_controller.rb | 11 ++++++++--- spec/integration/groups_spec.rb | 8 ++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 33b86d9e5b2..292bfd104d0 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -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! diff --git a/spec/integration/groups_spec.rb b/spec/integration/groups_spec.rb index f5ab5fc75ba..055129425e0 100644 --- a/spec/integration/groups_spec.rb +++ b/spec/integration/groups_spec.rb @@ -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