2013-02-05 14:16:51 -05:00
|
|
|
require_dependency 'topic_view'
|
|
|
|
require_dependency 'promotion'
|
2013-12-12 11:24:00 -05:00
|
|
|
require_dependency 'url_helper'
|
2014-01-30 11:15:49 -05:00
|
|
|
require_dependency 'topics_bulk_action'
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
class TopicsController < ApplicationController
|
2013-12-12 11:24:00 -05:00
|
|
|
include UrlHelper
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-02-07 10:45:24 -05:00
|
|
|
before_filter :ensure_logged_in, only: [:timings,
|
|
|
|
:destroy_timings,
|
|
|
|
:update,
|
|
|
|
:star,
|
|
|
|
:destroy,
|
2013-07-12 12:08:23 -04:00
|
|
|
:recover,
|
2013-02-07 10:45:24 -05:00
|
|
|
:status,
|
|
|
|
:invite,
|
|
|
|
:mute,
|
|
|
|
:unmute,
|
2013-02-05 14:16:51 -05:00
|
|
|
:set_notifications,
|
2013-03-06 15:17:07 -05:00
|
|
|
:move_posts,
|
2013-05-16 15:55:14 -04:00
|
|
|
:merge_topic,
|
2013-05-07 14:25:41 -04:00
|
|
|
:clear_pin,
|
2014-04-09 20:56:56 -04:00
|
|
|
:re_pin,
|
2014-01-29 15:48:52 -05:00
|
|
|
:autoclose,
|
2014-03-03 15:46:38 -05:00
|
|
|
:bulk,
|
2014-03-27 21:28:14 -04:00
|
|
|
:reset_new,
|
|
|
|
:change_post_owners]
|
2013-03-06 15:17:07 -05:00
|
|
|
|
2013-02-10 13:50:26 -05:00
|
|
|
before_filter :consider_user_for_promotion, only: :show
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-08-13 16:08:29 -04:00
|
|
|
skip_before_filter :check_xhr, only: [:show, :feed]
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-02-10 13:50:26 -05:00
|
|
|
def show
|
2014-08-03 21:06:06 -04:00
|
|
|
flash["referer"] ||= request.referer
|
|
|
|
|
2013-06-28 13:55:34 -04:00
|
|
|
# We'd like to migrate the wordpress feed to another url. This keeps up backwards compatibility with
|
|
|
|
# existing installs.
|
|
|
|
return wordpress if params[:best].present?
|
|
|
|
|
2014-07-15 17:02:43 -04:00
|
|
|
opts = params.slice(:username_filters, :filter, :page, :post_number, :show_deleted)
|
2013-10-28 02:12:07 -04:00
|
|
|
username_filters = opts[:username_filters]
|
2013-09-16 14:08:55 -04:00
|
|
|
|
2014-04-15 15:33:08 -04:00
|
|
|
opts[:username_filters] = username_filters.split(',') if username_filters.is_a?(String)
|
2013-10-03 12:51:30 -04:00
|
|
|
|
2013-06-06 14:41:27 -04:00
|
|
|
begin
|
|
|
|
@topic_view = TopicView.new(params[:id] || params[:topic_id], current_user, opts)
|
|
|
|
rescue Discourse::NotFound
|
2014-06-24 21:36:17 -04:00
|
|
|
topic = Topic.find_by(slug: params[:id].downcase) if params[:id]
|
2013-06-06 14:41:27 -04:00
|
|
|
raise Discourse::NotFound unless topic
|
2014-08-13 16:12:44 -04:00
|
|
|
redirect_to_correct_topic(topic, opts[:post_number]) && return
|
2013-06-06 14:41:27 -04:00
|
|
|
end
|
2013-05-19 20:29:49 -04:00
|
|
|
|
2013-10-16 01:39:18 -04:00
|
|
|
discourse_expires_in 1.minute
|
2013-07-04 14:08:23 -04:00
|
|
|
|
2014-08-13 16:12:44 -04:00
|
|
|
redirect_to_correct_topic(@topic_view.topic, opts[:post_number]) && return if slugs_do_not_match || (!request.xhr? && params[:slug].nil?)
|
2013-07-04 14:08:23 -04:00
|
|
|
|
2013-10-16 01:39:18 -04:00
|
|
|
track_visit_to_topic
|
2013-10-04 03:00:23 -04:00
|
|
|
|
2013-10-16 01:39:18 -04:00
|
|
|
if should_track_visit_to_topic?
|
|
|
|
@topic_view.draft = Draft.get(current_user, @topic_view.draft_key, @topic_view.draft_sequence)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
2013-02-13 06:04:43 -05:00
|
|
|
|
2013-10-16 01:39:18 -04:00
|
|
|
perform_show_response
|
|
|
|
|
2013-12-16 18:35:34 -05:00
|
|
|
canonical_url absolute_without_cdn(@topic_view.canonical_path)
|
2014-05-26 13:26:28 -04:00
|
|
|
rescue Discourse::InvalidAccess => ex
|
|
|
|
|
|
|
|
if current_user
|
|
|
|
# If the user can't see the topic, clean up notifications for it.
|
|
|
|
Notification.remove_for(current_user.id, params[:topic_id])
|
|
|
|
end
|
|
|
|
|
|
|
|
raise ex
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-06-28 13:55:34 -04:00
|
|
|
def wordpress
|
|
|
|
params.require(:best)
|
|
|
|
params.require(:topic_id)
|
2013-07-05 16:07:24 -04:00
|
|
|
params.permit(:min_trust_level, :min_score, :min_replies, :bypass_trust_level_score, :only_moderator_liked)
|
2014-06-16 12:28:07 -04:00
|
|
|
|
2013-10-28 02:12:07 -04:00
|
|
|
opts = { best: params[:best].to_i,
|
|
|
|
min_trust_level: params[:min_trust_level] ? 1 : params[:min_trust_level].to_i,
|
|
|
|
min_score: params[:min_score].to_i,
|
|
|
|
min_replies: params[:min_replies].to_i,
|
|
|
|
bypass_trust_level_score: params[:bypass_trust_level_score].to_i, # safe cause 0 means ignore
|
|
|
|
only_moderator_liked: params[:only_moderator_liked].to_s == "true"
|
|
|
|
}
|
|
|
|
|
|
|
|
@topic_view = TopicView.new(params[:topic_id], current_user, opts)
|
2013-10-16 01:39:18 -04:00
|
|
|
discourse_expires_in 1.minute
|
|
|
|
|
|
|
|
wordpress_serializer = TopicViewWordpressSerializer.new(@topic_view, scope: guardian, root: false)
|
|
|
|
render_json_dump(wordpress_serializer)
|
2013-06-20 17:20:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def posts
|
|
|
|
params.require(:topic_id)
|
|
|
|
params.require(:post_ids)
|
2013-06-28 13:55:34 -04:00
|
|
|
|
2013-06-20 17:20:08 -04:00
|
|
|
@topic_view = TopicView.new(params[:topic_id], current_user, post_ids: params[:post_ids])
|
|
|
|
render_json_dump(TopicViewPostsSerializer.new(@topic_view, scope: guardian, root: false))
|
2013-06-28 13:55:34 -04:00
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
def destroy_timings
|
2014-02-21 13:03:50 -05:00
|
|
|
PostTiming.destroy_for(current_user.id, [params[:topic_id].to_i])
|
2013-02-05 14:16:51 -05:00
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2014-05-06 09:41:59 -04:00
|
|
|
topic = Topic.find_by(id: params[:topic_id])
|
2013-02-07 10:45:24 -05:00
|
|
|
guardian.ensure_can_edit!(topic)
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2014-06-16 12:28:07 -04:00
|
|
|
topic.title = params[:title] if params[:title].present?
|
2013-12-11 21:41:34 -05:00
|
|
|
topic.acting_user = current_user
|
|
|
|
|
2013-05-31 15:22:34 -04:00
|
|
|
success = false
|
2013-02-05 14:16:51 -05:00
|
|
|
Topic.transaction do
|
2014-07-16 15:39:39 -04:00
|
|
|
success = topic.save && topic.change_category_to_id(params[:category_id].to_i)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
2013-12-11 21:41:34 -05:00
|
|
|
|
|
|
|
# this is used to return the title to the client as it may have been changed by "TextCleaner"
|
2013-10-28 02:12:07 -04:00
|
|
|
success ? render_serialized(topic, BasicTopicSerializer) : render_json_error(topic)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-03-14 14:45:29 -04:00
|
|
|
def similar_to
|
2013-06-06 03:14:32 -04:00
|
|
|
params.require(:title)
|
|
|
|
params.require(:raw)
|
2013-03-14 14:45:29 -04:00
|
|
|
title, raw = params[:title], params[:raw]
|
2013-10-28 02:12:07 -04:00
|
|
|
[:title, :raw].each { |key| check_length_of(key, params[key]) }
|
2013-03-14 14:45:29 -04:00
|
|
|
|
2013-12-21 02:19:22 -05:00
|
|
|
# Only suggest similar topics if the site has a minimum amount of topics present.
|
2013-10-28 02:12:07 -04:00
|
|
|
topics = Topic.similar_to(title, raw, current_user).to_a if Topic.count_exceeds_minimum?
|
2013-06-19 13:13:12 -04:00
|
|
|
|
2013-03-14 14:45:29 -04:00
|
|
|
render_serialized(topics, BasicTopicSerializer)
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
def status
|
2013-06-06 03:14:32 -04:00
|
|
|
params.require(:status)
|
|
|
|
params.require(:enabled)
|
2013-10-28 02:12:07 -04:00
|
|
|
status, topic_id = params[:status], params[:topic_id].to_i
|
|
|
|
enabled = (params[:enabled] == 'true')
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-10-28 02:12:07 -04:00
|
|
|
check_for_status_presence(:status, status)
|
2014-05-06 09:41:59 -04:00
|
|
|
@topic = Topic.find_by(id: topic_id)
|
2013-02-05 14:16:51 -05:00
|
|
|
guardian.ensure_can_moderate!(@topic)
|
2013-10-28 02:12:07 -04:00
|
|
|
@topic.update_status(status, enabled, current_user)
|
2013-02-05 14:16:51 -05:00
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
|
|
|
def star
|
2014-05-06 09:41:59 -04:00
|
|
|
@topic = Topic.find_by(id: params[:topic_id].to_i)
|
2013-02-05 14:16:51 -05:00
|
|
|
guardian.ensure_can_see!(@topic)
|
|
|
|
|
|
|
|
@topic.toggle_star(current_user, params[:starred] == 'true')
|
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
2013-02-07 10:45:24 -05:00
|
|
|
def mute
|
2013-06-14 01:38:59 -04:00
|
|
|
toggle_mute
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def unmute
|
2013-06-14 01:38:59 -04:00
|
|
|
toggle_mute
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-05-07 14:25:41 -04:00
|
|
|
def autoclose
|
2013-11-26 19:06:20 -05:00
|
|
|
raise Discourse::InvalidParameters.new(:auto_close_time) unless params.has_key?(:auto_close_time)
|
2014-05-06 09:41:59 -04:00
|
|
|
topic = Topic.find_by(id: params[:topic_id].to_i)
|
2013-11-26 19:06:20 -05:00
|
|
|
guardian.ensure_can_moderate!(topic)
|
|
|
|
topic.set_auto_close(params[:auto_close_time], current_user)
|
|
|
|
if topic.save
|
|
|
|
render json: success_json.merge!(auto_close_at: topic.auto_close_at)
|
|
|
|
else
|
|
|
|
render_json_error(topic)
|
|
|
|
end
|
2013-05-07 14:25:41 -04:00
|
|
|
end
|
|
|
|
|
2014-06-16 12:28:07 -04:00
|
|
|
def make_banner
|
|
|
|
topic = Topic.find_by(id: params[:topic_id].to_i)
|
|
|
|
guardian.ensure_can_moderate!(topic)
|
|
|
|
|
2014-06-16 13:21:21 -04:00
|
|
|
topic.make_banner!(current_user)
|
2014-06-16 12:28:07 -04:00
|
|
|
|
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_banner
|
|
|
|
topic = Topic.find_by(id: params[:topic_id].to_i)
|
|
|
|
guardian.ensure_can_moderate!(topic)
|
|
|
|
|
2014-06-16 13:21:21 -04:00
|
|
|
topic.remove_banner!(current_user)
|
2014-06-16 12:28:07 -04:00
|
|
|
|
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
def destroy
|
2014-05-06 09:41:59 -04:00
|
|
|
topic = Topic.find_by(id: params[:id])
|
2013-02-05 14:16:51 -05:00
|
|
|
guardian.ensure_can_delete!(topic)
|
2014-08-07 13:12:35 -04:00
|
|
|
|
|
|
|
first_post = topic.ordered_posts.first
|
|
|
|
PostDestroyer.new(current_user, first_post).destroy
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
render nothing: true
|
|
|
|
end
|
2013-02-07 10:45:24 -05:00
|
|
|
|
2013-07-12 12:08:23 -04:00
|
|
|
def recover
|
|
|
|
topic = Topic.where(id: params[:topic_id]).with_deleted.first
|
|
|
|
guardian.ensure_can_recover_topic!(topic)
|
2014-08-07 13:12:35 -04:00
|
|
|
|
|
|
|
first_post = topic.posts.with_deleted.order(:post_number).first
|
|
|
|
PostDestroyer.new(current_user, first_post).recover
|
|
|
|
|
2013-07-12 12:08:23 -04:00
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
def excerpt
|
2013-02-07 10:45:24 -05:00
|
|
|
render nothing: true
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-06-18 03:17:01 -04:00
|
|
|
def remove_allowed_user
|
|
|
|
params.require(:username)
|
2014-05-06 09:41:59 -04:00
|
|
|
topic = Topic.find_by(id: params[:topic_id])
|
2013-06-18 03:17:01 -04:00
|
|
|
guardian.ensure_can_remove_allowed_users!(topic)
|
|
|
|
|
|
|
|
if topic.remove_allowed_user(params[:username])
|
|
|
|
render json: success_json
|
|
|
|
else
|
|
|
|
render json: failed_json, status: 422
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
def invite
|
2013-10-28 02:12:07 -04:00
|
|
|
username_or_email = params[:user] ? fetch_username : fetch_email
|
2013-07-10 21:21:39 -04:00
|
|
|
|
2014-05-06 09:41:59 -04:00
|
|
|
topic = Topic.find_by(id: params[:topic_id])
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2014-05-09 04:22:15 -04:00
|
|
|
group_ids = Group.lookup_group_ids(params)
|
2014-05-08 21:45:18 -04:00
|
|
|
guardian.ensure_can_invite_to!(topic,group_ids)
|
|
|
|
|
|
|
|
if topic.invite(current_user, username_or_email, group_ids)
|
2013-07-10 21:21:39 -04:00
|
|
|
user = User.find_by_username_or_email(username_or_email)
|
2013-06-18 03:17:01 -04:00
|
|
|
if user
|
|
|
|
render_json_dump BasicUserSerializer.new(user, scope: guardian, root: 'user')
|
|
|
|
else
|
|
|
|
render json: success_json
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
else
|
|
|
|
render json: failed_json, status: 422
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_notifications
|
|
|
|
topic = Topic.find(params[:topic_id].to_i)
|
|
|
|
TopicUser.change(current_user, topic.id, notification_level: params[:notification_level].to_i)
|
|
|
|
render json: success_json
|
|
|
|
end
|
|
|
|
|
2013-05-16 15:55:14 -04:00
|
|
|
def merge_topic
|
2013-06-06 03:14:32 -04:00
|
|
|
params.require(:destination_topic_id)
|
2013-05-16 15:55:14 -04:00
|
|
|
|
2014-05-06 09:41:59 -04:00
|
|
|
topic = Topic.find_by(id: params[:topic_id])
|
2013-05-16 15:55:14 -04:00
|
|
|
guardian.ensure_can_move_posts!(topic)
|
|
|
|
|
|
|
|
dest_topic = topic.move_posts(current_user, topic.posts.pluck(:id), destination_topic_id: params[:destination_topic_id].to_i)
|
2013-06-18 01:52:09 -04:00
|
|
|
render_topic_changes(dest_topic)
|
2013-05-16 15:55:14 -04:00
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
def move_posts
|
2013-06-06 03:14:32 -04:00
|
|
|
params.require(:post_ids)
|
2013-10-29 15:30:06 -04:00
|
|
|
params.require(:topic_id)
|
|
|
|
params.permit(:category_id)
|
2013-05-08 13:33:58 -04:00
|
|
|
|
2014-05-06 09:41:59 -04:00
|
|
|
topic = Topic.find_by(id: params[:topic_id])
|
2013-02-05 14:16:51 -05:00
|
|
|
guardian.ensure_can_move_posts!(topic)
|
|
|
|
|
2013-09-04 11:53:00 -04:00
|
|
|
dest_topic = move_posts_to_destination(topic)
|
2013-06-18 01:52:09 -04:00
|
|
|
render_topic_changes(dest_topic)
|
2014-08-11 14:42:50 -04:00
|
|
|
rescue ActiveRecord::RecordInvalid => ex
|
|
|
|
render_json_error(ex)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2014-03-27 21:28:14 -04:00
|
|
|
def change_post_owners
|
|
|
|
params.require(:post_ids)
|
|
|
|
params.require(:topic_id)
|
|
|
|
params.require(:username)
|
|
|
|
|
|
|
|
guardian.ensure_can_change_post_owner!
|
|
|
|
|
|
|
|
topic = Topic.find(params[:topic_id].to_i)
|
|
|
|
new_user = User.find_by_username(params[:username])
|
|
|
|
ids = params[:post_ids].to_a
|
|
|
|
|
|
|
|
unless new_user && topic && ids
|
|
|
|
render json: failed_json, status: 422
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
ids.each do |id|
|
|
|
|
post = Post.find(id)
|
|
|
|
if post.is_first_post?
|
|
|
|
topic.user = new_user # Update topic owner (first avatar)
|
|
|
|
end
|
|
|
|
post.set_owner(new_user, current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
topic.update_statistics
|
|
|
|
|
|
|
|
render json: success_json
|
|
|
|
end
|
|
|
|
|
2013-03-06 15:17:07 -05:00
|
|
|
def clear_pin
|
2014-05-06 09:41:59 -04:00
|
|
|
topic = Topic.find_by(id: params[:topic_id].to_i)
|
2013-03-06 15:17:07 -05:00
|
|
|
guardian.ensure_can_see!(topic)
|
|
|
|
topic.clear_pin_for(current_user)
|
|
|
|
render nothing: true
|
|
|
|
end
|
2013-02-25 18:38:11 -05:00
|
|
|
|
2014-04-09 20:56:56 -04:00
|
|
|
def re_pin
|
2014-05-06 09:41:59 -04:00
|
|
|
topic = Topic.find_by(id: params[:topic_id].to_i)
|
2014-04-09 20:56:56 -04:00
|
|
|
guardian.ensure_can_see!(topic)
|
|
|
|
topic.re_pin_for(current_user)
|
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
2013-03-06 15:17:07 -05:00
|
|
|
def timings
|
2013-02-25 02:42:42 -05:00
|
|
|
PostTiming.process_timings(
|
2013-03-06 15:17:07 -05:00
|
|
|
current_user,
|
|
|
|
params[:topic_id].to_i,
|
|
|
|
params[:topic_time].to_i,
|
|
|
|
(params[:timings] || []).map{|post_number, t| [post_number.to_i, t.to_i]}
|
2013-02-25 02:42:42 -05:00
|
|
|
)
|
2013-02-05 14:16:51 -05:00
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
2013-02-21 13:20:00 -05:00
|
|
|
def feed
|
|
|
|
@topic_view = TopicView.new(params[:topic_id])
|
2013-10-16 01:39:18 -04:00
|
|
|
discourse_expires_in 1.minute
|
|
|
|
render 'topics/show', formats: [:rss]
|
2013-02-21 13:20:00 -05:00
|
|
|
end
|
|
|
|
|
2014-01-29 15:48:52 -05:00
|
|
|
def bulk
|
2014-02-21 14:17:45 -05:00
|
|
|
if params[:topic_ids].present?
|
|
|
|
topic_ids = params[:topic_ids].map {|t| t.to_i}
|
|
|
|
elsif params[:filter] == 'unread'
|
|
|
|
tq = TopicQuery.new(current_user)
|
|
|
|
topic_ids = TopicQuery.unread_filter(tq.joined_topic_user).listable_topics.pluck(:id)
|
|
|
|
else
|
|
|
|
raise ActionController::ParameterMissing.new(:topic_ids)
|
|
|
|
end
|
|
|
|
|
2014-01-30 11:15:49 -05:00
|
|
|
operation = params.require(:operation).symbolize_keys
|
|
|
|
raise ActionController::ParameterMissing.new(:operation_type) if operation[:type].blank?
|
|
|
|
operator = TopicsBulkAction.new(current_user, topic_ids, operation)
|
|
|
|
changed_topic_ids = operator.perform!
|
|
|
|
render_json_dump topic_ids: changed_topic_ids
|
2014-01-29 15:48:52 -05:00
|
|
|
end
|
|
|
|
|
2014-03-03 15:46:38 -05:00
|
|
|
def reset_new
|
|
|
|
current_user.user_stat.update_column(:new_since, Time.now)
|
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
private
|
|
|
|
|
2013-06-14 01:38:59 -04:00
|
|
|
def toggle_mute
|
2014-05-06 09:41:59 -04:00
|
|
|
@topic = Topic.find_by(id: params[:topic_id].to_i)
|
2013-02-10 13:50:26 -05:00
|
|
|
guardian.ensure_can_see!(@topic)
|
|
|
|
|
2013-05-24 02:06:38 -04:00
|
|
|
@topic.toggle_mute(current_user)
|
2013-02-10 13:50:26 -05:00
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
|
|
|
def consider_user_for_promotion
|
|
|
|
Promotion.new(current_user).review if current_user.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def slugs_do_not_match
|
|
|
|
params[:slug] && @topic_view.topic.slug != params[:slug]
|
|
|
|
end
|
|
|
|
|
2014-08-13 16:12:44 -04:00
|
|
|
def redirect_to_correct_topic(topic, post_number=nil)
|
|
|
|
url = topic.relative_url
|
2014-08-17 22:35:31 -04:00
|
|
|
url << "/#{post_number}" if post_number.to_i > 0
|
2014-08-13 16:12:44 -04:00
|
|
|
url << ".json" if request.format.json?
|
|
|
|
|
|
|
|
redirect_to url, status: 301
|
2013-02-10 13:50:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def track_visit_to_topic
|
2014-06-11 21:29:29 -04:00
|
|
|
topic_id = @topic_view.topic.id
|
|
|
|
ip = request.remote_ip
|
|
|
|
user_id = (current_user.id if current_user)
|
|
|
|
track_visit = should_track_visit_to_topic?
|
|
|
|
|
2014-08-03 21:06:06 -04:00
|
|
|
Scheduler::Defer.later "Track Link" do
|
|
|
|
IncomingLink.add(
|
|
|
|
referer: request.referer || flash[:referer],
|
|
|
|
host: request.host,
|
|
|
|
current_user: current_user,
|
|
|
|
topic_id: @topic_view.topic.id,
|
|
|
|
post_number: params[:post_number],
|
|
|
|
username: request['u'],
|
|
|
|
ip_address: request.remote_ip
|
|
|
|
)
|
|
|
|
end unless request.xhr?
|
|
|
|
|
2014-07-17 16:22:46 -04:00
|
|
|
Scheduler::Defer.later "Track Visit" do
|
2014-08-04 05:07:55 -04:00
|
|
|
TopicViewItem.add(topic_id, ip, user_id)
|
2014-06-11 21:29:29 -04:00
|
|
|
if track_visit
|
|
|
|
TopicUser.track_visit! topic_id, user_id
|
|
|
|
end
|
|
|
|
end
|
2013-10-04 03:00:23 -04:00
|
|
|
|
2013-02-10 13:50:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def should_track_visit_to_topic?
|
2013-10-04 04:06:32 -04:00
|
|
|
!!((!request.xhr? || params[:track_visit]) && current_user)
|
2013-02-10 13:50:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def perform_show_response
|
|
|
|
topic_view_serializer = TopicViewSerializer.new(@topic_view, scope: guardian, root: false)
|
2013-06-28 13:55:34 -04:00
|
|
|
|
2013-02-10 13:50:26 -05:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2014-05-07 11:21:37 -04:00
|
|
|
@description_meta = @topic_view.topic.excerpt
|
2013-02-10 13:50:26 -05:00
|
|
|
store_preloaded("topic_#{@topic_view.topic.id}", MultiJson.dump(topic_view_serializer))
|
|
|
|
end
|
|
|
|
|
|
|
|
format.json do
|
|
|
|
render_json_dump(topic_view_serializer)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-06-18 01:52:09 -04:00
|
|
|
|
|
|
|
def render_topic_changes(dest_topic)
|
|
|
|
if dest_topic.present?
|
|
|
|
render json: {success: true, url: dest_topic.relative_url}
|
|
|
|
else
|
|
|
|
render json: {success: false}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-04 11:53:00 -04:00
|
|
|
def move_posts_to_destination(topic)
|
2013-06-18 01:52:09 -04:00
|
|
|
args = {}
|
|
|
|
args[:title] = params[:title] if params[:title].present?
|
|
|
|
args[:destination_topic_id] = params[:destination_topic_id].to_i if params[:destination_topic_id].present?
|
2013-10-29 15:30:06 -04:00
|
|
|
args[:category_id] = params[:category_id].to_i if params[:category_id].present?
|
2013-06-18 01:52:09 -04:00
|
|
|
|
2013-09-04 11:53:00 -04:00
|
|
|
topic.move_posts(current_user, post_ids_including_replies, args)
|
2013-06-18 01:52:09 -04:00
|
|
|
end
|
|
|
|
|
2013-10-28 02:12:07 -04:00
|
|
|
def check_length_of(key, attr)
|
|
|
|
str = (key == :raw) ? "body" : key.to_s
|
|
|
|
invalid_param(key) if attr.length < SiteSetting.send("min_#{str}_similar_length")
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_for_status_presence(key, attr)
|
2014-04-07 02:38:51 -04:00
|
|
|
invalid_param(key) unless %w(pinned_globally visible closed pinned archived).include?(attr)
|
2013-10-28 02:12:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def invalid_param(key)
|
|
|
|
raise Discourse::InvalidParameters.new(key.to_sym)
|
|
|
|
end
|
|
|
|
|
|
|
|
def fetch_username
|
|
|
|
params.require(:user)
|
|
|
|
params[:user]
|
|
|
|
end
|
|
|
|
|
|
|
|
def fetch_email
|
|
|
|
params.require(:email)
|
|
|
|
params[:email]
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|