diff options
author | Jonne Haß <me@jhass.eu> | 2015-04-06 13:48:15 +0300 |
---|---|---|
committer | Jonne Haß <me@jhass.eu> | 2015-04-06 13:49:46 +0300 |
commit | 4812dc7a23c0efcf7765c4743de0cb8436cd1478 (patch) | |
tree | ff071936d349897704e9a3bed9274a8fd36e7e87 | |
parent | f4ed086ae06f80daa85cc7d4de05616e40d68dae (diff) | |
parent | a6b9c6c05765525aa16ac479678a72f68155cbcf (diff) |
Merge pull request #5849 from svbergerem/406-on-people-contacts-json
Return 406 on people/guid/contacts, format json
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | app/controllers/people_controller.rb | 40 | ||||
-rw-r--r-- | spec/controllers/people_controller_spec.rb | 5 |
3 files changed, 29 insertions, 17 deletions
diff --git a/Changelog.md b/Changelog.md index 315260b3a..2c6c2d77d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,7 @@ ## Bug fixes * Disable auto follow back on aspect deletion [#5846](https://github.com/diaspora/diaspora/pull/5846) * Fix only sharing flag for contacts that are receiving [#5848](https://github.com/diaspora/diaspora/pull/5848) +* Return 406 when requesting a JSON representation of people/:guid/contacts [#5849](https://github.com/diaspora/diaspora/pull/5849) ## Features * Hide post title of limited post in comment notification email [#5843](https://github.com/diaspora/diaspora/pull/5843) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 57c18fa7b..a4693a90a 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -135,24 +135,30 @@ class PeopleController < ApplicationController end def contacts - @person = Person.find_by_guid(params[:person_id]) + respond_to do |format| + format.json { render nothing: true, status: 406 } - if @person - @contact = current_user.contact_for(@person) - @contacts_of_contact = Contact.contact_contacts_for(current_user, @person) - gon.preloads[:person] = PersonPresenter.new(@person, current_user).full_hash_with_profile - gon.preloads[:photos] = { - count: photos_from(@person, :all).count(:all) - } - gon.preloads[:contacts] = { - count: @contacts_of_contact.count(:all), - } - @contacts_of_contact = @contacts_of_contact.paginate(:page => params[:page], :per_page => (params[:limit] || 15)) - @hashes = hashes_for_people @contacts_of_contact, @aspects - respond_with @person, layout: "with_header" - else - flash[:error] = I18n.t 'people.show.does_not_exist' - redirect_to people_path + format.any do + @person = Person.find_by_guid(params[:person_id]) + + if @person + @contact = current_user.contact_for(@person) + @contacts_of_contact = Contact.contact_contacts_for(current_user, @person) + gon.preloads[:person] = PersonPresenter.new(@person, current_user).full_hash_with_profile + gon.preloads[:photos] = { + count: photos_from(@person, :all).count(:all) + } + gon.preloads[:contacts] = { + count: @contacts_of_contact.count(:all), + } + @contacts_of_contact = @contacts_of_contact.paginate(page: params[:page], per_page: (params[:limit] || 15)) + @hashes = hashes_for_people @contacts_of_contact, @aspects + respond_with @person, layout: "with_header" + else + flash[:error] = I18n.t "people.show.does_not_exist" + redirect_to people_path + end + end end end diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 74610562e..841e3d616 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -497,6 +497,11 @@ describe PeopleController, :type => :controller do get :contacts, :person_id => eve.person.to_param expect(response.body).to include '"photos":{"count":16}' # eve is not sharing with alice end + + it "returns a 406 for json format" do + get :contacts, person_id: "foo", format: :json + expect(response.code).to eq("406") + end end describe '#diaspora_id?' do |