fixes #2230
This commit is contained in:
@@ -45,7 +45,11 @@ div#c-users {
|
||||
|
||||
div#a-edit {
|
||||
h1 {
|
||||
margin-bottom: 0.5em;
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
|
||||
div.input {
|
||||
|
||||
@@ -8,6 +8,7 @@ class Dmail < ActiveRecord::Base
|
||||
belongs_to :owner, :class_name => "User"
|
||||
belongs_to :to, :class_name => "User"
|
||||
belongs_to :from, :class_name => "User"
|
||||
before_create :auto_delete_if_filtered
|
||||
after_create :update_recipient
|
||||
after_create :send_dmail
|
||||
attr_accessible :title, :body, :is_deleted, :to_id, :to, :to_name, :creator_ip_addr
|
||||
@@ -192,8 +193,16 @@ class Dmail < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def auto_delete_if_filtered
|
||||
if owner_id != CurrentUser.user.id && to.dmail_filter.try(:filtered?, self)
|
||||
self.is_deleted = true
|
||||
end
|
||||
end
|
||||
|
||||
def update_recipient
|
||||
to.update_attribute(:has_mail, true)
|
||||
unless is_deleted
|
||||
to.update_attribute(:has_mail, true)
|
||||
end
|
||||
end
|
||||
|
||||
def visible_to?(user)
|
||||
|
||||
12
app/models/dmail_filter.rb
Normal file
12
app/models/dmail_filter.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class DmailFilter < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
attr_accessible :user_id, :words, :as => [:moderator, :janitor, :contributor, :gold, :member, :anonymous, :default, :builder, :admin]
|
||||
|
||||
def filtered?(dmail)
|
||||
dmail.body =~ regexp || dmail.subject =~ regexp
|
||||
end
|
||||
|
||||
def regexp
|
||||
@regexp ||= Regexp.compile(words.scan(/\S+/).map {|x| Regexp.escape(x)}.join("|"))
|
||||
end
|
||||
end
|
||||
@@ -33,7 +33,7 @@ class User < ActiveRecord::Base
|
||||
}
|
||||
|
||||
attr_accessor :password, :old_password
|
||||
attr_accessible :enable_privacy_mode, :enable_post_navigation, :new_post_navigation_layout, :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :enable_sequential_post_navigation, :per_page, :hide_deleted_posts, :style_usernames, :enable_auto_complete, :custom_style, :show_deleted_children, :as => [:moderator, :janitor, :contributor, :gold, :member, :anonymous, :default, :builder, :admin]
|
||||
attr_accessible :dmail_filter_attributes, :enable_privacy_mode, :enable_post_navigation, :new_post_navigation_layout, :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :enable_sequential_post_navigation, :per_page, :hide_deleted_posts, :style_usernames, :enable_auto_complete, :custom_style, :show_deleted_children, :as => [:moderator, :janitor, :contributor, :gold, :member, :anonymous, :default, :builder, :admin]
|
||||
attr_accessible :level, :as => :admin
|
||||
validates_length_of :name, :within => 2..100, :on => :create
|
||||
validates_format_of :name, :with => /\A[^\s:]+\Z/, :on => :create, :message => "cannot have whitespace or colons"
|
||||
@@ -60,12 +60,14 @@ class User < ActiveRecord::Base
|
||||
has_many :bans, lambda {order("bans.id desc")}
|
||||
has_one :recent_ban, lambda {order("bans.id desc")}, :class_name => "Ban"
|
||||
has_one :api_key
|
||||
has_one :dmail_filter
|
||||
has_many :subscriptions, lambda {order("tag_subscriptions.name")}, :class_name => "TagSubscription", :foreign_key => "creator_id"
|
||||
has_many :note_versions, :foreign_key => "updater_id"
|
||||
has_many :dmails, lambda {order("dmails.id desc")}, :foreign_key => "owner_id"
|
||||
has_many :saved_searches
|
||||
belongs_to :inviter, :class_name => "User"
|
||||
after_update :create_mod_action
|
||||
accepts_nested_attributes_for :dmail_filter
|
||||
|
||||
module BanMethods
|
||||
def validate_ip_addr_is_not_banned
|
||||
|
||||
@@ -67,6 +67,12 @@
|
||||
<span class="hint">A list of tags that you use often. They will appear when using the list of Related Tags.</span>
|
||||
</div>
|
||||
|
||||
<div class="input text optional field_with_hint">
|
||||
<label class="text optional" for="user_dmail_filter_attributes_words">Dmail filter</label>
|
||||
<%= 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 :custom_style, :label => "Custom <a href='http://en.wikipedia.org/wiki/Cascading_Style_Sheets'>CSS</a> style".html_safe, :hint => "Style to apply to the whole site.", :input_html => {:size => "40x5"} %>
|
||||
</fieldset>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user