FIX: Refresh automatic groups after inviting moderators.

FIX: Refresh automatic groups after inviting moderators.

diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb
index c17c432..17ded05 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 6a7ea16..dcbd5c0 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)

GitHub sha: 07b80d49

1 Like