added delete actions for private messages
This commit is contained in:
parent
090c412690
commit
979d9d7fb4
6 changed files with 90 additions and 12 deletions
19
app/controllers/private_message_visibilities_controller.rb
Normal file
19
app/controllers/private_message_visibilities_controller.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
#
|
||||
|
||||
class PrivateMessageVisibilitiesController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
|
||||
def destroy
|
||||
@vis = PrivateMessageVisibility.where(:person_id => current_user.person.id,
|
||||
:private_message_id => params[:private_message_id]).first
|
||||
if @vis
|
||||
if @vis.destroy
|
||||
flash[:notice] = "Message successfully removed"
|
||||
end
|
||||
end
|
||||
redirect_to private_messages_path
|
||||
end
|
||||
end
|
||||
|
|
@ -3,15 +3,26 @@
|
|||
-# the COPYRIGHT file.
|
||||
|
||||
|
||||
= link_to 'new message', new_private_message_path
|
||||
.span-12.last
|
||||
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
%h2
|
||||
.right
|
||||
= link_to 'new message', new_private_message_path, :class => 'button'
|
||||
Message Inbox
|
||||
|
||||
- for message in @messages
|
||||
%b
|
||||
= message.author.name
|
||||
%br
|
||||
= link_to message.message, message
|
||||
%hr
|
||||
|
||||
- if @messages.count > 0
|
||||
.stream
|
||||
- for message in @messages
|
||||
.stream_element
|
||||
.right
|
||||
= link_to image_tag('deletelabel.png'), private_message_private_message_visibility_path(message), :method => 'delete', :confirm => t('are_you_sure')
|
||||
|
||||
.from
|
||||
= message.author.name
|
||||
%p
|
||||
= link_to message.message, message
|
||||
|
||||
- else
|
||||
%i
|
||||
You have no messages
|
||||
|
|
|
|||
|
|
@ -15,5 +15,5 @@
|
|||
message
|
||||
= private_message.text_area :message, :rows => 5
|
||||
|
||||
= link_to 'cancel', private_messages_path
|
||||
= private_message.submit :send
|
||||
= link_to 'cancel', private_messages_path
|
||||
|
|
|
|||
|
|
@ -27,3 +27,12 @@
|
|||
%h4
|
||||
message
|
||||
= @message.message
|
||||
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
|
||||
= link_to t('delete'), private_message_private_message_visibility_path(@message), :method => 'delete', :confirm => t('are_you_sure')
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# the COPYRIGHT file.
|
||||
|
||||
Diaspora::Application.routes.draw do
|
||||
resources :private_messages
|
||||
|
||||
|
||||
resources :status_messages, :only => [:create, :destroy, :show]
|
||||
resources :comments, :only => [:create]
|
||||
|
|
@ -26,6 +26,10 @@ Diaspora::Application.routes.draw do
|
|||
resources :contacts
|
||||
resources :aspect_memberships, :only => [:destroy, :create]
|
||||
|
||||
resources :private_messages do
|
||||
resource :private_message_visibility, :only => [:destroy], :path => '/visibility/'
|
||||
end
|
||||
|
||||
resources :people, :except => [:edit, :update] do
|
||||
resources :status_messages
|
||||
resources :photos
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe PrivateMessageVisibilitiesController do
|
||||
render_views
|
||||
|
||||
before do
|
||||
@user1 = alice
|
||||
sign_in :user, @user1
|
||||
|
||||
@create_hash = { :participant_ids => [@user1.contacts.first.person.id, @user1.person.id],
|
||||
:author => @user1.person, :message => "cool stuff" }
|
||||
@message = PrivateMessage.create(@create_hash)
|
||||
end
|
||||
|
||||
describe '#destroy' do
|
||||
it 'deletes the visibility' do
|
||||
lambda {
|
||||
delete :destroy, :private_message_id => @message.id
|
||||
}.should change(PrivateMessageVisibility, :count).by(-1)
|
||||
end
|
||||
|
||||
it 'does not let a user destroy a visibility that is not theirs' do
|
||||
user2 = eve
|
||||
sign_in :user, user2
|
||||
|
||||
lambda {
|
||||
delete :destroy, :private_message_id => @message.id
|
||||
}.should_not change(PrivateMessageVisibility, :count)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue