Commit e27af6ee authored by Steffen van Bergerem's avatar Steffen van Bergerem Committed by Dennis Schubert

Redirect logged in users to inviters page when following an invitation link

closes #7061
parent c5ebea5b
......@@ -17,6 +17,7 @@
* Deleted comments will be removed when loading more comments [#7045](https://github.com/diaspora/diaspora/pull/7045)
* The "subscribe" indicator on a post now gets toggled when you like or rehsare a post [#7040](https://github.com/diaspora/diaspora/pull/7040)
* Add OpenGraph video support [#7043](https://github.com/diaspora/diaspora/pull/7043)
* You'll now get redirected to the invites page if you follow an invitation but you're already logged in [#7061](https://github.com/diaspora/diaspora/pull/7061)
# 0.6.0.0
......
......@@ -5,9 +5,14 @@ class InvitationCodesController < ApplicationController
redirect_to root_url, :notice => I18n.t('invitation_codes.not_valid')
end
def show
sign_out(current_user) if user_signed_in?
redirect_to new_user_registration_path(:invite => {:token => params[:id]})
def show
if user_signed_in?
invite = InvitationCode.find_by_token!(params[:id])
flash[:notice] = I18n.t("invitation_codes.already_logged_in", inviter: invite.user.name)
redirect_to person_path(invite.user.person)
else
redirect_to new_user_registration_path(invite: {token: params[:id]})
end
end
private
......
......@@ -553,6 +553,7 @@ en:
invitation_codes:
not_valid: "That invite code is no longer valid"
already_logged_in: "You have been invited by %{inviter} to join this pod but you are already logged in."
invitations:
create:
......
require "spec_helper"
describe InvitationCodesController, type: :controller do
describe "#show" do
it "redirects to the root page if the invitation code is invalid" do
get :show, id: "InvalidInvitationCode"
expect(response).to redirect_to root_path
expect(flash[:notice]).to eq(I18n.t("invitation_codes.not_valid"))
end
context "valid invitation code" do
let(:invitation_token) { alice.invitation_code.token }
it "redirects logged out users to the sign in page" do
post :show, id: invitation_token
expect(response).to redirect_to new_user_registration_path(invite: {token: invitation_token})
end
it "redirects logged in users the the inviters page" do
sign_in bob
post :show, id: invitation_token
expect(response).to redirect_to person_path(alice.person)
expect(flash[:notice]).to eq(I18n.t("invitation_codes.already_logged_in", inviter: alice.name))
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment