1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-31 19:45:45 +00:00

Added logic to delegate tournament access

This commit is contained in:
2016-01-06 18:38:02 +00:00
parent eb9037b078
commit f46029efaf
46 changed files with 417 additions and 121 deletions

View File

@@ -1,5 +0,0 @@
class AdminController < ApplicationController
def index
end
end

View File

@@ -3,4 +3,8 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
rescue_from CanCan::AccessDenied do |exception|
# flash[:error] = "Access denied!"
redirect_to '/static_pages/not_allowed'
end
end

View File

@@ -49,8 +49,6 @@ class MatchesController < ApplicationController
end
def check_access
if current_user != @match.tournament.user
redirect_to '/static_pages/not_allowed'
end
authorize! :manage, @match.tournament
end
end

View File

@@ -89,9 +89,7 @@ class MatsController < ApplicationController
elsif @mat
@tournament = @mat.tournament
end
if current_user != @tournament.user
redirect_to '/static_pages/not_allowed'
end
authorize! :manage, @tournament
end

View File

@@ -84,9 +84,7 @@ class SchoolsController < ApplicationController
elsif @school
@tournament = @school.tournament
end
if current_user != @tournament.user
redirect_to '/static_pages/not_allowed'
end
authorize! :manage, @tournament
end
end

View File

@@ -1,7 +1,10 @@
class StaticPagesController < ApplicationController
def my_tournaments
@tournaments = current_user.tournaments.sort_by{|t| t.daysUntil}
tournaments_created = current_user.tournaments
tournaments_delegated = current_user.delegated_tournaments
all_tournaments = tournaments_created + tournaments_delegated
@tournaments = all_tournaments.sort_by{|t| t.daysUntil}
end
def not_allowed

View File

@@ -1,6 +1,8 @@
class TournamentsController < ApplicationController
before_action :set_tournament, only: [:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets]
before_filter :check_access, only: [:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:destroy,:generate_matches,:matches]
before_filter :check_access_manage, only: [:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches]
before_filter :check_access_destroy, only: [:destroy]
before_filter :check_for_matches, only: [:up_matches,:bracket,:all_brackets]
def matches
@@ -149,10 +151,12 @@ class TournamentsController < ApplicationController
end
#Check for tournament owner
def check_access
if current_user != @tournament.user
redirect_to '/static_pages/not_allowed'
end
def check_access_destroy
authorize! :destroy, @tournament
end
def check_access_manage
authorize! :manage, @tournament
end
def check_for_matches

View File

@@ -63,9 +63,6 @@ class WeightsController < ApplicationController
# DELETE /weights/1.json
def destroy
@tournament = Tournament.find(@weight.tournament_id)
if current_user != @tournament.user
redirect_to root_path
end
@weight.destroy
respond_to do |format|
format.html { redirect_to @tournament }
@@ -91,9 +88,7 @@ class WeightsController < ApplicationController
elsif @weight
@tournament = @weight.tournament
end
if current_user != @tournament.user
redirect_to '/static_pages/not_allowed'
end
authorize! :manage, @tournament
end

View File

@@ -99,8 +99,6 @@ class WrestlersController < ApplicationController
elsif @wrestler
@tournament = @wrestler.tournament
end
if current_user != @tournament.user
redirect_to '/static_pages/not_allowed'
end
authorize! :manage, @tournament
end
end