diff --git a/app/controllers/match_proposals_controller.rb b/app/controllers/match_proposals_controller.rb index 8d02ece..687124b 100644 --- a/app/controllers/match_proposals_controller.rb +++ b/app/controllers/match_proposals_controller.rb @@ -1,26 +1,24 @@ class MatchProposalsController < ApplicationController - + before_filter :get_match def index - @match = Match.find(params[:match_id]) end def new - match = Match.find(params[:match_id]) - @proposal = MatchProposal.new(match: match) + @proposal = MatchProposal.new + @proposal.match = @match raise AccessError unless @proposal.can_create? cuser end def create - match = Match.find(params[:match_id]) - @proposal = MatchProposal.new(match: match) - raise AccessError unless @ban.can_create? cuser + @proposal = MatchProposal.new(params[:match_proposal]) + @proposal.match = @match + raise AccessError unless @proposal.can_create? cuser @proposal.team = cuser.team @proposal.status = MatchProposal::STATUS_PENDING - @proposal.proposed_time = params[:match_proposal][:proposed_time] - if @proposal.save + if @proposal.save! flash[:notice] = 'Created new proposal' - redirect_to(match) + redirect_to(@match) else render :new end @@ -29,4 +27,8 @@ class MatchProposalsController < ApplicationController def update end +private + def get_match + @match = Match.find params[:match_id] + end end diff --git a/app/models/match.rb b/app/models/match.rb index 82495a0..5a547e4 100755 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -358,4 +358,8 @@ class Match < ActiveRecord::Base def can_destroy?(cuser) cuser && cuser.admin? end + + def can_make_proposal?(cuser) + cuser && (contester1.team.is_leader?(cuser) || contester2.team.is_leader?(cuser)) + end end diff --git a/app/models/match_proposal.rb b/app/models/match_proposal.rb index 56c3412..44e1a42 100644 --- a/app/models/match_proposal.rb +++ b/app/models/match_proposal.rb @@ -19,11 +19,11 @@ class MatchProposal < ActiveRecord::Base end def can_create? cuser - cuser && cuser.team.is_leader?(cuser) && match.of_team(cuser.team) + cuser && match && match.can_make_proposal?(cuser) end def can_update? cuser - cuser && cuser.team.is_leader?(cuser) && match.of_team (cuser.team) + cuser && match && match.can_make_proposal?(cuser) end def can_destroy? diff --git a/app/views/match_proposals/index.html.erb b/app/views/match_proposals/index.html.erb index d89fe99..83950dd 100644 --- a/app/views/match_proposals/index.html.erb +++ b/app/views/match_proposals/index.html.erb @@ -3,7 +3,6 @@ <% if @match.match_proposals.empty? %>
Team | @@ -20,5 +19,5 @@
---|