Drop dmail filters.
Few people used dmail filters (~900 users in 5 years) and even fewer used them correctly. Most people used them to try to block dmail spam, but usually they either blocked too much (by adding common words that are present in nearly all dmails, causing all mails to them to be filtered) or too little (blocking specific email addresses or urls, which usually are never seen again after the spammer is banned). Nowadays the spam detection system does a better job of filtering spam.
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
module Maintenance
|
||||
module User
|
||||
class DmailFiltersController < ApplicationController
|
||||
before_action :ensure_ownership
|
||||
respond_to :html, :json, :xml
|
||||
|
||||
def edit
|
||||
@dmail_filter = CurrentUser.dmail_filter || DmailFilter.new
|
||||
end
|
||||
|
||||
def update
|
||||
@dmail_filter = CurrentUser.dmail_filter || DmailFilter.new
|
||||
@dmail_filter.update(dmail_filter_params)
|
||||
flash[:notice] = "Filter updated"
|
||||
respond_with(@dmail)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ensure_ownership
|
||||
@dmail = Dmail.find(params[:dmail_id])
|
||||
|
||||
if @dmail.owner_id != CurrentUser.user.id
|
||||
raise ::User::PrivilegeError.new
|
||||
end
|
||||
end
|
||||
|
||||
def dmail_filter_params
|
||||
params.require(:dmail_filter).permit(:words)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -118,7 +118,6 @@ class UsersController < ApplicationController
|
||||
enable_recommended_posts opt_out_tracking
|
||||
]
|
||||
|
||||
permitted_params += [dmail_filter_attributes: %i[id words]]
|
||||
permitted_params << :name if context == :create
|
||||
permitted_params << :level if CurrentUser.is_admin?
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ class Dmail < ApplicationRecord
|
||||
belongs_to :from, :class_name => "User"
|
||||
|
||||
after_initialize :initialize_attributes, if: :new_record?
|
||||
before_create :auto_read_if_filtered
|
||||
after_create :update_recipient
|
||||
after_commit :send_email, on: :create
|
||||
|
||||
@@ -185,16 +184,6 @@ class Dmail < ApplicationRecord
|
||||
owner == to
|
||||
end
|
||||
|
||||
def filtered?
|
||||
CurrentUser.dmail_filter.try(:filtered?, self)
|
||||
end
|
||||
|
||||
def auto_read_if_filtered
|
||||
if is_recipient? && to.dmail_filter.try(:filtered?, self)
|
||||
self.is_read = true
|
||||
end
|
||||
end
|
||||
|
||||
def update_recipient
|
||||
if is_recipient? && !is_deleted? && !is_read?
|
||||
to.update(has_mail: true, unread_dmail_count: to.dmails.unread.count)
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
class DmailFilter < ApplicationRecord
|
||||
extend Memoist
|
||||
|
||||
belongs_to :user
|
||||
before_validation :initialize_user
|
||||
|
||||
def initialize_user
|
||||
unless user_id
|
||||
self.user_id = CurrentUser.user.id
|
||||
end
|
||||
end
|
||||
|
||||
def filtered?(dmail)
|
||||
dmail.from.level < User::Levels::MODERATOR && has_filter? && (dmail.body.match?(regexp) || dmail.title.match?(regexp) || dmail.from.name.match?(regexp))
|
||||
end
|
||||
|
||||
def has_filter?
|
||||
!words.strip.empty?
|
||||
end
|
||||
|
||||
def regexp
|
||||
union = words.split(/[[:space:]]+/).map { |word| Regexp.escape(word) }.join("|")
|
||||
/\b#{union}\b/i
|
||||
end
|
||||
|
||||
memoize :regexp
|
||||
end
|
||||
@@ -107,7 +107,6 @@ class User < ApplicationRecord
|
||||
has_one :recent_ban, -> {order("bans.id desc")}, :class_name => "Ban"
|
||||
|
||||
has_one :api_key
|
||||
has_one :dmail_filter
|
||||
has_one :super_voter
|
||||
has_one :token_bucket
|
||||
has_many :notes, foreign_key: :creator_id
|
||||
@@ -122,7 +121,6 @@ class User < ApplicationRecord
|
||||
has_many :tag_aliases, foreign_key: :creator_id
|
||||
has_many :tag_implications, foreign_key: :creator_id
|
||||
belongs_to :inviter, class_name: "User", optional: true
|
||||
accepts_nested_attributes_for :dmail_filter
|
||||
|
||||
enum theme: { light: 0, dark: 100 }, _suffix: true
|
||||
|
||||
|
||||
@@ -15,21 +15,13 @@
|
||||
<%= compact_time(dmail.created_at) %>
|
||||
<% end %>
|
||||
<% t.column "From" do |dmail| %>
|
||||
<% if dmail.filtered? %>
|
||||
<%= link_to "[filtered]", user_path(dmail.from) %>
|
||||
<% else %>
|
||||
<%= link_to_user dmail.from %>
|
||||
<% end %>
|
||||
<%= link_to_user dmail.from %>
|
||||
<% end %>
|
||||
<% t.column "To" do |dmail| %>
|
||||
<%= link_to_user dmail.to %>
|
||||
<% end %>
|
||||
<% t.column "Subject", td: { class: "col-expand" } do |dmail| %>
|
||||
<% if dmail.filtered? %>
|
||||
<%= link_to "[filtered]", dmail_path(dmail) %>
|
||||
<% else %>
|
||||
<%= link_to dmail.title, dmail_path(dmail) %>
|
||||
<% end %>
|
||||
<%= link_to dmail.title, dmail_path(dmail) %>
|
||||
<% end %>
|
||||
<% t.column do |dmail| %>
|
||||
<%= link_to "delete", dmail_path(dmail), :method => :delete, :data => {:confirm => "Are you sure you want to delete this Dmail?"} %>
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
<p>
|
||||
<%= link_to "Respond", new_dmail_path(:respond_to_id => @dmail) %>
|
||||
| <%= link_to "Forward", new_dmail_path(:respond_to_id => @dmail, :forward => true) %>
|
||||
| <%= link_to "Filter messages like these", edit_maintenance_user_dmail_filter_path(:dmail_id => @dmail.id) %>
|
||||
| <%= link_to "Permalink", dmail_path(@dmail, :key => @dmail.key), :title => "Use this URL to privately share with a moderator" %>
|
||||
<% if CurrentUser.is_gold? %>
|
||||
<span id="spam-links">
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
<div id="c-maintenance-user-dmail-filters">
|
||||
<div id="a-edit">
|
||||
<h1>Edit Message Filters</h1>
|
||||
|
||||
<div>
|
||||
<h2><%= @dmail.title %></h2>
|
||||
|
||||
<ul style="margin-bottom: 1em;">
|
||||
<li><strong>Sender</strong>: <%= link_to_user @dmail.from %></li>
|
||||
<li><strong>Recipient</strong>: <%= link_to_user @dmail.to, :raw => true %></li>
|
||||
<li><strong>Date</strong>: <%= compact_time(@dmail.created_at) %></li>
|
||||
</ul>
|
||||
|
||||
<h3>Body</h3>
|
||||
<div class="prose">
|
||||
<%= format_text(@dmail.body) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= edit_form_for @dmail_filter, :url => maintenance_user_dmail_filter_path(:dmail_id => @dmail.id) do |f| %>
|
||||
<div class="input text optional field_with_hint">
|
||||
<label class="text" for="dmail_filter_words">Banned Words</label>
|
||||
<%= text_area_tag "dmail_filter[words]", @dmail_filter.words, :id => "dmail_filter_words", :class => "text", :style => "height: 10em;" %>
|
||||
<p class="hint">A list of banned words or users (space delimited). Any message you receive with a banned word will automatically be deleted. Make sure user names have no spaces in them (replace with underscores).</p>
|
||||
</div>
|
||||
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
Edit Message Filters - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
@@ -65,13 +65,6 @@
|
||||
<%= f.input :disable_responsive_mode, :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false, :hint => "Disable alternative layout for mobile and tablet" %>
|
||||
<%= f.input :opt_out_tracking, :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false, :hint => "Opt out of tracking" %>
|
||||
|
||||
<div class="input text optional field_with_hint">
|
||||
<label class="text optional" for="user_dmail_filter_attributes_words">Dmail filter</label>
|
||||
<%= hidden_field_tag "user[dmail_filter_attributes][id]", @user.dmail_filter.try(:id) %>
|
||||
<%= text_field_tag "user[dmail_filter_attributes][words]", @user.dmail_filter.try(:words), :id => "user_dmail_filter_attributes_words", :class => "text optional", :size => 40 %>
|
||||
<span class="hint">A list of banned words (space delimited). Any dmail you receive with a banned word will automatically be deleted.</span>
|
||||
</div>
|
||||
|
||||
<%= f.input :favorite_tags, :label => "Frequent tags", :hint => "A list of tags that you use often. They will appear when using the list of Related Tags.", :input_html => { :rows => 5, :data => { :autocomplete => "tag-query" } } %>
|
||||
<%= f.input :custom_style, :label => "Custom <a href='https://en.wikipedia.org/wiki/Cascading_Style_Sheets'>CSS</a> style".html_safe, :hint => "CSS rules to apply to the whole site.", :input_html => {:size => "40x5"} %>
|
||||
</fieldset>
|
||||
|
||||
Reference in New Issue
Block a user