2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-04 01:15:08 +08:00
discourse/app/models/directory_column.rb
Ted Johansson 62f3b9fd5e
DEV: Remove ignored columns that are now dropped in migration (#36129)
These post-migration files have now been promoted to migrations:

- `20240212034010_drop_deprecated_columns`
- `20240717053710_drop_groups_smtp_ssl`

And we can remove the interim `ignored_columns` configuration.
2025-11-20 11:09:58 +08:00

75 lines
1.8 KiB
Ruby

# frozen_string_literal: true
class DirectoryColumn < ActiveRecord::Base
self.inheritance_column = nil
enum :type, { automatic: 0, user_field: 1, plugin: 2 }, scopes: false
def self.automatic_column_names
@automatic_column_names ||= %i[
likes_received
likes_given
topics_entered
topic_count
post_count
posts_read
days_visited
]
end
def self.active_column_names
DirectoryColumn
.where(type: %i[automatic plugin])
.where(enabled: true)
.pluck(:name)
.map(&:to_sym)
end
@@plugin_directory_columns = []
def self.plugin_directory_columns
@@plugin_directory_columns
end
belongs_to :user_field
def self.clear_plugin_directory_columns
@@plugin_directory_columns = []
end
def self.find_or_create_plugin_directory_column(attrs)
directory_column =
find_or_create_by(
name: attrs[:column_name],
icon: attrs[:icon],
type: DirectoryColumn.types[:plugin],
) do |column|
column.position = DirectoryColumn.maximum("position") + 1
column.enabled = false
end
if @@plugin_directory_columns.exclude?(directory_column.name)
@@plugin_directory_columns << directory_column.name
DirectoryItem.add_plugin_query(attrs[:query])
end
end
end
# == Schema Information
#
# Table name: directory_columns
#
# id :bigint not null, primary key
# name :string
# automatic_position :integer
# icon :string
# user_field_id :integer
# enabled :boolean not null
# position :integer not null
# created_at :datetime
# type :integer default("automatic"), not null
#
# Indexes
#
# directory_column_index (enabled,position,user_field_id)
#