Added new spam_flag to Accounts, replacing is_flagged_as_spam

• Added:
- new spam_flag to Accounts, replacing is_flagged_as_spam
- null/0: no spam, 1: spam, 2: safe from spam

• Updated:
- Comment, Status to reflect changes

• Todo:
- Fully remove is_flagged_as_spam
- Update SortingQueryBuilder
This commit is contained in:
Developer 2021-02-18 23:46:53 -05:00
parent bf1d00b5f8
commit 2a8ca2cd56
13 changed files with 34 additions and 12 deletions

View File

@ -174,7 +174,7 @@ module Admin
end
def reset_spam
@account.is_flagged_as_spam = false
@account.spam_flag = Account::SPAM_FLAG_CLASS_MAP[:safe]
@account.save!
redirect_to admin_account_path(@account.id)
end

View File

@ -87,7 +87,7 @@ class Api::BaseController < ApplicationController
# : todo : when figure out email/catpcha, put this back
# elsif !current_user.confirmed?
# render json: { error: 'Your login is missing a confirmed e-mail address' }, status: 403
elsif !current_user.account.nil? and current_user.account.is_flagged_as_spam?
elsif !current_user.account.nil? and current_user.account.is_spam?
render json: { error: 'Your account has been flagged as spam. Please contact support@gab.com if you believe this is an error.' }, status: 403
elsif !current_user.approved?
render json: { error: 'Your login is currently pending approval' }, status: 403

View File

