Revert "DEV: move post flags into database (#26951)" (#27102)

This reverts commit 7aff9806eb.
This commit is contained in:
Krzysztof Kotlarek
2024-05-21 16:21:07 +10:00
committed by GitHub
parent 67a7b28096
commit 40d65dddf8
28 changed files with 83 additions and 346 deletions

View File

@@ -1,61 +0,0 @@
# frozen_string_literal: true
class Flag < ActiveRecord::Base
scope :enabled, -> { where(enabled: true) }
scope :system, -> { where("id < 1000") }
before_save :set_position
before_save :set_name_key
after_save :reset_flag_settings!
after_destroy :reset_flag_settings!
def used?
PostAction.exists?(post_action_type_id: self.id) ||
ReviewableScore.exists?(reviewable_score_type: self.id)
end
def self.reset_flag_settings!
PostActionType.reload_types
ReviewableScore.reload_types
end
def system?
self.id < 1000
end
def applies_to?(type)
self.applies_to.include?(type)
end
private
def reset_flag_settings!
self.class.reset_flag_settings!
end
def set_position
self.position = Flag.maximum(:position).to_i + 1 if !self.position
end
def set_name_key
self.name_key = self.name.squeeze(" ").gsub(" ", "_").gsub(/[^\w]/, "").downcase
end
end
# == Schema Information
#
# Table name: flags
#
# id :bigint not null, primary key
# name :string
# name_key :string
# description :text
# notify_type :boolean default(FALSE), not null
# auto_action_type :boolean default(FALSE), not null
# custom_type :boolean default(FALSE), not null
# applies_to :string not null, is an Array
# position :integer not null
# enabled :boolean default(TRUE), not null
# created_at :datetime not null
# updated_at :datetime not null
#

View File

@@ -18,7 +18,7 @@ class PostActionType < ActiveRecord::Base
if settings
@flag_settings = settings
else
reload_types
initialize_flag_settings
end
@types = nil
end
@@ -79,27 +79,34 @@ class PostActionType < ActiveRecord::Base
flag_types.valid?(sym)
end
def reload_types
@types = nil
private
def initialize_flag_settings
@flag_settings = FlagSettings.new
Flag
.enabled
.order(:position)
.each do |flag|
@flag_settings.add(
flag.id,
flag.name_key.to_sym,
topic_type: flag.applies_to?("Topic"),
notify_type: flag.notify_type,
auto_action_type: flag.auto_action_type,
custom_type: flag.custom_type,
name: flag.name,
)
end
@flag_settings.add(3, :off_topic, notify_type: true, auto_action_type: true)
@flag_settings.add(
4,
:inappropriate,
topic_type: true,
notify_type: true,
auto_action_type: true,
)
@flag_settings.add(8, :spam, topic_type: true, notify_type: true, auto_action_type: true)
@flag_settings.add(6, :notify_user, topic_type: false, notify_type: false, custom_type: true)
@flag_settings.add(
7,
:notify_moderators,
topic_type: true,
notify_type: true,
custom_type: true,
)
@flag_settings.add(10, :illegal, topic_type: true, notify_type: true, custom_type: true)
# When adding a new ID here, check that it doesn't clash with any added in
# `ReviewableScore.types`. You can thank me later.
end
end
reload_types
initialize_flag_settings
end
# == Schema Information