diff options
Diffstat (limited to 'app/controllers/tournaments_controller.rb')
-rw-r--r-- | app/controllers/tournaments_controller.rb | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index cc25033..d1a926b 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -1,6 +1,4 @@ class TournamentsController < ApplicationController - before_action :set_tournament, only: [:show, :edit, :update, :destroy, :join] - before_action :check_perms, only: [:new, :create, :edit, :destroy] # GET /tournaments # GET /tournaments.json @@ -36,7 +34,7 @@ class TournamentsController < ApplicationController # GET /tournaments/1/edit def edit - + check_permission(:edit, @tournament) end # POST /tournaments @@ -61,7 +59,7 @@ class TournamentsController < ApplicationController def update case params[:update_action] when nil - check_perms + check_permission(:edit, @tournament) respond_to do |format| if @tournament.update(tournament_params) format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' } @@ -72,6 +70,7 @@ class TournamentsController < ApplicationController end end when "join" + check_permission(:join) respond_to do |format| if @tournament.join(current_user) format.html { redirect_to @tournament, notice: 'You have joined this tournament.' } @@ -90,6 +89,7 @@ class TournamentsController < ApplicationController format.json { render json: "Permission denied", status: :forbidden } end when "start" + check_permission(:edit, @tournament) @tournament.status = 1 @tournament.save respond_to do |format| @@ -124,17 +124,16 @@ class TournamentsController < ApplicationController @tournament = Tournament.find(params[:id]) end - def check_perms - unless (signed_in? and current_user.in_group?(:host)) - respond_to do |format| - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } - end - end - end - # Never trust parameters from the scary internet, only allow the white list through. def tournament_params params.require(:tournament).permit(:game, :name, :game_id, :status, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams) end + + def is_owner?(object) + object.hosts.include?(current_user) + end + + # Turn of check_edit, since our #update is flexible + def check_edit + end end |