@ -110,7 +110,7 @@ class Comment extends ImmutablePureComponent {
if (!status) return null
//If account is spam and not mine, hide
if (status.getIn(['account', 'is_flagged_as_spam']) && status.getIn(['account', 'id']) !== me) {
if (status.getIn(['account', 'is_spam']) && status.getIn(['account', 'id']) !== me) {
return null
}

View File

@ -326,7 +326,7 @@ class Status extends ImmutablePureComponent {
}
//If account is spam and not mine, hide
if (status.getIn(['account', 'is_flagged_as_spam']) && status.getIn(['account', 'id']) !== me) {
if (status.getIn(['account', 'is_spam']) && status.getIn(['account', 'id']) !== me) {
return null
}

View File

@ -49,6 +49,7 @@
# is_donor :boolean default(FALSE), not null
# is_investor :boolean default(FALSE), not null
# is_flagged_as_spam :boolean default(FALSE), not null
# spam_flag :integer
#
class Account < ApplicationRecord
@ -68,6 +69,12 @@ class Account < ApplicationRecord
include AccountCounters
include DomainNormalizable
SPAM_FLAG_CLASS_MAP = {
none: 0,
spam: 1,
safe: 2,
}.freeze
validates :username, presence: true
# Remote user validations
@ -81,6 +88,7 @@ class Account < ApplicationRecord
validates :display_name, length: { maximum: 30 }, if: -> { local? && will_save_change_to_display_name? }
validates :note, note_length: { maximum: 500 }, if: -> { local? && will_save_change_to_note? }
validates :fields, length: { maximum: 6 }, if: -> { local? && will_save_change_to_fields? }
validates :spam_flag, inclusion: { in: SPAM_FLAG_CLASS_MAP.values }
scope :remote, -> { where.not(domain: nil) }
scope :local, -> { where(domain: nil) }
@ -123,6 +131,10 @@ class Account < ApplicationRecord
domain.nil?
end
def is_spam?
spam_flag == SPAM_FLAG_CLASS_MAP[:spam]
end
def moved?
moved_to_account_id.present?
end

View File

@ -59,7 +59,7 @@ class AccountFilter
when "sign_up_date_gte"
Account.where("created_at >= ?", value)
when "spam"
Account.where(is_flagged_as_spam: true)
Account.where(spam_flag: Account::SPAM_FLAG_CLASS_MAP[:spam])
when "is_pro"
Account.where(is_pro: true)
when "is_investor"

View File

@ -4,7 +4,7 @@ class REST::AccountSerializer < ActiveModel::Serializer
include RoutingHelper
attributes :id, :username, :acct, :display_name, :locked, :bot, :created_at,
:note, :url, :avatar, :avatar_static, :header, :header_static, :is_flagged_as_spam,
:note, :url, :avatar, :avatar_static, :header, :header_static, :is_spam,
:followers_count, :following_count, :statuses_count, :is_pro, :is_verified, :is_donor, :is_investor
has_one :moved_to_account, key: :moved, serializer: REST::AccountSerializer, if: :moved_and_not_nested?
@ -24,6 +24,10 @@ class REST::AccountSerializer < ActiveModel::Serializer
object.id.to_s
end
def is_spam
object.is_spam?
end
def note
Formatter.instance.simplified_format(object)
end

View File

@ -12,7 +12,7 @@ class FollowLimitValidator < ActiveModel::Validator
class << self
def limit_for_account(account)
adjusted_limit = account.is_pro ? 50000 : LIMIT
adjusted_limit = account.is_flagged_as_spam ? 0 : LIMIT
adjusted_limit = account.is_spam? ? 0 : LIMIT
adjusted_limit = !account.user.confirmed? ? 10 : LIMIT
if account.following_count < adjusted_limit

View File

@ -1,6 +1,6 @@
- if current_user&.staff?
%div{ :style => "display:flex;flex-direction:row;" }
- if account.is_flagged_as_spam
- if account.is_spam?
%span{ :style => "display:inline-block;margin-right:4px;font-size:12px;background-color:#781600;border-radius:6px;color:#fff;width:40px;line-height:22px;font-weight:600;padding:2px 0 0 6px;" } SPAM
- if account.is_pro
%span{ :style => "display:inline-block;margin-right:4px;font-size:12px;background-color:#FFD700;border-radius:6px;color:#292929;width:24px;line-height:22px;font-weight:600;text-align:center;padding:2px 0 0 2px;" } P

View File

@ -138,11 +138,11 @@
%tr
%th Is flagged as spam
%td
- if @account.is_flagged_as_spam?
- if @account.is_spam?
%span YES
- else
%span no
- if @account.is_flagged_as_spam?
- if @account.is_spam?
%td= table_link_to 'ban', 'Reset', reset_spam_admin_account_path(@account.id), method: :post

View File

@ -25,7 +25,7 @@
= account_link_to target_account, '', size: 36, path: admin_account_path(target_account.id)
.report-card__profile__stats
%div{ :style => "display:flex;flex-direction:row;margin-bottom:4px;" }
- if target_account.is_flagged_as_spam
- if target_account.is_spam?
%span{ :style => "display:inline-block;margin-right:4px;font-size:12px;background-color:#781600;border-radius:6px;color:#fff;width:40px;line-height:22px;font-weight:600;text-align:center;padding:2px 0 0 6px;" } SPAM
- if target_account.is_pro
%span{ :style => "display:inline-block;margin-right:4px;font-size:12px;background-color:#FFD700;border-radius:6px;color:#292929;width:24px;line-height:22px;font-weight:600;text-align:center;padding:2px 0 0 2px;" } P

View File

@ -0,0 +1,5 @@
class AddSpamFlagToAccounts < ActiveRecord::Migration[6.0]
def change
add_column :accounts, :spam_flag, :integer, null: true
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_02_16_022902) do
ActiveRecord::Schema.define(version: 2021_02_18_235403) do
# These are extensions that must be enabled in order to support this database
enable_extension "mongo_fdw"
@ -143,6 +143,7 @@ ActiveRecord::Schema.define(version: 2021_02_16_022902) do
t.boolean "is_donor", default: false, null: false
t.boolean "is_investor", default: false, null: false
t.boolean "is_flagged_as_spam", default: false, null: false
t.integer "spam_flag"
t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin
t.index "lower((username)::text), lower((domain)::text)", name: "index_accounts_on_username_and_domain_lower", unique: true
t.index ["domain"], name: "index_accounts_on_domain"