diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb index 31359ee8..4e17362a 100644 --- a/app/controllers/admin/accounts_controller.rb +++ b/app/controllers/admin/accounts_controller.rb @@ -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 diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index 9dc5bddf..0fa9318b 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -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 diff --git a/app/javascript/gabsocial/components/comment.js b/app/javascript/gabsocial/components/comment.js index b6231cff..4b57f844 100644 --- a/app/javascript/gabsocial/components/comment.js +++ b/app/javascript/gabsocial/components/comment.js @@ -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 } diff --git a/app/javascript/gabsocial/components/status.js b/app/javascript/gabsocial/components/status.js index 36d0a6f8..0444d466 100644 --- a/app/javascript/gabsocial/components/status.js +++ b/app/javascript/gabsocial/components/status.js @@ -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 } diff --git a/app/models/account.rb b/app/models/account.rb index 464b3986..6ef1aed9 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -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 diff --git a/app/models/account_filter.rb b/app/models/account_filter.rb index 55f20ac5..8c2fb218 100644 --- a/app/models/account_filter.rb +++ b/app/models/account_filter.rb @@ -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" diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index 3e7e441e..77edfa7a 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -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 diff --git a/app/validators/follow_limit_validator.rb b/app/validators/follow_limit_validator.rb index ef32ff61..88c88a37 100644 --- a/app/validators/follow_limit_validator.rb +++ b/app/validators/follow_limit_validator.rb @@ -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 diff --git a/app/views/admin/accounts/_account_flags_block.html.haml b/app/views/admin/accounts/_account_flags_block.html.haml index 95fea090..e76c50bd 100644 --- a/app/views/admin/accounts/_account_flags_block.html.haml +++ b/app/views/admin/accounts/_account_flags_block.html.haml @@ -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 diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml index d0e2b7d5..433352a0 100644 --- a/app/views/admin/accounts/show.html.haml +++ b/app/views/admin/accounts/show.html.haml @@ -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 diff --git a/app/views/admin/reports/index.html.haml b/app/views/admin/reports/index.html.haml index c32c213e..2c79dec0 100644 --- a/app/views/admin/reports/index.html.haml +++ b/app/views/admin/reports/index.html.haml @@ -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 diff --git a/db/migrate/20210218235403_add_spam_flag_to_accounts.rb b/db/migrate/20210218235403_add_spam_flag_to_accounts.rb new file mode 100644 index 00000000..81966cb4 --- /dev/null +++ b/db/migrate/20210218235403_add_spam_flag_to_accounts.rb @@ -0,0 +1,5 @@ +class AddSpamFlagToAccounts < ActiveRecord::Migration[6.0] + def change + add_column :accounts, :spam_flag, :integer, null: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 4ce76ee5..9023a692 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"