refactor: BoardAccessible concernを導入し、ボード関連コントローラを整理、ターン表示ロジックをTurnモデルへ移動し、ボード提案表示をコントローラで処理するよう変更
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
class BoardsController < ApplicationController
|
||||
include BoardAccessible
|
||||
|
||||
before_action :require_login
|
||||
before_action :set_game
|
||||
before_action :set_board, only: [ :show, :toggle_public ]
|
||||
@@ -14,21 +16,19 @@ class BoardsController < ApplicationController
|
||||
|
||||
if @game.status == "finished"
|
||||
# 履歴モード:かつて参加していた掲示板をすべて表示
|
||||
# (共通掲示板は全員参加扱いなので含む)
|
||||
@boards = @game.boards.select { |b| b.member?(@current_participant) || b.global? }
|
||||
@boards = @game.boards.includes(:participants, :board_posts, :board_memberships)
|
||||
.select { |b| b.member?(@current_participant) || b.global? }
|
||||
.sort_by { |b| [ b.global? ? 0 : 1, b.created_at ] }
|
||||
else
|
||||
return redirect_to game_path(@game), alert: "参加者ではないためアクセスできません" unless @current_participant
|
||||
|
||||
# 進行中:参加中の掲示板のみ
|
||||
@boards = @current_participant.boards.includes(:participants, :board_posts).order(created_at: :desc)
|
||||
# 共通掲示板がまだ紐付いていない場合のフォールバック(通常は作成時に紐づくはずだが念の為)
|
||||
# 進行中:参加中の掲示板のみ(eager load で N+1 防止)
|
||||
@boards = @current_participant.boards.includes(:participants, :board_posts, :board_memberships).order(created_at: :desc)
|
||||
# 共通掲示板のフォールバック
|
||||
global_board = @game.boards.global.first
|
||||
if global_board && !@boards.include?(global_board)
|
||||
# 表示上追加するが、DBには保存しない(閲覧時に参加処理をする作りも考えられるが、createタイミングで保証する前提)
|
||||
@boards = [ global_board ] + @boards
|
||||
end
|
||||
# 先頭に共通掲示板を持ってくる
|
||||
@boards = @boards.sort_by { |b| b.global? ? 0 : 1 }
|
||||
end
|
||||
end
|
||||
@@ -36,7 +36,6 @@ class BoardsController < ApplicationController
|
||||
def show
|
||||
@current_participant = @game.participants.find_by(user: current_user)
|
||||
|
||||
# アクセス制御
|
||||
# アクセス制御
|
||||
access_allowed = false
|
||||
|
||||
@@ -72,11 +71,12 @@ class BoardsController < ApplicationController
|
||||
end
|
||||
|
||||
@posts = @board.board_posts.includes(:participant).order(created_at: :desc)
|
||||
@proposals = @board.board_proposals.includes(:proposer).order(created_at: :desc)
|
||||
@new_post = BoardPost.new
|
||||
@new_proposal = BoardProposal.new
|
||||
@active_members = @board.active_memberships.includes(:participant).map(&:participant)
|
||||
|
||||
# メンバー追加用:招待可能なプレイヤー一覧(自分と既に参加している人を除く)
|
||||
# メンバー追加用:招待可能なプレイヤー一覧
|
||||
if @board.negotiation? && !@board.history_mode?
|
||||
existing_member_ids = @board.board_memberships.where(left_at: nil).pluck(:participant_id)
|
||||
@candidates = @game.participants.where.not(id: existing_member_ids).where.not(power: nil)
|
||||
@@ -135,35 +135,17 @@ class BoardsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def set_game
|
||||
@game = Game.find(params[:game_id])
|
||||
end
|
||||
|
||||
def set_board
|
||||
@board = @game.boards.find(params[:id])
|
||||
end
|
||||
|
||||
def board_params
|
||||
# パラメータは特にないが、将来的にタイトルなど追加するかも
|
||||
params.fetch(:board, {}).permit(:is_public)
|
||||
end
|
||||
|
||||
def build_diplomacy_matrix
|
||||
# 外交関係マップ構築
|
||||
# Matrix: { "FRANCE" => { "GERMANY" => true, "ENGLAND" => false }, ... }
|
||||
# 全組み合わせの初期化
|
||||
powers = @game.participants.where.not(power: nil).pluck(:power)
|
||||
matrix = {}
|
||||
powers.each { |p| matrix[p] = [] }
|
||||
|
||||
# 参加中の全掲示板を走査(自分が参加していないものも含めたいが、
|
||||
# DB設計上 board_memberships を見る必要がある)
|
||||
# is_publicなもの、または自分が参加しているものについて情報を開示?
|
||||
# 仕様書には「どの国とどの国が掲示板を持っているか」とあるが、
|
||||
# 秘密交渉なので、本来は「自分が見えている範囲」あるいは「公開宣言されたもの」のみ?
|
||||
# ここでは「自分が参加している掲示板」および「公開された掲示板」の関係を表示する。
|
||||
|
||||
visible_boards = @game.boards.negotiation.includes(:participants)
|
||||
# 自分が参加している掲示板・公開された掲示板の関係を表示
|
||||
visible_boards = @game.boards.negotiation.includes(:participants, :board_memberships)
|
||||
|
||||
visible_boards.each do |board|
|
||||
# アクセス権チェック(簡易)
|
||||
|
||||
Reference in New Issue
Block a user