A platform for community discussion. Free, open, simple.
FIX: automatically redirect logged in users to topic when... (#31301)
Régis Hanol2e10fe98a3cb
diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rbindex 16ac6669a46..148ed9e3ec2 100644--- a/app/controllers/invites_controller.rb+++ b/app/controllers/invites_controller.rb@@ -28,6 +28,13 @@ class InvitesController < ApplicationControllerinvite = Invite.find_by(invite_key: params[:id])+ # automatically redirect to the topic if the user is logged in and can see it+ if current_user+ if topic = invite.topics.first+ return redirect_to(topic.url) if current_user.guardian.can_see?(topic)+ end+ end+if invite.present? && invite.redeemable?show_invite(invite)elsediff --git a/spec/requests/invites_controller_spec.rb b/spec/requests/invites_controller_spec.rbindex 05e3ba10095..bffbf4b1c15 100644--- a/spec/requests/invites_controller_spec.rb+++ b/spec/requests/invites_controller_spec.rb@@ -102,6 +102,24 @@ RSpec.describe InvitesController dobefore { sign_in(user) }+ it "automatically redirects to the topic if the user can access it" do+ invite.update!(topics: [Fabricate(:topic)])++ get "/invites/#{invite.invite_key}"+ expect(response.status).to eq(302)+ expect(response.location).to eq(invite.topics.first.url)+ end++ it "doesn't automatically redirect to the topic if the user can't access it" do+ secret_group = Fabricate(:group)+ invite.update!(+ topics: [Fabricate(:topic, category: Fabricate(:private_category, group: secret_group))],+ )++ get "/invites/#{invite.invite_key}"+ expect(response.status).to eq(200)+ end+it "shows the accept invite page when user's email matches the invite email" doinvite.update_columns(email: user.email)@@ -592,14 +610,16 @@ RSpec.describe InvitesController doexpect(json["successful_invitations"].length).to eq(2)end- it "creates many invite codes with one request" do #change to+ it "creates many invite codes with one request" dosign_in(admin)- num_emails = 5 # increase manually for load testing++ num_emails = 5+post "/invites/create-multiple.json",params: {email: 1.upto(num_emails).map { |i| "test#{i}@example.com" },- #email: %w[[email protected] [email protected]]}+expect(response.status).to eq(200)json = JSON(response.body)expect(json["failed_invitations"].length).to eq(0)