refactor: BoardAccessible concernを導入し、ボード関連コントローラを整理、ターン表示ロジックをTurnモデルへ移動し、ボード提案表示をコントローラで処理するよう変更
This commit is contained in:
@@ -1,34 +1,28 @@
|
||||
class BoardChannel < ApplicationCable::Channel
|
||||
def subscribed
|
||||
board = Board.find_by(id: params[:board_id])
|
||||
|
||||
unless board
|
||||
reject
|
||||
return
|
||||
end
|
||||
|
||||
# 権限チェック
|
||||
# ゲーム参加者を取得(current_userから)
|
||||
current_participant = board.game.participants.find_by(user: current_user)
|
||||
|
||||
# 参加権限があるか(メンバー、または終了済み、または公開ボード)
|
||||
# コントローラの判定ロジックと合わせる
|
||||
# 共通掲示板は誰でも購読OK(ただしゲーム参加者に限る)
|
||||
# ゲーム参加者でなければ一律拒否
|
||||
unless current_participant
|
||||
reject
|
||||
return
|
||||
end
|
||||
|
||||
if board.global?
|
||||
stream_from "board_#{board.id}" if current_participant
|
||||
elsif board.is_public?
|
||||
stream_from "board_#{board.id}" if current_participant
|
||||
elsif board.member?(current_participant)
|
||||
# 権限判定:共通掲示板/公開掲示板/メンバー/履歴モードのいずれかで許可
|
||||
if board.global? || board.is_public? || board.member?(current_participant) || board.history_mode?
|
||||
stream_from "board_#{board.id}"
|
||||
elsif board.history_mode?
|
||||
stream_from "board_#{board.id}" if current_participant
|
||||
else
|
||||
reject
|
||||
end
|
||||
end
|
||||
|
||||
def unsubscribed
|
||||
# Any cleanup needed when channel is unsubscribed
|
||||
# cleanup
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user