]> git.openstreetmap.org Git - rails.git/commitdiff
Allow messages to be deleted from the outbox as well as the inbox.
authorTom Hughes <tom@compton.nu>
Thu, 23 Jul 2009 17:41:50 +0000 (17:41 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 23 Jul 2009 17:41:50 +0000 (17:41 +0000)
app/controllers/message_controller.rb
app/models/user.rb
app/views/message/_message_summary.html.erb
app/views/message/_sent_message_summary.html.erb
app/views/message/outbox.html.erb
config/locales/en.yml
db/migrate/037_add_sender_visible_to_message.rb [new file with mode: 0644]

index ba9e9f1e2171d16d41a6c844fc7f4d95356c53fa..db40cc03f7922b33625eb7ed9f17391e3b86b6a0 100644 (file)
@@ -110,10 +110,16 @@ class MessageController < ApplicationController
     if params[:message_id]
       id = params[:message_id]
       message = Message.find_by_id(id)
     if params[:message_id]
       id = params[:message_id]
       message = Message.find_by_id(id)
-      message.visible = false
+      message.from_user_visible = false if message.sender == @user
+      message.to_user_visible = false if message.recipient == @user
       if message.save
         flash[:notice] = t 'message.delete.deleted'
       if message.save
         flash[:notice] = t 'message.delete.deleted'
-        redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
+
+        if params[:referer]
+          redirect_to params[:referer]
+        else
+          redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
+        end
       end
     end
   rescue ActiveRecord::RecordNotFound
       end
     end
   rescue ActiveRecord::RecordNotFound
index 68738a8f071e9bc51c34b5a319b566e81ee106a9..4f1e1f093c30be22c7aff1bff4e7f5ba23a80910 100644 (file)
@@ -3,9 +3,9 @@ class User < ActiveRecord::Base
 
   has_many :traces
   has_many :diary_entries, :order => 'created_at DESC'
 
   has_many :traces
   has_many :diary_entries, :order => 'created_at DESC'
-  has_many :messages, :foreign_key => :to_user_id, :conditions => { :visible => true }, :order => 'sent_on DESC'
+  has_many :messages, :foreign_key => :to_user_id, :conditions => { :to_user_visible => true }, :order => 'sent_on DESC'
   has_many :new_messages, :class_name => "Message", :foreign_key => :to_user_id, :conditions => { :message_read => false }, :order => 'sent_on DESC'
   has_many :new_messages, :class_name => "Message", :foreign_key => :to_user_id, :conditions => { :message_read => false }, :order => 'sent_on DESC'
-  has_many :sent_messages, :class_name => "Message", :foreign_key => :from_user_id, :order => 'sent_on DESC'
+  has_many :sent_messages, :class_name => "Message", :foreign_key => :from_user_id, :conditions => { :from_user_visible => true }, :order => 'sent_on DESC'
   has_many :friends, :include => :befriendee, :conditions => ["users.visible = ?", true]
   has_many :tokens, :class_name => "UserToken"
   has_many :preferences, :class_name => "UserPreference"
   has_many :friends, :include => :befriendee, :conditions => ["users.visible = ?", true]
   has_many :tokens, :class_name => "UserToken"
   has_many :preferences, :class_name => "UserPreference"
index b00329d6e927e6b69f56d234d149ad5c22850261..3d9976aab6e8162ca9855803100910b3ce3256b4 100644 (file)
@@ -10,5 +10,5 @@
     <td><%= button_to t('message.message_summary.read_button'), :controller => 'message', :action => 'mark', :message_id => message_summary.id, :mark => 'read' %></td>
   <% end %>
   <td><%= button_to t('message.message_summary.reply_button'), :controller => 'message', :action => 'reply', :message_id => message_summary.id %></td>
     <td><%= button_to t('message.message_summary.read_button'), :controller => 'message', :action => 'mark', :message_id => message_summary.id, :mark => 'read' %></td>
   <% end %>
   <td><%= button_to t('message.message_summary.reply_button'), :controller => 'message', :action => 'reply', :message_id => message_summary.id %></td>
-  <td><%= button_to t('message.message_summary.delete_button'), :controller => 'message', :action => 'delete', :message_id => message_summary.id %></td>
+  <td><%= button_to t('message.message_summary.delete_button'), :controller => 'message', :action => 'delete', :message_id => message_summary.id, :referer => request.request_uri %></td>
 </tr>
 </tr>
index be1048a024c6fc3b20692952ded7ff8f8b0dbf99..9d3275835d42dca96f717342201d9c4ac713104a 100644 (file)
@@ -4,4 +4,5 @@
   <td class="inbox-sender" bgcolor="<%= this_colour %>"><%= link_to h(sent_message_summary.recipient.display_name), :controller => 'user', :action => sent_message_summary.recipient.display_name %></td>
   <td class="inbox-subject" bgcolor="<%= this_colour %>"><%= link_to h(sent_message_summary.title), :controller => 'message', :action => 'read', :message_id => sent_message_summary.id  %></td>
   <td class="inbox-sent nowrap" bgcolor="<%= this_colour %>"><%= l sent_message_summary.sent_on %></td>
   <td class="inbox-sender" bgcolor="<%= this_colour %>"><%= link_to h(sent_message_summary.recipient.display_name), :controller => 'user', :action => sent_message_summary.recipient.display_name %></td>
   <td class="inbox-subject" bgcolor="<%= this_colour %>"><%= link_to h(sent_message_summary.title), :controller => 'message', :action => 'read', :message_id => sent_message_summary.id  %></td>
   <td class="inbox-sent nowrap" bgcolor="<%= this_colour %>"><%= l sent_message_summary.sent_on %></td>
+  <td><%= button_to t('message.sent_message_summary.delete_button'), :controller => 'message', :action => 'delete', :message_id => sent_message_summary.id, :referer => request.request_uri %></td>
 </tr>
 </tr>
index 5be5b7bfb2897e4aaba020147d35c690f25e668f..f1f9ddea73a5523b6d7ccc96babd876bf3c547a6 100644 (file)
@@ -9,6 +9,7 @@
         <th><%= t'message.outbox.to' %></th>
         <th><%= t'message.outbox.subject' %></th>
         <th><%= t'message.outbox.date' %></th>
         <th><%= t'message.outbox.to' %></th>
         <th><%= t'message.outbox.subject' %></th>
         <th><%= t'message.outbox.date' %></th>
+        <th></th>
       </tr>
       <%= render :partial => "sent_message_summary", :collection => @user.sent_messages %>
     </table>
       </tr>
       <%= render :partial => "sent_message_summary", :collection => @user.sent_messages %>
     </table>
index 06c691f9f026cec37c4255f33a4703f62342c680..5df7504f5d273535184b1c4ad8f6dfad854d2064 100644 (file)
@@ -583,6 +583,8 @@ en:
       reading_your_sent_messages: "Reading your sent messages"
       to: "To"
       back_to_outbox: "Back to outbox"
       reading_your_sent_messages: "Reading your sent messages"
       to: "To"
       back_to_outbox: "Back to outbox"
+    sent_message_summary:
+      delete_button: "Delete"
     mark:
       as_read: "Message marked as read"
       as_unread: "Message marked as unread"
     mark:
       as_read: "Message marked as read"
       as_unread: "Message marked as unread"
diff --git a/db/migrate/037_add_sender_visible_to_message.rb b/db/migrate/037_add_sender_visible_to_message.rb
new file mode 100644 (file)
index 0000000..305473a
--- /dev/null
@@ -0,0 +1,11 @@
+class AddSenderVisibleToMessage < ActiveRecord::Migration
+  def self.up
+    rename_column :messages, :visible, :to_user_visible
+    add_column :messages, :from_user_visible, :boolean, :default => true, :null => false
+  end
+
+  def self.down
+    remove_column :messages, :from_user_visible
+    rename_column :messages, :to_user_visible, :visible
+  end
+end