refactor: BoardAccessible concernを導入し、ボード関連コントローラを整理、ターン表示ロジックをTurnモデルへ移動し、ボード提案表示をコントローラで処理するよう変更
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
class BoardProposalsController < ApplicationController
|
||||
include BoardAccessible
|
||||
|
||||
before_action :require_login
|
||||
before_action :set_game
|
||||
before_action :set_board
|
||||
@@ -13,13 +15,9 @@ class BoardProposalsController < ApplicationController
|
||||
@proposal.proposer = @current_participant
|
||||
@proposal.status = "pending"
|
||||
|
||||
# フェーズ情報の保存
|
||||
latest_turn = @game.turns.max_by(&:number)
|
||||
if latest_turn
|
||||
@proposal.phase = latest_turn.phase
|
||||
else
|
||||
@proposal.phase = "S1901M" # 初期値
|
||||
end
|
||||
# フェーズ情報の保存(latest_turnアソシエーションを使用)
|
||||
latest_turn = @game.latest_turn
|
||||
@proposal.phase = latest_turn&.phase || "S1901M"
|
||||
|
||||
if @proposal.save
|
||||
redirect_to game_board_path(@game, @board), notice: "提案を作成しました"
|
||||
@@ -31,12 +29,6 @@ class BoardProposalsController < ApplicationController
|
||||
def update
|
||||
@proposal = @board.board_proposals.find(params[:id])
|
||||
|
||||
# 承認・拒否権限:
|
||||
# 提案者本人以外が承認/拒否できるべきか、あるいは全員できるべきか?
|
||||
# 通常は「相手」が承認するものだが、多国間の場合は?
|
||||
# ここでは「メンバーであれば誰でもステータス変更可能」とする(簡易実装)
|
||||
# ただし、提案者本人が自分で承認するのは変なので、他者のみとするのがベター
|
||||
|
||||
unless @board.member?(@current_participant)
|
||||
return redirect_to game_board_path(@game, @board), alert: "権限がありません"
|
||||
end
|
||||
@@ -44,7 +36,6 @@ class BoardProposalsController < ApplicationController
|
||||
new_status = params[:board_proposal][:status]
|
||||
if %w[accepted rejected].include?(new_status)
|
||||
@proposal.update!(status: new_status)
|
||||
# ログにも残す(投稿として自動投稿しても良いが、今回はステータス変更のみ)
|
||||
redirect_to game_board_path(@game, @board), notice: "提案を#{new_status == 'accepted' ? '承認' : '拒否'}しました"
|
||||
else
|
||||
redirect_to game_board_path(@game, @board), alert: "不正なステータスです"
|
||||
@@ -53,18 +44,6 @@ class BoardProposalsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def set_game
|
||||
@game = Game.find(params[:game_id])
|
||||
end
|
||||
|
||||
def set_board
|
||||
@board = @game.boards.find(params[:board_id])
|
||||
end
|
||||
|
||||
def set_current_participant
|
||||
@current_participant = @game.participants.find_by(user: current_user)
|
||||
end
|
||||
|
||||
def proposal_params
|
||||
params.require(:board_proposal).permit(:body)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user