DEV: removes dead code (#24345)
This commit is contained in:
parent
208491fa00
commit
7f3f682f67
|
@ -2,22 +2,13 @@
|
|||
|
||||
module Chat
|
||||
class ChatController < ::Chat::BaseController
|
||||
PAST_MESSAGE_LIMIT = 40
|
||||
FUTURE_MESSAGE_LIMIT = 40
|
||||
PAST = "past"
|
||||
FUTURE = "future"
|
||||
CHAT_DIRECTIONS = [PAST, FUTURE]
|
||||
|
||||
# Other endpoints use set_channel_and_chatable_with_access_check, but
|
||||
# these endpoints require a standalone find because they need to be
|
||||
# able to get deleted channels and recover them.
|
||||
before_action :find_chatable, only: %i[enable_chat disable_chat]
|
||||
before_action :find_chat_message, only: %i[rebake message_link]
|
||||
before_action :set_channel_and_chatable_with_access_check,
|
||||
except: %i[
|
||||
respond
|
||||
enable_chat
|
||||
disable_chat
|
||||
message_link
|
||||
set_user_chat_status
|
||||
dismiss_retention_reminder
|
||||
|
@ -28,55 +19,6 @@ module Chat
|
|||
render
|
||||
end
|
||||
|
||||
def enable_chat
|
||||
chat_channel = Chat::Channel.with_deleted.find_by(chatable_id: @chatable)
|
||||
|
||||
guardian.ensure_can_join_chat_channel!(chat_channel) if chat_channel
|
||||
|
||||
if chat_channel && chat_channel.trashed?
|
||||
chat_channel.recover!
|
||||
elsif chat_channel
|
||||
return render_json_error I18n.t("chat.already_enabled")
|
||||
else
|
||||
chat_channel = @chatable.chat_channel
|
||||
guardian.ensure_can_join_chat_channel!(chat_channel)
|
||||
end
|
||||
|
||||
success = chat_channel.save
|
||||
if success && chat_channel.chatable_has_custom_fields?
|
||||
@chatable.custom_fields[Chat::HAS_CHAT_ENABLED] = true
|
||||
@chatable.save!
|
||||
end
|
||||
|
||||
if success
|
||||
membership = Chat::ChannelMembershipManager.new(channel).follow(user)
|
||||
render_serialized(chat_channel, Chat::ChannelSerializer, membership: membership)
|
||||
else
|
||||
render_json_error(chat_channel)
|
||||
end
|
||||
|
||||
Chat::ChannelMembershipManager.new(channel).follow(user)
|
||||
end
|
||||
|
||||
def disable_chat
|
||||
chat_channel = Chat::Channel.with_deleted.find_by(chatable_id: @chatable)
|
||||
guardian.ensure_can_join_chat_channel!(chat_channel)
|
||||
return render json: success_json if chat_channel.trashed?
|
||||
chat_channel.trash!(current_user)
|
||||
|
||||
success = chat_channel.save
|
||||
if success
|
||||
if chat_channel.chatable_has_custom_fields?
|
||||
@chatable.custom_fields.delete(Chat::HAS_CHAT_ENABLED)
|
||||
@chatable.save!
|
||||
end
|
||||
|
||||
render json: success_json
|
||||
else
|
||||
render_json_error(chat_channel)
|
||||
end
|
||||
end
|
||||
|
||||
def react
|
||||
params.require(%i[message_id emoji react_action])
|
||||
guardian.ensure_can_react!
|
||||
|
@ -209,11 +151,6 @@ module Chat
|
|||
query
|
||||
end
|
||||
|
||||
def find_chatable
|
||||
@chatable = Category.find_by(id: params[:chatable_id])
|
||||
guardian.ensure_can_moderate_chat!(@chatable)
|
||||
end
|
||||
|
||||
def find_chat_message
|
||||
@message = preloaded_chat_message_query.with_deleted
|
||||
@message = @message.where(chat_channel_id: params[:chat_channel_id]) if params[
|
||||
|
|
|
@ -71,8 +71,6 @@ Chat::Engine.routes.draw do
|
|||
get "/browse/closed" => "chat#respond"
|
||||
get "/browse/open" => "chat#respond"
|
||||
get "/browse/archived" => "chat#respond"
|
||||
post "/enable" => "chat#enable_chat"
|
||||
post "/disable" => "chat#disable_chat"
|
||||
post "/dismiss-retention-reminder" => "chat#dismiss_retention_reminder"
|
||||
get "/message/:message_id" => "chat#message_link"
|
||||
put ":chat_channel_id/react/:message_id" => "chat#react"
|
||||
|
|
|
@ -32,43 +32,6 @@ RSpec.describe Chat::ChatController do
|
|||
Chat::ReviewQueue.new.flag_message(message, Guardian.new(flagger), flag_type)[:reviewable]
|
||||
end
|
||||
|
||||
describe "#enable_chat" do
|
||||
context "with category as chatable" do
|
||||
let!(:category) { Fabricate(:category) }
|
||||
let(:channel) { Fabricate(:category_channel, chatable: category) }
|
||||
|
||||
it "ensures created channel can be seen" do
|
||||
Guardian.any_instance.expects(:can_join_chat_channel?).with(channel)
|
||||
|
||||
sign_in(admin)
|
||||
post "/chat/enable.json", params: { chatable_type: "Category", chatable_id: category.id }
|
||||
end
|
||||
|
||||
# TODO: rewrite specs to ensure no exception is raised
|
||||
it "ensures existing channel can be seen" do
|
||||
Guardian.any_instance.expects(:can_join_chat_channel?)
|
||||
|
||||
sign_in(admin)
|
||||
post "/chat/enable.json", params: { chatable_type: "Category", chatable_id: category.id }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#disable_chat" do
|
||||
context "with category as chatable" do
|
||||
it "ensures category can be seen" do
|
||||
category = Fabricate(:category)
|
||||
channel = Fabricate(:category_channel, chatable: category)
|
||||
message = Fabricate(:chat_message, chat_channel: channel)
|
||||
|
||||
Guardian.any_instance.expects(:can_join_chat_channel?).with(channel)
|
||||
|
||||
sign_in(admin)
|
||||
post "/chat/disable.json", params: { chatable_type: "Category", chatable_id: category.id }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#rebake" do
|
||||
fab!(:chat_message) { Fabricate(:chat_message, chat_channel: chat_channel, user: user) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue