Class: ListController
Constant Summary
ApplicationController::CHALLENGE_KEY, ApplicationController::HONEYPOT_KEY, ApplicationController::LEGACY_NO_THEMES, ApplicationController::LEGACY_NO_UNOFFICIAL_PLUGINS, ApplicationController::NO_PLUGINS, ApplicationController::NO_THEMES, ApplicationController::NO_UNOFFICIAL_PLUGINS, ApplicationController::SAFE_MODE
CanonicalURL::ControllerExtensions::ALLOWED_CANONICAL_PARAMS
Instance Attribute Summary
#theme_id
Class Method Summary
collapse
Instance Method Summary
collapse
#build_topic_list_options
#respond_with_list
#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, #login_method, #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
resolve_theme_id
#add_readonly_header, #allowed_in_staff_writes_only_mode?, #block_if_readonly_mode, #check_readonly_mode, #get_or_check_readonly_mode, #get_or_check_staff_writes_only_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
#canonical_url, #default_canonical, included
#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
186
187
188
189
190
|
# File 'app/controllers/list_controller.rb', line 186
def self.generate_message_route(action)
define_method action do
message_route(action)
end
end
|
Instance Method Details
#category_default ⇒ Object
147
148
149
150
151
152
153
|
# File 'app/controllers/list_controller.rb', line 147
def category_default
canonical_url "#{Discourse.base_url_no_prefix}#{@category.url}"
view_method = @category.default_view
view_method = "latest" if %w[latest top].exclude?(view_method)
self.public_send(view_method, category: @category.id)
end
|
#category_feed ⇒ Object
274
275
276
277
278
279
280
281
282
283
284
285
286
|
# File 'app/controllers/list_controller.rb', line 274
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_top ⇒ Object
317
318
319
|
# File 'app/controllers/list_controller.rb', line 317
def category_none_top
top(category: @category.id, no_subcategories: true)
end
|
#category_top ⇒ Object
313
314
315
|
# File 'app/controllers/list_controller.rb', line 313
def category_top
top(category: @category.id)
end
|
#filter ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'app/controllers/list_controller.rb', line 128
def 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_topics ⇒ Object
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'app/controllers/list_controller.rb', line 173
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
|
#hot_feed ⇒ Object
266
267
268
269
270
271
272
|
# File 'app/controllers/list_controller.rb', line 266
def hot_feed
discourse_expires_in 1.minute
@topic_list = TopicQuery.new(nil).list_hot
render "list", formats: [:rss]
end
|
#latest_feed ⇒ Object
237
238
239
240
241
242
243
244
245
246
247
248
249
|
# File 'app/controllers/list_controller.rb', line 237
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
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
219
220
221
|
# File 'app/controllers/list_controller.rb', line 192
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
304
305
306
307
308
309
310
311
|
# File 'app/controllers/list_controller.rb', line 304
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
|
#topics_by ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'app/controllers/list_controller.rb', line 155
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_feed ⇒ Object
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
# File 'app/controllers/list_controller.rb', line 288
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
|