Browse Source

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
develop
Developer 2 months ago
parent
commit
2a8ca2cd56
13 changed files with 34 additions and 12 deletions
  1. +1
    -1
      app/controllers/admin/accounts_controller.rb
  2. +1
    -1
      app/controllers/api/base_controller.rb
  3. +1
    -1
      app/javascript/gabsocial/components/comment.js
  4. +1
    -1
      app/javascript/gabsocial/components/status.js
  5. +12
    -0
      app/models/account.rb
  6. +1
    -1
      app/models/account_filter.rb
  7. +5
    -1
      app/serializers/rest/account_serializer.rb
  8. +1
    -1
      app/validators/follow_limit_validator.rb
  9. +1
    -1
      app/views/admin/accounts/_account_flags_block.html.haml
  10. +2
    -2
      app/views/admin/accounts/show.html.haml
  11. +1
    -1
      app/views/admin/reports/index.html.haml
  12. +5
    -0
      db/migrate/20210218235403_add_spam_flag_to_accounts.rb
  13. +2
    -1
      db/schema.rb

+ 1
- 1
app/controllers/admin/accounts_controller.rb 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


+ 1
- 1
app/controllers/api/base_controller.rb 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


+ 1
- 1
app/javascript/gabsocial/components/comment.js 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
}


+ 1
- 1
app/javascript/gabsocial/components/status.js 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
}


+ 12
- 0
app/models/account.rb 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


+ 1
- 1
app/models/account_filter.rb 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"


+ 5
- 1
app/serializers/rest/account_serializer.rb 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


+ 1
- 1
app/validators/follow_limit_validator.rb 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


+ 1
- 1
app/views/admin/accounts/_account_flags_block.html.haml 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


+ 2
- 2
app/views/admin/accounts/show.html.haml 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


+ 1
- 1
app/views/admin/reports/index.html.haml 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


+ 5
- 0
db/migrate/20210218235403_add_spam_flag_to_accounts.rb View File

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

+ 2
- 1
db/schema.rb 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"


Loading…
Cancel
Save