掲示板実装
This commit is contained in:
71
app/controllers/board_proposals_controller.rb
Normal file
71
app/controllers/board_proposals_controller.rb
Normal file
@@ -0,0 +1,71 @@
|
||||
class BoardProposalsController < ApplicationController
|
||||
before_action :require_login
|
||||
before_action :set_game
|
||||
before_action :set_board
|
||||
before_action :set_current_participant
|
||||
|
||||
def create
|
||||
unless @board.member?(@current_participant)
|
||||
return redirect_to game_board_path(@game, @board), alert: "権限がありません"
|
||||
end
|
||||
|
||||
@proposal = @board.board_proposals.new(proposal_params)
|
||||
@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
|
||||
|
||||
if @proposal.save
|
||||
redirect_to game_board_path(@game, @board), notice: "提案を作成しました"
|
||||
else
|
||||
redirect_to game_board_path(@game, @board), alert: "提案の作成に失敗しました"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@proposal = @board.board_proposals.find(params[:id])
|
||||
|
||||
# 承認・拒否権限:
|
||||
# 提案者本人以外が承認/拒否できるべきか、あるいは全員できるべきか?
|
||||
# 通常は「相手」が承認するものだが、多国間の場合は?
|
||||
# ここでは「メンバーであれば誰でもステータス変更可能」とする(簡易実装)
|
||||
# ただし、提案者本人が自分で承認するのは変なので、他者のみとするのがベター
|
||||
|
||||
unless @board.member?(@current_participant)
|
||||
return redirect_to game_board_path(@game, @board), alert: "権限がありません"
|
||||
end
|
||||
|
||||
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: "不正なステータスです"
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
Reference in New Issue
Block a user