Skip to content
Extraits de code Groupes Projets
Valider fef22615 rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

Update controllers to use User#retract, change Relayable#relayable to Relayable#relayable?

parent b9af4506
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -122,7 +122,7 @@ class PhotosController < ApplicationController ...@@ -122,7 +122,7 @@ class PhotosController < ApplicationController
photo = current_user.posts.where(:id => params[:id]).first photo = current_user.posts.where(:id => params[:id]).first
if photo if photo
photo.destroy current_user.retract(photo)
respond_to do |format| respond_to do |format|
format.json{ render :nothing => true, :status => 204 } format.json{ render :nothing => true, :status => 204 }
......
...@@ -81,7 +81,7 @@ class StatusMessagesController < ApplicationController ...@@ -81,7 +81,7 @@ class StatusMessagesController < ApplicationController
def destroy def destroy
@status_message = current_user.posts.where(:id => params[:id]).first @status_message = current_user.posts.where(:id => params[:id]).first
if @status_message if @status_message
@status_message.destroy current_user.retract(@status_message)
render :nothing => true, :status => 200 render :nothing => true, :status => 200
else else
Rails.logger.info "event=post_destroy status=failure user=#{current_user.diaspora_handle} reason='User does not own post'" Rails.logger.info "event=post_destroy status=failure user=#{current_user.diaspora_handle} reason='User does not own post'"
......
...@@ -218,7 +218,7 @@ class User < ActiveRecord::Base ...@@ -218,7 +218,7 @@ class User < ActiveRecord::Base
######### Posts and Such ############### ######### Posts and Such ###############
def retract(post) def retract(post)
if post.relayable if post.respond_to?(:relayable?) && post.relayable?
aspects = post.parent.aspects aspects = post.parent.aspects
retraction = RelayableRetraction.build(self, post) retraction = RelayableRetraction.build(self, post)
else else
......
...@@ -15,7 +15,7 @@ module Diaspora ...@@ -15,7 +15,7 @@ module Diaspora
end end
end end
def relayable def relayable?
true true
end end
......
...@@ -22,7 +22,7 @@ class Postzord::Dispatch ...@@ -22,7 +22,7 @@ class Postzord::Dispatch
unless @subscribers == nil unless @subscribers == nil
remote_people, local_people = @subscribers.partition{ |person| person.owner_id.nil? } remote_people, local_people = @subscribers.partition{ |person| person.owner_id.nil? }
if @object.respond_to?(:relayable) && @sender.owns?(@object.parent) if @object.respond_to?(:relayable?) && @sender.owns?(@object.parent)
user_ids = [*local_people].map{|x| x.owner_id } user_ids = [*local_people].map{|x| x.owner_id }
local_users = User.where(:id => user_ids) local_users = User.where(:id => user_ids)
self.notify_users(local_users) self.notify_users(local_users)
......
...@@ -49,7 +49,7 @@ module Postzord ...@@ -49,7 +49,7 @@ module Postzord
end end
def xml_author def xml_author
if @object.respond_to?(:relayable) if @object.respond_to?(:relayable?)
#if A and B are friends, and A sends B a comment from C, we delegate the validation to the owner of the post being commented on #if A and B are friends, and A sends B a comment from C, we delegate the validation to the owner of the post being commented on
xml_author = @user.owns?(@object.parent) ? @object.diaspora_handle : @object.parent.author.diaspora_handle xml_author = @user.owns?(@object.parent) ? @object.diaspora_handle : @object.parent.author.diaspora_handle
@author = Webfinger.new(@object.diaspora_handle).fetch @author = Webfinger.new(@object.diaspora_handle).fetch
...@@ -71,7 +71,7 @@ module Postzord ...@@ -71,7 +71,7 @@ module Postzord
end end
# abort if we haven't received the post to a comment # abort if we haven't received the post to a comment
if @object.respond_to?(:relayable) && @object.parent.nil? if @object.respond_to?(:relayable?) && @object.parent.nil?
Rails.logger.info("event=receive status=abort reason='received a comment but no corresponding post' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{@object.class})") Rails.logger.info("event=receive status=abort reason='received a comment but no corresponding post' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{@object.class})")
return false return false
end end
......
...@@ -8,14 +8,11 @@ describe PhotosController do ...@@ -8,14 +8,11 @@ describe PhotosController do
render_views render_views
before do before do
@alice = alice @alices_photo = alice.post(:photo, :user_file => uploaded_photo, :to => alice.aspects.first.id)
@bob = bob @bobs_photo = bob.post(:photo, :user_file => uploaded_photo, :to => bob.aspects.first.id, :public => true)
@alices_photo = @alice.post(:photo, :user_file => uploaded_photo, :to => @alice.aspects.first.id) @controller.stub!(:current_user).and_return(alice)
@bobs_photo = @bob.post(:photo, :user_file => uploaded_photo, :to => @bob.aspects.first.id, :public => true) sign_in :user, alice
@controller.stub!(:current_user).and_return(@alice)
sign_in :user, @alice
request.env["HTTP_REFERER"] = '' request.env["HTTP_REFERER"] = ''
end end
...@@ -32,23 +29,23 @@ describe PhotosController do ...@@ -32,23 +29,23 @@ describe PhotosController do
end end
it 'can set the photo as the profile photo' do it 'can set the photo as the profile photo' do
old_url = @alice.person.profile.image_url old_url = alice.person.profile.image_url
@params[:photo][:set_profile_photo] = true @params[:photo][:set_profile_photo] = true
post :create, @params post :create, @params
@alice.reload.person.profile.image_url.should_not == old_url alice.reload.person.profile.image_url.should_not == old_url
end end
end end
describe '#index' do describe '#index' do
it "displays the logged in user's pictures" do it "displays the logged in user's pictures" do
get :index, :person_id => @alice.person.id.to_s get :index, :person_id => alice.person.id.to_s
assigns[:person].should == @alice.person assigns[:person].should == alice.person
assigns[:posts].should == [@alices_photo] assigns[:posts].should == [@alices_photo]
end end
it "displays another person's pictures" do it "displays another person's pictures" do
get :index, :person_id => @bob.person.id.to_s get :index, :person_id => bob.person.id.to_s
assigns[:person].should == @bob.person assigns[:person].should == bob.person
assigns[:posts].should == [@bobs_photo] assigns[:posts].should == [@bobs_photo]
end end
end end
...@@ -118,21 +115,32 @@ describe PhotosController do ...@@ -118,21 +115,32 @@ describe PhotosController do
it "redirects when the user does not own the photo" do it "redirects when the user does not own the photo" do
get :edit, :id => @bobs_photo.id get :edit, :id => @bobs_photo.id
response.should redirect_to(:action => :index, :person_id => @alice.person.id.to_s) response.should redirect_to(:action => :index, :person_id => alice.person.id.to_s)
end end
end end
describe '#destroy' do describe '#destroy' do
it 'allows the user to delete his photos' do it 'let a user delete his message' do
delete :destroy, :id => @alices_photo.id delete :destroy, :id => @alices_photo.id
Photo.find_by_id(@alices_photo.id).should be_nil Photo.find_by_id(@alices_photo.id).should be_nil
end end
it 'will not let you destory posts you do not own' do it 'sends a retraction on delete' do
alice.should_receive(:retract).with(@alices_photo)
delete :destroy, :id => @alices_photo.id
end
it 'will not let you destroy posts visible to you' do
delete :destroy, :id => @bobs_photo.id delete :destroy, :id => @bobs_photo.id
Photo.find_by_id(@bobs_photo.id).should be_true Photo.find_by_id(@bobs_photo.id).should be_true
end end
it 'will not let you destory posts you do not own' do
eves_photo = eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => true)
delete :destroy, :id => eves_photo.id
Photo.find_by_id(eves_photo.id).should be_true
end
end end
describe "#update" do describe "#update" do
...@@ -145,13 +153,13 @@ describe PhotosController do ...@@ -145,13 +153,13 @@ describe PhotosController do
new_user = Factory.create(:user) new_user = Factory.create(:user)
params = { :text => "now with lasers!", :author_id => new_user.id } params = { :text => "now with lasers!", :author_id => new_user.id }
put :update, :id => @alices_photo.id, :photo => params put :update, :id => @alices_photo.id, :photo => params
@alices_photo.reload.author_id.should == @alice.person.id @alices_photo.reload.author_id.should == alice.person.id
end end
it 'redirects if you do not have access to the post' do it 'redirects if you do not have access to the post' do
params = { :text => "now with lasers!" } params = { :text => "now with lasers!" }
put :update, :id => @bobs_photo.id, :photo => params put :update, :id => @bobs_photo.id, :photo => params
response.should redirect_to(:action => :index, :person_id => @alice.person.id.to_s) response.should redirect_to(:action => :index, :person_id => alice.person.id.to_s)
end end
end end
......
...@@ -8,42 +8,39 @@ describe StatusMessagesController do ...@@ -8,42 +8,39 @@ describe StatusMessagesController do
render_views render_views
before do before do
@user1 = alice @aspect1 = alice.aspects.first
@user2 = bob @aspect2 = bob.aspects.first
@aspect1 = @user1.aspects.first
@aspect2 = @user2.aspects.first
request.env["HTTP_REFERER"] = "" request.env["HTTP_REFERER"] = ""
sign_in :user, @user1 sign_in :user, alice
@controller.stub!(:current_user).and_return(@user1) @controller.stub!(:current_user).and_return(alice)
@user1.reload alice.reload
end end
describe '#new' do describe '#new' do
it 'succeeds' do it 'succeeds' do
get :new, get :new,
:person_id => @user2.person.id :person_id => bob.person.id
response.should be_success response.should be_success
end end
it 'generates a jasmine fixture' do it 'generates a jasmine fixture' do
contact = @user1.contact_for(@user2.person) contact = alice.contact_for(bob.person)
aspect = @user1.aspects.create(:name => 'people') aspect = alice.aspects.create(:name => 'people')
contact.aspects << aspect contact.aspects << aspect
contact.save contact.save
get :new, :person_id => @user2.person.id, :layout => true get :new, :person_id => bob.person.id, :layout => true
save_fixture(html_for("body"), "status_message_new") save_fixture(html_for("body"), "status_message_new")
end end
end end
describe '#show' do describe '#show' do
before do before do
@message = @user1.build_post :status_message, :text => "ohai", :to => @aspect1.id @message = alice.build_post :status_message, :text => "ohai", :to => @aspect1.id
@message.save! @message.save!
@user1.add_to_streams(@message, [@aspect1]) alice.add_to_streams(@message, [@aspect1])
@user1.dispatch_post @message, :to => @aspect1.id alice.dispatch_post @message, :to => @aspect1.id
end end
it 'succeeds' do it 'succeeds' do
...@@ -97,30 +94,30 @@ describe StatusMessagesController do ...@@ -97,30 +94,30 @@ describe StatusMessagesController do
it "dispatches the post to the specified services" do it "dispatches the post to the specified services" do
s1 = Services::Facebook.new s1 = Services::Facebook.new
@user1.services << s1 alice.services << s1
@user1.services << Services::Twitter.new alice.services << Services::Twitter.new
status_message_hash[:services] = ['facebook'] status_message_hash[:services] = ['facebook']
@user1.should_receive(:dispatch_post).with(anything(), hash_including(:services => [s1])) alice.should_receive(:dispatch_post).with(anything(), hash_including(:services => [s1]))
post :create, status_message_hash post :create, status_message_hash
end end
it "doesn't overwrite author_id" do it "doesn't overwrite author_id" do
status_message_hash[:status_message][:author_id] = @user2.person.id status_message_hash[:status_message][:author_id] = bob.person.id
post :create, status_message_hash post :create, status_message_hash
new_message = StatusMessage.find_by_text(status_message_hash[:status_message][:text]) new_message = StatusMessage.find_by_text(status_message_hash[:status_message][:text])
new_message.author_id.should == @user1.person.id new_message.author_id.should == alice.person.id
end end
it "doesn't overwrite id" do it "doesn't overwrite id" do
old_status_message = @user1.post(:status_message, :text => "hello", :to => @aspect1.id) old_status_message = alice.post(:status_message, :text => "hello", :to => @aspect1.id)
status_message_hash[:status_message][:id] = old_status_message.id status_message_hash[:status_message][:id] = old_status_message.id
post :create, status_message_hash post :create, status_message_hash
old_status_message.reload.text.should == 'hello' old_status_message.reload.text.should == 'hello'
end end
it 'calls dispatch post once subscribers is set' do it 'calls dispatch post once subscribers is set' do
@user1.should_receive(:dispatch_post){|post, opts| alice.should_receive(:dispatch_post){|post, opts|
post.subscribers(@user1).should == [@user2.person] post.subscribers(alice).should == [bob.person]
} }
post :create, status_message_hash post :create, status_message_hash
end end
...@@ -135,8 +132,8 @@ describe StatusMessagesController do ...@@ -135,8 +132,8 @@ describe StatusMessagesController do
fixture_filename = 'button.png' fixture_filename = 'button.png'
fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename) fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename)
@photo1 = @user1.build_post(:photo, :pending => true, :user_file=> File.open(fixture_name), :to => @aspect1.id) @photo1 = alice.build_post(:photo, :pending => true, :user_file=> File.open(fixture_name), :to => @aspect1.id)
@photo2 = @user1.build_post(:photo, :pending => true, :user_file=> File.open(fixture_name), :to => @aspect1.id) @photo2 = alice.build_post(:photo, :pending => true, :user_file=> File.open(fixture_name), :to => @aspect1.id)
@photo1.save! @photo1.save!
@photo2.save! @photo2.save!
...@@ -150,7 +147,7 @@ describe StatusMessagesController do ...@@ -150,7 +147,7 @@ describe StatusMessagesController do
response.should be_redirect response.should be_redirect
end end
it "dispatches all referenced photos" do it "dispatches all referenced photos" do
@user1.should_receive(:dispatch_post).exactly(3).times alice.should_receive(:dispatch_post).exactly(3).times
post :create, @hash post :create, @hash
end end
it "sets the pending bit of referenced photos" do it "sets the pending bit of referenced photos" do
...@@ -166,22 +163,30 @@ describe StatusMessagesController do ...@@ -166,22 +163,30 @@ describe StatusMessagesController do
end end
describe '#destroy' do describe '#destroy' do
let!(:message) {@user1.post(:status_message, :text => "hey", :to => @aspect1.id)} before do
let!(:message2) {@user2.post(:status_message, :text => "hey", :to => @aspect2.id)} @message = alice.post(:status_message, :text => "hey", :to => @aspect1.id)
@message2 = bob.post(:status_message, :text => "hey", :to => @aspect2.id)
@message3 = eve.post(:status_message, :text => "hey", :to => eve.aspects.first.id)
end
it 'let a user delete his message' do
delete :destroy, :id => @message.id
StatusMessage.find_by_id(@message.id).should be_nil
end
it 'let a user delete his photos' do it 'sends a retraction on delete' do
delete :destroy, :id => message.id alice.should_receive(:retract).with(@message)
StatusMessage.find_by_id(message.id).should be_nil delete :destroy, :id => @message.id
end end
it 'will not let you destroy posts visible to you' do it 'will not let you destroy posts visible to you' do
delete :destroy, :id => message2.id delete :destroy, :id => @message2.id
StatusMessage.find_by_id(message2.id).should be_true StatusMessage.find_by_id(@message2.id).should be_true
end end
it 'will not let you destory posts you do not own' do it 'will not let you destory posts you do not own' do
delete :destroy, :id => message2.id delete :destroy, :id => @message3.id
StatusMessage.find_by_id(message2.id).should be_true StatusMessage.find_by_id(@message3.id).should be_true
end end
end end
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter