mirror of
https://github.com/discourse/discourse.git
synced 2026-07-29 15:54:48 -05:00
Add ScreenedUrl. Rename BlockedEmail to ScreenedEmail.
This commit is contained in:
@@ -235,6 +235,7 @@ Discourse.AdminUser = Discourse.User.extend({
|
||||
var formData = { context: window.location.pathname };
|
||||
if (block) {
|
||||
formData["block_email"] = true;
|
||||
formData["block_urls"] = true;
|
||||
}
|
||||
Discourse.ajax("/admin/users/" + user.get('id') + '.json', {
|
||||
type: 'DELETE',
|
||||
@@ -292,7 +293,7 @@ Discourse.AdminUser = Discourse.User.extend({
|
||||
"callback": function() {
|
||||
Discourse.ajax("/admin/users/" + user.get('id') + '.json', {
|
||||
type: 'DELETE',
|
||||
data: {delete_posts: true, block_email: true, context: window.location.pathname}
|
||||
data: {delete_posts: true, block_email: true, block_urls: true, context: window.location.pathname}
|
||||
}).then(function(data) {
|
||||
if (data.deleted) {
|
||||
bootbox.alert(I18n.t("admin.user.deleted"), function() {
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
class Admin::BlockedEmailsController < Admin::AdminController
|
||||
|
||||
def index
|
||||
blocked_emails = BlockedEmail.limit(200).order('last_match_at desc').to_a
|
||||
render_serialized(blocked_emails, BlockedEmailSerializer)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class Admin::ScreenedEmailsController < Admin::AdminController
|
||||
|
||||
def index
|
||||
screened_emails = ScreenedEmail.limit(200).order('last_match_at desc').to_a
|
||||
render_serialized(screened_emails, ScreenedEmailSerializer)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -118,7 +118,7 @@ class Admin::UsersController < Admin::AdminController
|
||||
user = User.where(id: params[:id]).first
|
||||
guardian.ensure_can_delete_user!(user)
|
||||
begin
|
||||
if UserDestroyer.new(current_user).destroy(user, params.slice(:delete_posts, :block_email, :context))
|
||||
if UserDestroyer.new(current_user).destroy(user, params.slice(:delete_posts, :block_email, :block_urls, :context))
|
||||
render json: {deleted: true}
|
||||
else
|
||||
render json: {deleted: false, user: AdminDetailedUserSerializer.new(user, root: false).as_json}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
# A BlockedEmail record represents an email address that is being watched,
|
||||
# typically when creating a new User account. If the email of the signup form
|
||||
# (or some other form) matches a BlockedEmail record, an action can be
|
||||
# performed based on the action_type.
|
||||
class BlockedEmail < ActiveRecord::Base
|
||||
|
||||
before_validation :set_defaults
|
||||
|
||||
validates :email, presence: true, uniqueness: true
|
||||
|
||||
def self.actions
|
||||
@actions ||= Enum.new(:block, :do_nothing)
|
||||
end
|
||||
|
||||
def self.block(email, opts={})
|
||||
find_by_email(email) || create(opts.slice(:action_type).merge({email: email}))
|
||||
end
|
||||
|
||||
def self.should_block?(email)
|
||||
blocked_email = BlockedEmail.where(email: email).first
|
||||
blocked_email.record_match! if blocked_email
|
||||
blocked_email && blocked_email.action_type == actions[:block]
|
||||
end
|
||||
|
||||
def set_defaults
|
||||
self.action_type ||= BlockedEmail.actions[:block]
|
||||
end
|
||||
|
||||
def record_match!
|
||||
self.match_count += 1
|
||||
self.last_match_at = Time.zone.now
|
||||
save
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: blocked_emails
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# email :string(255) not null
|
||||
# action_type :integer not null
|
||||
# match_count :integer default(0), not null
|
||||
# last_match_at :datetime
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_blocked_emails_on_email (email) UNIQUE
|
||||
# index_blocked_emails_on_last_match_at (last_match_at)
|
||||
#
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
require_dependency 'screening_model'
|
||||
|
||||
# A ScreenedEmail record represents an email address that is being watched,
|
||||
# typically when creating a new User account. If the email of the signup form
|
||||
# (or some other form) matches a ScreenedEmail record, an action can be
|
||||
# performed based on the action_type.
|
||||
class ScreenedEmail < ActiveRecord::Base
|
||||
|
||||
include ScreeningModel
|
||||
|
||||
default_action :block
|
||||
|
||||
validates :email, presence: true, uniqueness: true
|
||||
|
||||
def self.block(email, opts={})
|
||||
find_by_email(email) || create(opts.slice(:action_type).merge({email: email}))
|
||||
end
|
||||
|
||||
def self.should_block?(email)
|
||||
screened_email = ScreenedEmail.where(email: email).first
|
||||
screened_email.record_match! if screened_email
|
||||
screened_email && screened_email.action_type == actions[:block]
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,26 @@
|
||||
require_dependency 'screening_model'
|
||||
|
||||
# A ScreenedUrl record represents a URL that is being watched.
|
||||
# If the URL is found in a post, some action can be performed.
|
||||
|
||||
# For now, nothing is done. We're just collecting the data and will decide
|
||||
# what to do with it later.
|
||||
class ScreenedUrl < ActiveRecord::Base
|
||||
|
||||
include ScreeningModel
|
||||
|
||||
default_action :do_nothing
|
||||
|
||||
before_validation :strip_http
|
||||
|
||||
validates :url, presence: true, uniqueness: true
|
||||
validates :domain, presence: true
|
||||
|
||||
def strip_http
|
||||
self.url.gsub!(/http(s?):\/\//i, '')
|
||||
end
|
||||
|
||||
def self.watch(url, domain, opts={})
|
||||
find_by_url(url) || create(opts.slice(:action_type).merge(url: url, domain: domain))
|
||||
end
|
||||
end
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
class BlockedEmailSerializer < ApplicationSerializer
|
||||
class ScreenedEmailSerializer < ApplicationSerializer
|
||||
attributes :email,
|
||||
:action,
|
||||
:match_count,
|
||||
:last_match_at,
|
||||
:created_at
|
||||
|
||||
|
||||
def action
|
||||
BlockedEmail.actions.key(object.action_type).to_s
|
||||
ScreenedEmail.actions.key(object.action_type).to_s
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user