From 07b80d491b7973b69648dd358205d9d55766f5a6 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Fri, 10 May 2019 15:49:12 +0300 Subject: [PATCH] FIX: Refresh automatic groups after inviting moderators. --- app/controllers/invites_controller.rb | 2 ++ spec/requests/invites_controller_spec.rb | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb index c17c4329a27..17ded05e660 100644 --- a/app/controllers/invites_controller.rb +++ b/app/controllers/invites_controller.rb @@ -223,6 +223,8 @@ class InvitesController < ApplicationController def post_process_invite(user) user.enqueue_welcome_message('welcome_invite') if user.send_welcome_message + Group.refresh_automatic_groups!(:admins, :moderators, :staff) if user.staff? + if user.has_password? send_activation_email(user) unless user.active elsif !SiteSetting.enable_sso && SiteSetting.enable_local_logins diff --git a/spec/requests/invites_controller_spec.rb b/spec/requests/invites_controller_spec.rb index 6a7ea16d118..dcbd5c01302 100644 --- a/spec/requests/invites_controller_spec.rb +++ b/spec/requests/invites_controller_spec.rb @@ -312,11 +312,20 @@ describe InvitesController do expect(Jobs::SendSystemMessage.jobs.size).to eq(1) end + it 'refreshes automatic groups if staff' do + topic.user.grant_admin! + invite.update!(moderator: true) + + put "/invites/show/#{invite.invite_key}.json" + expect(response.status).to eq(200) + + expect(invite.reload.user.groups.pluck(:name)).to contain_exactly("moderators", "staff") + end + context "without password" do it "sends password reset email" do put "/invites/show/#{invite.invite_key}.json" expect(response.status).to eq(200) - expect(JSON.parse(response.body)["success"]).to eq(true) expect(Jobs::InvitePasswordInstructionsEmail.jobs.size).to eq(1) expect(Jobs::CriticalUserEmail.jobs.size).to eq(0) @@ -327,7 +336,6 @@ describe InvitesController do SiteSetting.enable_sso = true put "/invites/show/#{invite.invite_key}.json" expect(response.status).to eq(200) - expect(JSON.parse(response.body)["success"]).to eq(true) expect(Jobs::InvitePasswordInstructionsEmail.jobs.size).to eq(0) expect(Jobs::CriticalUserEmail.jobs.size).to eq(0) @@ -337,7 +345,6 @@ describe InvitesController do SiteSetting.enable_local_logins = false put "/invites/show/#{invite.invite_key}.json" expect(response.status).to eq(200) - expect(JSON.parse(response.body)["success"]).to eq(true) expect(Jobs::InvitePasswordInstructionsEmail.jobs.size).to eq(0) expect(Jobs::CriticalUserEmail.jobs.size).to eq(0)