From 23541546e9630fcab58ce63391492bfac18afb98 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Mon, 15 Aug 2016 01:27:53 +0200 Subject: [PATCH] Allow hovercards of remote people when not logged in In #6603 hovercards were activated for logged out users, but they only worked for local people. Hovercards on remote-people are important to get the diaspora-id to search the person on the local pod, if you don't know who it is. --- app/controllers/people_controller.rb | 8 ++++---- spec/controllers/people_controller_spec.rb | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 5029ccc62..6277e1adf 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -7,6 +7,7 @@ class PeopleController < ApplicationController before_action :authenticate_user!, except: %i(show stream hovercard) before_action :find_person, only: %i(show stream hovercard) + before_action :authenticate_if_remote_profile!, only: %i(show stream) respond_to :html respond_to :json, :only => [:index, :show] @@ -163,8 +164,6 @@ class PeopleController < ApplicationController }) end - # view this profile on the home pod, if you don't want to sign in... - authenticate_user! if remote_profile_with_no_user_session? raise ActiveRecord::RecordNotFound if @person.nil? raise Diaspora::AccountClosed if @person.closed_account? end @@ -189,8 +188,9 @@ class PeopleController < ApplicationController !query.try(:match, /^(\w)*@([a-zA-Z0-9]|[-]|[.]|[:])*$/).nil? end - def remote_profile_with_no_user_session? - @person.try(:remote?) && !user_signed_in? + # view this profile on the home pod, if you don't want to sign in... + def authenticate_if_remote_profile! + authenticate_user! if @person.try(:remote?) end def mark_corresponding_notifications_read diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 8672b7547..be95ddb3d 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -462,6 +462,24 @@ describe PeopleController, :type => :controller do get :hovercard, person_id: @hover_test.guid, format: "json" expect(JSON.parse(response.body)["contact"]).not_to be_falsy end + + context "with no user signed in" do + before do + sign_out :user + end + + it "succeeds with local person" do + get :hovercard, person_id: bob.person.guid, format: :json + expect(response.status).to eq(200) + expect(JSON.parse(response.body)["diaspora_id"]).to eq(bob.diaspora_handle) + end + + it "succeeds with remote person" do + get :hovercard, person_id: remote_raphael.guid, format: :json + expect(response.status).to eq(200) + expect(JSON.parse(response.body)["diaspora_id"]).to eq(remote_raphael.diaspora_handle) + end + end end describe '#refresh_search ' do