diff --git a/app/controllers/dmails_controller.rb b/app/controllers/dmails_controller.rb index b1eeede00..b68b20432 100644 --- a/app/controllers/dmails_controller.rb +++ b/app/controllers/dmails_controller.rb @@ -1,6 +1,6 @@ class DmailsController < ApplicationController respond_to :html, :xml, :js, :json - before_action :member_only, except: [:index, :show, :update, :destroy, :mark_all_as_read] + before_action :member_only, except: [:index, :show, :update, :mark_all_as_read] def new if params[:respond_to_id] @@ -18,7 +18,8 @@ class DmailsController < ApplicationController if params[:folder] && params[:set_default_folder] cookies.permanent[:dmail_folder] = params[:folder] end - @dmails = Dmail.active.visible.paginated_search(params, count_pages: true) + + @dmails = Dmail.visible.paginated_search(params, defaults: { is_spam: false, is_deleted: false }, count_pages: true) respond_with(@dmails) end @@ -43,14 +44,6 @@ class DmailsController < ApplicationController respond_with(@dmail) end - def destroy - @dmail = Dmail.find(params[:id]) - check_privilege(@dmail) - @dmail.mark_as_read! - @dmail.destroy - redirect_to dmails_path, :notice => "Message destroyed" - end - def mark_all_as_read Dmail.visible.unread.each do |x| x.update_column(:is_read, true) diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 777ab9011..8af541e1a 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -7,8 +7,10 @@ class ApplicationRecord < ActiveRecord::Base extending(PaginationExtension).paginate(*options) end - def paginated_search(params, count_pages: params[:search].present?) + def paginated_search(params, defaults: {}, count_pages: params[:search].present?) search_params = params.fetch(:search, {}).permit! + search_params = defaults.merge(search_params).with_indifferent_access + search(search_params).paginate(params[:page], limit: params[:limit], search_count: count_pages) end end @@ -93,7 +95,7 @@ class ApplicationRecord < ActiveRecord::Base end def search_boolean_attribute(attribute, params) - return all unless params[attribute] + return all unless params.key?(attribute) value = params[attribute].to_s if value.truthy? diff --git a/app/models/dmail.rb b/app/models/dmail.rb index eb8ae5085..b635af47b 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -136,8 +136,6 @@ class Dmail < ApplicationRecord q = q.text_attribute_matches(:title, params[:title_matches]) q = q.text_attribute_matches(:body, params[:message_matches], index_column: :message_index) - params[:is_spam] = false unless params[:is_spam].present? - q = q.read if params[:read].to_s.truthy? q = q.unread if params[:read].to_s.falsy? diff --git a/app/views/dmails/_secondary_links.html.erb b/app/views/dmails/_secondary_links.html.erb index bd73cf9c6..9a3649914 100644 --- a/app/views/dmails/_secondary_links.html.erb +++ b/app/views/dmails/_secondary_links.html.erb @@ -4,6 +4,7 @@ <%= subnav_link_to "Received", received_dmails_path(set_default_folder: true) %> <%= subnav_link_to "Sent", sent_dmails_path(set_default_folder: true) %> <%= subnav_link_to "Spam", spam_dmails_path %> + <%= subnav_link_to "Deleted", dmails_path(search: { is_deleted: true }) %>