Class: ListController

Inherits:
ApplicationController show all
Includes:
TopicListResponder, TopicQueryParams
Defined in:
app/controllers/list_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::LEGACY_NO_THEMES, ApplicationController::LEGACY_NO_UNOFFICIAL_PLUGINS, ApplicationController::NO_PLUGINS, ApplicationController::NO_THEMES, ApplicationController::NO_UNOFFICIAL_PLUGINS, ApplicationController::SAFE_MODE

Constants included from CanonicalURL::ControllerExtensions

CanonicalURL::ControllerExtensions::ALLOWED_CANONICAL_PARAMS

Instance Attribute Summary

Attributes inherited from ApplicationController

#theme_id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TopicQueryParams

#build_topic_list_options

Methods included from TopicListResponder

#respond_with_list

Methods inherited from ApplicationController

#application_layout, #can_cache_content?, #clear_notifications, #conditionally_allow_site_embedding, #current_homepage, #discourse_expires_in, #dont_cache_page, #ember_cli_required?, #fetch_user_from_params, #guardian, #handle_permalink, #handle_theme, #handle_unverified_request, #has_escaped_fragment?, #immutable_for, #no_cookies, #perform_refresh_session, #post_ids_including_replies, #preload_json, #rate_limit_second_factor!, #redirect_with_client_support, #render_json_dump, #render_serialized, requires_plugin, #rescue_discourse_actions, #resolve_safe_mode, #secure_session, #serialize_data, #set_current_user_for_logs, #set_layout, #set_mobile_view, #set_mp_snapshot_fields, #show_browser_update?, #store_preloaded, #use_crawler_layout?, #with_resolved_locale

Methods included from VaryHeader

#ensure_vary_header

Methods included from ReadOnlyMixin

#add_readonly_header, #allowed_in_staff_writes_only_mode?, #block_if_readonly_mode, #check_readonly_mode, included, #staff_writes_only_mode?

Methods included from Hijack

#hijack

Methods included from GlobalPath

#cdn_path, #cdn_relative_path, #full_cdn_url, #path, #upload_cdn_path

Methods included from JsonError

#create_errors_json

Methods included from CanonicalURL::ControllerExtensions

#canonical_url, #default_canonical, included

Methods included from CurrentUser

#clear_current_user, #current_user, has_auth_cookie?, #is_api?, #is_user_api?, #log_off_user, #log_on_user, lookup_from_env, #refresh_session

Class Method Details

.generate_message_route(action) ⇒ Object



183
184
185
186
187
# File 'app/controllers/list_controller.rb', line 183

def self.generate_message_route(action)
  define_method action do
    message_route(action)
  end
end

Instance Method Details

#category_defaultObject



144
145
146
147
148
149
150
# File 'app/controllers/list_controller.rb', line 144

def category_default
  canonical_url "#{Discourse.base_url_no_prefix}#{@category.url}"
  view_method = @category.default_view
  view_method = "latest" unless %w[latest top].include?(view_method)

  self.public_send(view_method, category: @category.id)
end

#category_feedObject



263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'app/controllers/list_controller.rb', line 263

def category_feed
  guardian.ensure_can_see!(@category)
  discourse_expires_in 1.minute

  @title = "#{@category.name} - #{SiteSetting.title}"
  @link = "#{Discourse.base_url_no_prefix}#{@category.url}"
  @atom_link = "#{Discourse.base_url_no_prefix}#{@category.url}.rss"
  @description =
    "#{I18n.t("topics_in_category", category: @category.name)} #{@category.description}"
  @topic_list = TopicQuery.new(current_user).list_new_in_category(@category)

  render "list", formats: [:rss]
end

#category_none_topObject



306
307
308
# File 'app/controllers/list_controller.rb', line 306

def category_none_top
  top(category: @category.id, no_subcategories: true)
end

#category_topObject



302
303
304
# File 'app/controllers/list_controller.rb', line 302

def category_top
  top(category: @category.id)
end

#filterObject



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'app/controllers/list_controller.rb', line 123

def filter
  raise Discourse::NotFound if !SiteSetting.experimental_topics_filter

  topic_query_opts = { no_definitions: !SiteSetting.show_category_definitions_in_topic_lists }

  %i[page q].each do |key|
    if params.key?(key.to_s)
      value = params[key]
      raise Discourse::InvalidParameters.new(key) if !TopicQuery.validate?(key, value)
      topic_query_opts[key] = value
    end
  end

  user = list_target_user
  list = TopicQuery.new(user, topic_query_opts).list_filter
  list.more_topics_url = construct_url_with(:next, topic_query_opts)
  list.prev_topics_url = construct_url_with(:prev, topic_query_opts)

  respond_with_list(list)
