mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-31 19:45:45 +00:00
Added is_public to a tournament to hide lineups and brackets until you're ready to make it public
This commit is contained in:
@@ -2,7 +2,7 @@ class SchoolsController < ApplicationController
|
||||
before_action :set_school, only: [:import_baumspage_roster, :show, :edit, :update, :destroy, :stats]
|
||||
before_action :check_access_director, only: [:new,:create,:destroy]
|
||||
before_action :check_access_delegate, only: [:import_baumspage_roster, :update,:edit]
|
||||
|
||||
before_action :check_read_access, only: [:show]
|
||||
|
||||
def stats
|
||||
@tournament = @school.tournament
|
||||
@@ -108,5 +108,9 @@ class SchoolsController < ApplicationController
|
||||
def check_access_delegate
|
||||
authorize! :manage, @school
|
||||
end
|
||||
|
||||
def check_read_access
|
||||
authorize! :read, @school
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -4,6 +4,7 @@ class TournamentsController < ApplicationController
|
||||
before_action :check_access_destroy, only: [:destroy,:delegate,:remove_delegate]
|
||||
before_action :check_tournament_errors, only: [:generate_matches]
|
||||
before_action :check_for_matches, only: [:up_matches,:bracket,:all_brackets]
|
||||
before_action :check_access_read, only: [:up_matches,:bracket,:all_brackets]
|
||||
|
||||
def weigh_in_sheet
|
||||
|
||||
@@ -289,7 +290,7 @@ class TournamentsController < ApplicationController
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def tournament_params
|
||||
params.require(:tournament).permit(:name, :address, :director, :director_email, :tournament_type, :weigh_in_ref, :user_id, :date, :originalId, :swapId)
|
||||
params.require(:tournament).permit(:name, :address, :director, :director_email, :tournament_type, :weigh_in_ref, :user_id, :date, :originalId, :swapId, :is_public)
|
||||
end
|
||||
|
||||
#Check for tournament owner
|
||||
@@ -301,6 +302,10 @@ class TournamentsController < ApplicationController
|
||||
authorize! :manage, @tournament
|
||||
end
|
||||
|
||||
def check_access_read
|
||||
authorize! :read, @tournament
|
||||
end
|
||||
|
||||
def check_for_matches
|
||||
if @tournament
|
||||
if @tournament.matches.empty? or @tournament.curently_generating_matches == 1
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class WeightsController < ApplicationController
|
||||
before_action :set_weight, only: [:pool_order, :show, :edit, :update, :destroy,:re_gen]
|
||||
before_action :check_access, only: [:pool_order, :new,:create,:update,:destroy,:edit, :re_gen]
|
||||
before_action :check_access_manage, only: [:pool_order, :new,:create,:update,:destroy,:edit, :re_gen]
|
||||
before_action :check_access_read, only: [:show]
|
||||
|
||||
|
||||
# GET /weights/1
|
||||
@@ -103,7 +104,7 @@ class WeightsController < ApplicationController
|
||||
def weight_params
|
||||
params.require(:weight).permit(:max, :tournament_id, :mat_id)
|
||||
end
|
||||
def check_access
|
||||
def check_access_manage
|
||||
if params[:tournament]
|
||||
@tournament = Tournament.find(params[:tournament])
|
||||
elsif params[:weight]
|
||||
@@ -114,5 +115,16 @@ class WeightsController < ApplicationController
|
||||
authorize! :manage, @tournament
|
||||
end
|
||||
|
||||
def check_access_read
|
||||
if params[:tournament]
|
||||
@tournament = Tournament.find(params[:tournament])
|
||||
elsif params[:weight]
|
||||
@tournament = Tournament.find(params[:weight]["tournament_id"])
|
||||
elsif @weight
|
||||
@tournament = @weight.tournament
|
||||
end
|
||||
authorize! :read, @tournament
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -38,6 +38,16 @@ class Ability
|
||||
cannot :destroy, Tournament do |tournament|
|
||||
tournament.delegates.map(&:user_id).include? user.id
|
||||
end
|
||||
# Can read tournament if tournament owner or tournament delegate
|
||||
can :read, Tournament do |tournament|
|
||||
if tournament.is_public
|
||||
true
|
||||
elsif tournament.delegates.map(&:user_id).include? user.id or tournament.user_id == user.id
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
#Can manage school if tournament owner
|
||||
can :manage, School do |school|
|
||||
school.tournament.user_id == user.id
|
||||
@@ -53,6 +63,34 @@ class Ability
|
||||
cannot :destroy, School do |school|
|
||||
school.delegates.map(&:user_id).include? user.id
|
||||
end
|
||||
# Can read school if school delegate, tournament delegate, or tournament director
|
||||
can :read, School do |school|
|
||||
if school.tournament.is_public
|
||||
true
|
||||
elsif school.delegates.map(&:user_id).include? user.id or school.tournament.delegates.map(&:user_id).include? user.id or school.tournament.user_id == user.id
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
# Default for non logged in users
|
||||
else
|
||||
# Can read tournament if tournament is public
|
||||
can :read, Tournament do |tournament|
|
||||
if tournament.is_public
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
# Can read school if tournament is public
|
||||
can :read, School do |school|
|
||||
if school.tournament.is_public
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,6 +43,15 @@
|
||||
<%= f.hidden_field :user_id, :value => current_user.id %>
|
||||
<br>
|
||||
<br>
|
||||
<div class="field">
|
||||
<%= f.label "Information is public" %> <br />
|
||||
<%= f.check_box :is_public %> <br />
|
||||
</div>
|
||||
<div>
|
||||
Leave this unchecked until you're ready to share seeding info, brackets, and lineups.
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
<div class="actions">
|
||||
<%= f.submit 'Submit',:class=>"btn btn-success" %>
|
||||
</div>
|
||||
|
||||
@@ -17,6 +17,14 @@
|
||||
<strong>Tournament Type:</strong>
|
||||
<%= @tournament.tournament_type %>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Tournament Date:</strong>
|
||||
<%= @tournament.date %>
|
||||
</p>
|
||||
<p>
|
||||
<strong>Tournament Information Is Public:</strong>
|
||||
<%= @tournament.is_public %>
|
||||
</p>
|
||||
<p>Brackets and team scores can be found in the white nav-bar up top.</p>
|
||||
<br>
|
||||
<h3>Schools</h3>
|
||||
@@ -32,15 +40,20 @@
|
||||
<tbody>
|
||||
<% @schools.each do |school| %>
|
||||
<tr>
|
||||
<td><%= link_to "#{school.name}", school %>
|
||||
<td>
|
||||
<% if can? :read, school %>
|
||||
<%= link_to "#{school.name}", school %>
|
||||
<% else %>
|
||||
<%= "#{school.name}" %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% if can? :manage, school %>
|
||||
<td><%= link_to '', edit_school_path(school), :class=>"fas fa-edit" %>
|
||||
<%= link_to '', edit_school_path(school), :class=>"fas fa-edit" %>
|
||||
<% if can? :manage, @tournament %>
|
||||
<%= link_to '', school, method: :delete, data: { confirm: "Are you sure you want to delete #{school.name}?" }, :class=>"fas fa-trash-alt" %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
@@ -61,7 +74,13 @@
|
||||
<tbody>
|
||||
<% @weights.each do |weight| %>
|
||||
<tr>
|
||||
<td><%= link_to "#{weight.max} lbs", weight %></td>
|
||||
<td>
|
||||
<% if can? :read, @tournament %>
|
||||
<%= link_to "#{weight.max} lbs", weight %>
|
||||
<% else %>
|
||||
<%= "#{weight.max}" %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= weight.bracket_size %></td>
|
||||
<% if can? :manage, @tournament %>
|
||||
<td>
|
||||
|
||||
Reference in New Issue
Block a user