fixes #2477: Better way to notify when messages get filtered
This commit is contained in:
@@ -8,7 +8,7 @@ class Dmail < ActiveRecord::Base
|
|||||||
belongs_to :owner, :class_name => "User"
|
belongs_to :owner, :class_name => "User"
|
||||||
belongs_to :to, :class_name => "User"
|
belongs_to :to, :class_name => "User"
|
||||||
belongs_to :from, :class_name => "User"
|
belongs_to :from, :class_name => "User"
|
||||||
before_create :auto_delete_if_filtered
|
before_create :auto_read_if_filtered
|
||||||
after_create :update_recipient
|
after_create :update_recipient
|
||||||
after_create :send_dmail
|
after_create :send_dmail
|
||||||
attr_accessible :title, :body, :is_deleted, :to_id, :to, :to_name, :creator_ip_addr
|
attr_accessible :title, :body, :is_deleted, :to_id, :to, :to_name, :creator_ip_addr
|
||||||
@@ -193,9 +193,12 @@ class Dmail < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def auto_delete_if_filtered
|
def filtered?
|
||||||
if owner_id != CurrentUser.user.id && to.dmail_filter.try(:filtered?, self)
|
CurrentUser.dmail_filter.try(:filtered?, self)
|
||||||
self.is_deleted = true
|
end
|
||||||
|
|
||||||
|
def auto_read_if_filtered
|
||||||
|
if owner_id != CurrentUser.id && to.dmail_filter.try(:filtered?, self)
|
||||||
self.is_read = true
|
self.is_read = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,9 +22,21 @@
|
|||||||
<% @dmails.each do |dmail| %>
|
<% @dmails.each do |dmail| %>
|
||||||
<tr class="read-<%= dmail.is_read? %>">
|
<tr class="read-<%= dmail.is_read? %>">
|
||||||
<td><%= compact_time(dmail.created_at) %></td>
|
<td><%= compact_time(dmail.created_at) %></td>
|
||||||
<td><%= link_to_user dmail.from %></td>
|
<td>
|
||||||
|
<% if dmail.filtered? %>
|
||||||
|
<%= link_to "[filtered]", user_path(dmail.from) %>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to_user dmail.from %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
<td><%= link_to_user dmail.to %></td>
|
<td><%= link_to_user dmail.to %></td>
|
||||||
<td><%= link_to dmail.title, dmail_path(dmail) %></td>
|
<td>
|
||||||
|
<% if dmail.filtered? %>
|
||||||
|
<%= link_to "[filtered]", dmail_path(dmail) %>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to dmail.title, dmail_path(dmail) %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to "delete", dmail_path(dmail), :method => :delete, :data => {:confirm => "Are you sure you want to delete this Dmail?"} %>
|
<%= link_to "delete", dmail_path(dmail), :method => :delete, :data => {:confirm => "Are you sure you want to delete this Dmail?"} %>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -27,9 +27,8 @@ class DmailTest < ActiveSupport::TestCase
|
|||||||
assert(@recipient.dmail_filter.filtered?(@dmail))
|
assert(@recipient.dmail_filter.filtered?(@dmail))
|
||||||
end
|
end
|
||||||
|
|
||||||
should "autodelete if it has a banned word" do
|
should "autoread if it has a banned word" do
|
||||||
@dmail.save
|
@dmail.save
|
||||||
assert_equal(true, @dmail.is_deleted?)
|
|
||||||
assert_equal(true, @dmail.is_read?)
|
assert_equal(true, @dmail.is_read?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user