end

#group_topicsObject



170
171
172
173
174
175
176
177
178
179
180
181
# File 'app/controllers/list_controller.rb', line 170

def group_topics
  group = Group.find_by(name: params[:group_name])
  raise Discourse::NotFound unless group
  guardian.ensure_can_see_group!(group)
  guardian.ensure_can_see_group_members!(group)

  list_opts = build_topic_list_options
  list = generate_list_for("group_topics", group, list_opts)
  list.more_topics_url = construct_url_with(:next, list_opts)
  list.prev_topics_url = construct_url_with(:prev, list_opts)
  respond_with_list(list)
end

#latest_feedObject



234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'app/controllers/list_controller.rb', line 234

def latest_feed
  discourse_expires_in 1.minute

  options = { order: "created" }.merge(build_topic_list_options)

  @title = "#{SiteSetting.title} - #{I18n.t("rss_description.latest")}"
  @link = "#{Discourse.base_url}/latest"
  @atom_link = "#{Discourse.base_url}/latest.rss"
  @description = I18n.t("rss_description.latest")
  @topic_list = TopicQuery.new(nil, options).list_latest

  render "list", formats: [:rss]
end

#message_route(action) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'app/controllers/list_controller.rb', line 189

def message_route(action)
  target_user =
    fetch_user_from_params(
      { include_inactive: current_user.try(:staff?) },
      %i[user_stat user_option],
    )

  case action
  when :private_messages_unread, :private_messages_new, :private_messages_group_new,
       :private_messages_group_unread
    raise Discourse::NotFound if target_user.id != current_user.id
  when :private_messages_tag
    raise Discourse::NotFound if !guardian.can_tag_pms?
  when :private_messages_warnings
    guardian.ensure_can_see_warnings!(target_user)
  when :private_messages_group, :private_messages_group_archive
    group = Group.find_by("LOWER(name) = ?", params[:group_name].downcase)
    raise Discourse::NotFound if !group
    raise Discourse::NotFound unless guardian.can_see_group_messages?(group)
  else
    guardian.ensure_can_see_private_messages!(target_user.id)
  end

  list_opts = build_topic_list_options
  list = generate_list_for(action.to_s, target_user, list_opts)
  url_prefix = "topics"
  list.more_topics_url = construct_url_with(:next, list_opts, url_prefix)
  list.prev_topics_url = construct_url_with(:prev, list_opts, url_prefix)
  respond_with_list(list)
end

#top(options = nil) ⇒ Object



293
294
295
296
297
298
299
300
# File 'app/controllers/list_controller.rb', line 293

def top(options = nil)
  options ||= {}
  period = params[:period]
  period ||=
    ListController.best_period_for(current_user.try(:previous_visit_at), options[:category])
  TopTopic.validate_period(period)
  public_send("top_#{period}", options)
end

#top_feedObject



248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'app/controllers/list_controller.rb', line 248

def top_feed
  discourse_expires_in 1.minute

  @title = "#{SiteSetting.title} - #{I18n.t("rss_description.top")}"
  @link = "#{Discourse.base_url}/top"
  @atom_link = "#{Discourse.base_url}/top.rss"
  @description = I18n.t("rss_description.top")
  period = params[:period] || SiteSetting.top_page_default_timeframe.to_sym
  TopTopic.validate_period(period)

  @topic_list = TopicQuery.new(nil).list_top_for(period)

  render "list", formats: [:rss]
end

#topics_byObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'app/controllers/list_controller.rb', line 152

def topics_by
  list_opts = build_topic_list_options
  target_user =
    fetch_user_from_params(
      {
        include_inactive:
          current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts),
      },
      %i[user_stat user_option],
    )
  ensure_can_see_profile!(target_user)

  list = generate_list_for("topics_by", target_user, list_opts)
  list.more_topics_url = construct_url_with(:next, list_opts)
  list.prev_topics_url = construct_url_with(:prev, list_opts)
  respond_with_list(list)
end

#user_topics_feedObject



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'app/controllers/list_controller.rb', line 277

def user_topics_feed
  discourse_expires_in 1.minute
  target_user = fetch_user_from_params
  ensure_can_see_profile!(target_user)

  @title =
    "#{SiteSetting.title} - #{I18n.t("rss_description.user_topics", username: target_user.username)}"
  @link = "#{target_user.full_url}/activity/topics"
  @atom_link = "#{target_user.full_url}/activity/topics.rss"
  @description = I18n.t("rss_description.user_topics", username: target_user.username)

  @topic_list = TopicQuery.new(nil, order: "created").public_send("list_topics_by", target_user)

  render "list", formats: [:rss]
end