FEATURE: move a topic from PM to regular topic or vice versa

This commit is contained in:
Arpit Jalan
2016-05-01 17:18:43 +05:30
parent e2928f78d2
commit acfb540952
13 changed files with 280 additions and 3 deletions

View File

@ -27,6 +27,7 @@ class TopicsController < ApplicationController
:change_timestamps,
:archive_message,
:move_to_inbox,
:convert_topic,
:bookmark]
before_filter :consider_user_for_promotion, only: :show
@ -510,6 +511,22 @@ class TopicsController < ApplicationController
render nothing: true
end
def convert_topic
params.require(:id)
params.require(:type)
topic = Topic.find_by(id: params[:id])
guardian.ensure_can_convert_topic!(topic)
if params[:type] == "public"
converted_topic = topic.convert_to_public_topic(current_user)
else
converted_topic = topic.convert_to_private_message(current_user)
end
render_topic_changes(converted_topic)
rescue ActiveRecord::RecordInvalid => ex
render_json_error(ex)
end
private
def toggle_mute