/dmails: remove unused search[owner_id] param.

/dmails is restricted to viewing dmails for CurrentUser only (due to
Dmail.visible in the index action). Remove owner_id from subnavbar links
in /dmails, and don't support it in /dmails?search[owner_id], since it
doesn't actually do anything.

Also removes related dead methods and fixes tests that didn't test owner_id properly.
This commit is contained in:
evazion
2017-02-23 20:23:33 -06:00
parent 6de350cd7d
commit d852f98e4f
5 changed files with 28 additions and 26 deletions

View File

@@ -2,11 +2,23 @@ module DmailsHelper
def dmails_current_folder_path def dmails_current_folder_path
case cookies[:dmail_folder] case cookies[:dmail_folder]
when "sent" when "sent"
dmails_path(:search => {:owner_id => CurrentUser.id, :from_id => CurrentUser.id}, :folder => "sent") sent_dmails_path
when "all" when "received"
dmails_path(:search => {:owner_id => CurrentUser.id}, :folder => "all") received_dmails_path
else else
dmails_path(:search => {:owner_id => CurrentUser.id, :to_id => CurrentUser.id}, :folder => "received") all_dmails_path
end end
end end
def all_dmails_path(params = {})
dmails_path(folder: "all", **params)
end
def sent_dmails_path(params = {})
dmails_path(search: {from_id: CurrentUser.id}, folder: "sent", **params)
end
def received_dmails_path(params = {})
dmails_path(search: {to_id: CurrentUser.id}, folder: "received", **params)
end
end end

View File

@@ -86,18 +86,6 @@ class Dmail < ActiveRecord::Base
end end
module SearchMethods module SearchMethods
def for(user)
where("owner_id = ?", user)
end
def inbox
where("to_id = owner_id")
end
def sent
where("from_id = owner_id")
end
def active def active
where("is_deleted = ?", false) where("is_deleted = ?", false)
end end
@@ -139,10 +127,6 @@ class Dmail < ActiveRecord::Base
q = q.search_message(params[:message_matches]) q = q.search_message(params[:message_matches])
end end
if params[:owner_id].present?
q = q.for(params[:owner_id].to_i)
end
if params[:to_name].present? if params[:to_name].present?
q = q.to_name_matches(params[:to_name]) q = q.to_name_matches(params[:to_name])
end end

View File

@@ -1,9 +1,9 @@
<% content_for(:secondary_links) do %> <% content_for(:secondary_links) do %>
<menu> <menu>
<li><%= render "quick_search" %></li> <li><%= render "quick_search" %></li>
<li><%= link_to "All", dmails_path(:search => {:owner_id => CurrentUser.id}, :folder => "all", :set_default_folder => true) %></li> <li><%= link_to "All", all_dmails_path(set_default_folder: true) %></li>
<li><%= link_to "Received", dmails_path(:search => {:owner_id => CurrentUser.id, :to_id => CurrentUser.id}, :folder => "received", :set_default_folder => true) %></li> <li><%= link_to "Received", received_dmails_path(set_default_folder: true) %></li>
<li><%= link_to "Sent", dmails_path(:search => {:owner_id => CurrentUser.id, :from_id => CurrentUser.id}, :folder => "sent", :set_default_folder => true) %></li> <li><%= link_to "Sent", sent_dmails_path(set_default_folder: true) %></li>
<li><%= link_to "New", new_dmail_path %></li> <li><%= link_to "New", new_dmail_path %></li>
<li><%= link_to "Search", search_dmails_path %></li> <li><%= link_to "Search", search_dmails_path %></li>
<li><%= link_to "Mark all as read", {:controller => "dmails", :action => "mark_all_as_read"}, :method => :post, :remote => true %></li> <li><%= link_to "Mark all as read", {:controller => "dmails", :action => "mark_all_as_read"}, :method => :post, :remote => true %></li>

View File

@@ -0,0 +1,6 @@
FactoryGirl.define do
factory(:post_disapproval) do
reason { %w(breaks_rules poor_quality disinterest).sample }
message { FFaker::Lorem.sentence }
end
end

View File

@@ -48,17 +48,17 @@ class DmailsControllerTest < ActionController::TestCase
context "index action" do context "index action" do
should "show dmails owned by the current user" do should "show dmails owned by the current user" do
get :index, {:owner_id_equals => @dmail.owner_id, :folder => "sent"}, {:user_id => @dmail.owner_id} get :index, {:search => {:owner_id => @dmail.owner_id, :folder => "sent"}}, {:user_id => @dmail.owner_id}
assert_response :success assert_response :success
assert_equal(1, assigns[:dmails].size) assert_equal(1, assigns[:dmails].size)
get :index, {:owner_id_equals => @dmail.owner_id, :folder => "received"}, {:user_id => @dmail.owner_id} get :index, {:search => {:owner_id => @dmail.owner_id, :folder => "received"}}, {:user_id => @dmail.owner_id}
assert_response :success assert_response :success
assert_equal(1, assigns[:dmails].size) assert_equal(1, assigns[:dmails].size)
end end
should "not show dmails not owned by the current user" do should "not show dmails not owned by the current user" do
get :index, {:owner_id_equals => @dmail.owner_id}, {:user_id => @unrelated_user.id} get :index, {:search => {:owner_id => @dmail.owner_id}}, {:user_id => @unrelated_user.id}
assert_response :success assert_response :success
assert_equal(0, assigns[:dmails].size) assert_equal(0, assigns[:dmails].size)
end end