Merge branch 'stable' into develop

This commit is contained in:
Steffen van Bergerem 2016-01-20 21:37:30 +01:00
commit 6fce81fc99
6 changed files with 55 additions and 62 deletions

View file

@ -100,6 +100,9 @@ Contributions are very welcome, the hard work is done!
# 0.5.7.0 # 0.5.7.0
## Refactor
* Internationalize controller rescue\_from text [#6554](https://github.com/diaspora/diaspora/pull/6554)
# Bug fixes # Bug fixes
Fix plural rules handling more than wanted as "one" [#6630](https://github.com/diaspora/diaspora/pull/6630) Fix plural rules handling more than wanted as "one" [#6630](https://github.com/diaspora/diaspora/pull/6630)

View file

@ -9,15 +9,15 @@ class AspectMembershipsController < ApplicationController
respond_to :html, :json respond_to :html, :json
def destroy def destroy
aspect = current_user.aspects.joins(:aspect_memberships).where(:aspect_memberships=>{:id=>params[:id]}).first aspect = current_user.aspects.joins(:aspect_memberships).where(aspect_memberships: {id: params[:id]}).first
contact = current_user.contacts.joins(:aspect_memberships).where(:aspect_memberships=>{:id=>params[:id]}).first contact = current_user.contacts.joins(:aspect_memberships).where(aspect_memberships: {id: params[:id]}).first
raise ActiveRecord::RecordNotFound unless aspect.present? && contact.present? raise ActiveRecord::RecordNotFound unless aspect.present? && contact.present?
raise Diaspora::NotMine unless current_user.mine?(aspect) && raise Diaspora::NotMine unless current_user.mine?(aspect) &&
current_user.mine?(contact) current_user.mine?(contact)
membership = contact.aspect_memberships.where(:aspect_id => aspect.id).first membership = contact.aspect_memberships.where(aspect_id: aspect.id).first
raise ActiveRecord::RecordNotFound unless membership.present? raise ActiveRecord::RecordNotFound unless membership.present?
@ -26,17 +26,17 @@ class AspectMembershipsController < ApplicationController
# set the flash message # set the flash message
if success if success
flash.now[:notice] = I18n.t 'aspect_memberships.destroy.success' flash.now[:notice] = I18n.t "aspect_memberships.destroy.success"
else else
flash.now[:error] = I18n.t 'aspect_memberships.destroy.failure' flash.now[:error] = I18n.t "aspect_memberships.destroy.failure"
end end
respond_to do |format| respond_to do |format|
format.json do format.json do
if success if success
render :json => AspectMembershipPresenter.new(membership).base_hash render json: AspectMembershipPresenter.new(membership).base_hash
else else
render :text => membership.errors.full_messages, :status => 403 render text: membership.errors.full_messages, status: 403
end end
end end
@ -46,37 +46,36 @@ class AspectMembershipsController < ApplicationController
def create def create
@person = Person.find(params[:person_id]) @person = Person.find(params[:person_id])
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first @aspect = current_user.aspects.where(id: params[:aspect_id]).first
@contact = current_user.share_with(@person, @aspect) @contact = current_user.share_with(@person, @aspect)
if @contact.present? if @contact.present?
flash.now[:notice] = I18n.t('aspects.add_to_aspect.success') flash.now[:notice] = I18n.t("aspects.add_to_aspect.success")
respond_with do |format| respond_with do |format|
format.json do format.json do
render :json => AspectMembershipPresenter.new( render json: AspectMembershipPresenter.new(
AspectMembership.where(:contact_id => @contact.id, :aspect_id => @aspect.id).first) AspectMembership.where(contact_id: @contact.id, aspect_id: @aspect.id).first)
.base_hash .base_hash
end end
format.all { redirect_to :back } format.all { redirect_to :back }
end end
else else
flash.now[:error] = I18n.t('contacts.create.failure') flash.now[:error] = I18n.t("contacts.create.failure")
render :nothing => true, :status => 409 render nothing: true, status: 409
end end
end end
rescue_from ActiveRecord::StatementInvalid do rescue_from ActiveRecord::StatementInvalid do
render :text => "Duplicate record rejected.", :status => 400 render text: I18n.t("aspect_memberships.destroy.invalid_statement"), status: 400
end end
rescue_from ActiveRecord::RecordNotFound do rescue_from ActiveRecord::RecordNotFound do
render :text => I18n.t('aspect_memberships.destroy.no_membership'), :status => 404 render text: I18n.t("aspect_memberships.destroy.no_membership"), status: 404
end end
rescue_from Diaspora::NotMine do rescue_from Diaspora::NotMine do
render :text => "You are not allowed to do that.", :status => 403 render text: I18n.t("aspect_memberships.destroy.forbidden"), status: 403
end end
end end

View file

@ -2,7 +2,7 @@ class InvitationCodesController < ApplicationController
before_action :ensure_valid_invite_code before_action :ensure_valid_invite_code
rescue_from ActiveRecord::RecordNotFound do rescue_from ActiveRecord::RecordNotFound do
redirect_to root_url, :notice => "That invite code is no longer valid" redirect_to root_url, :notice => I18n.t('invitation_codes.not_valid')
end end
def show def show

View file

@ -22,7 +22,7 @@ class PostsController < ApplicationController
end end
rescue_from Diaspora::NotMine do rescue_from Diaspora::NotMine do
render text: "You are not allowed to do that", status: 403 render text: I18n.t("posts.show.forbidden"), status: 403
end end
def show def show

View file

@ -285,6 +285,8 @@ en:
success: "Successfully removed person from aspect." success: "Successfully removed person from aspect."
failure: "Failed to remove person from aspect." failure: "Failed to remove person from aspect."
no_membership: "Could not find the selected person in that aspect." no_membership: "Could not find the selected person in that aspect."
forbidden: "You are not allowed to do that."
invalid_statement: "Duplicate record rejected."
bookmarklet: bookmarklet:
heading: "Bookmarklet" heading: "Bookmarklet"
@ -594,6 +596,8 @@ en:
invitation_codes: invitation_codes:
excited: "%{name} is excited to see you here." excited: "%{name} is excited to see you here."
not_valid: "That invite code is no longer valid"
invitations: invitations:
create: create:
sent: "Invitations have been sent to: %{emails}" sent: "Invitations have been sent to: %{emails}"
@ -1028,6 +1032,7 @@ en:
destroy: "Delete" destroy: "Delete"
permalink: "Permalink" permalink: "Permalink"
not_found: "Sorry, we couldnt find that post." not_found: "Sorry, we couldnt find that post."
forbidden: "You are not allowed to do that"
photos_by: photos_by:
zero: "No photos by %{author}" zero: "No photos by %{author}"
one: "One photo by %{author}" one: "One photo by %{author}"

View file

@ -2,12 +2,12 @@
# licensed under the Affero General Public License version 3 or later. See # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file. # the COPYRIGHT file.
require 'spec_helper' require "spec_helper"
describe AspectMembershipsController, :type => :controller do describe AspectMembershipsController, type: :controller do
before do before do
@aspect0 = alice.aspects.first @aspect0 = alice.aspects.first
@aspect1 = alice.aspects.create(:name => "another aspect") @aspect1 = alice.aspects.create(name: "another aspect")
@aspect2 = bob.aspects.first @aspect2 = bob.aspects.first
@contact = alice.contact_for(bob.person) @contact = alice.contact_for(bob.person)
@ -15,68 +15,54 @@ describe AspectMembershipsController, :type => :controller do
alice.save alice.save
sign_in :user, alice sign_in :user, alice
allow(@controller).to receive(:current_user).and_return(alice) allow(@controller).to receive(:current_user).and_return(alice)
request.env["HTTP_REFERER"] = 'http://' + request.host request.env["HTTP_REFERER"] = "http://" + request.host
end end
describe '#create' do describe "#create" do
before do before do
@person = eve.person @person = eve.person
end end
it 'succeeds' do it "succeeds" do
post :create, post :create, format: :json, person_id: bob.person.id, aspect_id: @aspect1.id
:format => :json,
:person_id => bob.person.id,
:aspect_id => @aspect1.id
expect(response).to be_success expect(response).to be_success
end end
it 'creates an aspect membership' do it "creates an aspect membership" do
expect { expect {
post :create, post :create, format: :json, person_id: bob.person.id, aspect_id: @aspect1.id
:format => :json,
:person_id => bob.person.id,
:aspect_id => @aspect1.id
}.to change { }.to change {
alice.contact_for(bob.person).aspect_memberships.count alice.contact_for(bob.person).aspect_memberships.count
}.by(1) }.by(1)
end end
it 'creates a contact' do it "creates a contact" do
# argggg why? # argggg why?
alice.contacts.reload alice.contacts.reload
expect { expect {
post :create, post :create, format: :json, person_id: @person.id, aspect_id: @aspect0.id
:format => :json,
:person_id => @person.id,
:aspect_id => @aspect0.id
}.to change { }.to change {
alice.contacts.size alice.contacts.size
}.by(1) }.by(1)
end end
it 'failure flashes error' do it "failure flashes error" do
expect(alice).to receive(:share_with).and_return(nil) expect(alice).to receive(:share_with).and_return(nil)
post :create, post :create, format: :json, person_id: @person.id, aspect_id: @aspect0.id
:format => :json,
:person_id => @person.id,
:aspect_id => @aspect0.id
expect(flash[:error]).not_to be_blank expect(flash[:error]).not_to be_blank
end end
it 'does not 500 on a duplicate key error' do it "does not 500 on a duplicate key error" do
params = {:format => :json, :person_id => @person.id, :aspect_id => @aspect0.id} params = {format: :json, person_id: @person.id, aspect_id: @aspect0.id}
post :create, params post :create, params
post :create, params post :create, params
expect(response.status).to eq(400) expect(response.status).to eq(400)
expect(response.body).to include(I18n.t("aspect_memberships.destroy.invalid_statement"))
end end
context 'json' do context "json" do
it 'returns the aspect membership' do it "returns the aspect membership" do
post :create, post :create, format: :json, person_id: @person.id, aspect_id: @aspect0.id
:format => :json,
:person_id => @person.id,
:aspect_id => @aspect0.id
contact = @controller.current_user.contact_for(@person) contact = @controller.current_user.contact_for(@person)
expect(response.body).to eq(AspectMembershipPresenter.new(contact.aspect_memberships.first).base_hash.to_json) expect(response.body).to eq(AspectMembershipPresenter.new(contact.aspect_memberships.first).base_hash.to_json)
@ -85,26 +71,26 @@ describe AspectMembershipsController, :type => :controller do
end end
describe "#destroy" do describe "#destroy" do
it 'removes contacts from an aspect' do it "removes contacts from an aspect" do
membership = alice.add_contact_to_aspect(@contact, @aspect1) membership = alice.add_contact_to_aspect(@contact, @aspect1)
delete :destroy, :format => :json, :id => membership.id delete :destroy, format: :json, id: membership.id
expect(response).to be_success expect(response).to be_success
@aspect1.reload @aspect1.reload
expect(@aspect1.contacts.to_a).not_to include @contact expect(@aspect1.contacts.to_a).not_to include @contact
end end
it 'does not 500 on an html request' do it "does not 500 on an html request" do
membership = alice.add_contact_to_aspect(@contact, @aspect1) membership = alice.add_contact_to_aspect(@contact, @aspect1)
delete :destroy, :id => membership.id delete :destroy, id: membership.id
expect(response).to redirect_to :back expect(response).to redirect_to :back
@aspect1.reload @aspect1.reload
expect(@aspect1.contacts.to_a).not_to include @contact expect(@aspect1.contacts.to_a).not_to include @contact
end end
it 'aspect membership does not exist' do it "aspect membership does not exist" do
delete :destroy, :format => :json, :id => 123 delete :destroy, format: :json, id: 123
expect(response).not_to be_success expect(response).not_to be_success
expect(response.body).to include "Could not find the selected person in that aspect" expect(response.body).to include I18n.t("aspect_memberships.destroy.no_membership")
end end
end end
end end