Class: About
- Inherits:
-
Object
- Object
- About
- Includes:
- ActiveModel::Serialization, StatsCacheable
- Defined in:
- app/models/about.rb
Defined Under Namespace
Classes: CategoryMods
Class Method Summary collapse
Instance Method Summary collapse
- #admins ⇒ Object
- #banner_image ⇒ Object
- #category_moderators ⇒ Object
- #category_mods_limit ⇒ Object
- #category_mods_limit=(number) ⇒ Object
- #description ⇒ Object
- #extended_site_description ⇒ Object
- #https ⇒ Object
-
#initialize(user = nil) ⇒ About
constructor
A new instance of About.
- #locale ⇒ Object
- #moderators ⇒ Object
- #site_creation_date ⇒ Object
- #stats ⇒ Object
- #title ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(user = nil) ⇒ About
Returns a new instance of About.
29 30 31 |
# File 'app/models/about.rb', line 29 def initialize(user = nil) @user = user end |
Class Method Details
.fetch_stats ⇒ Object
25 26 27 |
# File 'app/models/about.rb', line 25 def self.fetch_stats Stat.api_stats end |
.stats_cache_key ⇒ Object
21 22 23 |
# File 'app/models/about.rb', line 21 def self.stats_cache_key "about-stats" end |
Instance Method Details
#admins ⇒ Object
74 75 76 77 78 79 80 |
# File 'app/models/about.rb', line 74 def admins @admins ||= DiscoursePluginRegistry.apply_modifier( :about_admins, apply_excluded_groups(User.where(admin: true).human_users.order(last_seen_at: :desc)), ) end |
#banner_image ⇒ Object
57 58 59 60 61 |
# File 'app/models/about.rb', line 57 def url = SiteSetting.&.url return if url.blank? GlobalPath.full_cdn_url(url) end |
#category_moderators ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/models/about.rb', line 86 def category_moderators allowed_cats = Guardian.new(@user).allowed_category_ids return [] if allowed_cats.blank? cats_with_mods = Category.joins(:category_moderation_groups).distinct.pluck(:id) category_ids = cats_with_mods & allowed_cats return [] if category_ids.blank? per_cat_limit = category_mods_limit / category_ids.size per_cat_limit = 1 if per_cat_limit < 1 results = DB.query(<<~SQL, category_ids:) WITH moderator_users AS ( SELECT cmg.category_id AS category_id, u.id AS user_id, u.last_seen_at, ROW_NUMBER() OVER (PARTITION BY cmg.category_id, u.id ORDER BY u.last_seen_at DESC) as rn FROM category_moderation_groups cmg INNER JOIN group_users gu ON cmg.group_id = gu.group_id INNER JOIN users u ON gu.user_id = u.id WHERE cmg.category_id IN (:category_ids) ) SELECT id AS category_id, user_ids FROM categories INNER JOIN ( SELECT category_id, (ARRAY_AGG(user_id ORDER BY last_seen_at DESC))[:#{per_cat_limit}] AS user_ids FROM moderator_users WHERE rn = 1 GROUP BY category_id ) X ON X.category_id = id ORDER BY position SQL cats = Category.where(id: results.map(&:category_id)).index_by(&:id) mods = User.where(id: results.map(&:user_ids).flatten.uniq).index_by(&:id) results.map { |row| CategoryMods.new(cats[row.category_id], mods.values_at(*row.user_ids)) } end |
#category_mods_limit ⇒ Object
132 133 134 |
# File 'app/models/about.rb', line 132 def category_mods_limit @category_mods_limit || 100 end |
#category_mods_limit=(number) ⇒ Object
136 137 138 |
# File 'app/models/about.rb', line 136 def category_mods_limit=(number) @category_mods_limit = number end |
#description ⇒ Object
49 50 51 |
# File 'app/models/about.rb', line 49 def description SiteSetting.site_description end |
#extended_site_description ⇒ Object
53 54 55 |
# File 'app/models/about.rb', line 53 def extended_site_description SiteSetting.extended_site_description_cooked end |
#https ⇒ Object
37 38 39 |
# File 'app/models/about.rb', line 37 def https SiteSetting.force_https end |
#locale ⇒ Object
45 46 47 |
# File 'app/models/about.rb', line 45 def locale SiteSetting.default_locale end |
#moderators ⇒ Object
67 68 69 70 71 72 |
# File 'app/models/about.rb', line 67 def moderators @moderators ||= apply_excluded_groups( User.where(moderator: true, admin: false).human_users.order(last_seen_at: :desc), ) end |
#site_creation_date ⇒ Object
63 64 65 |
# File 'app/models/about.rb', line 63 def site_creation_date Discourse.site_creation_date end |
#stats ⇒ Object
82 83 84 |
# File 'app/models/about.rb', line 82 def stats @stats ||= About.fetch_cached_stats end |
#title ⇒ Object
41 42 43 |
# File 'app/models/about.rb', line 41 def title SiteSetting.title end |