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:
@@ -1,5 +0,0 @@
|
||||
class AdminController < ApplicationController
|
||||
def index
|
||||
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user