From 70bae69d731afc5300ffa5b176732ebe27d0810f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 6 Mar 2014 22:26:37 -0500 Subject: add self as a host to a tourney upon creation --- app/controllers/tournaments_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 74a1f56..1e26584 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -31,9 +31,9 @@ class TournamentsController < ApplicationController # POST /tournaments.json def create @tournament = Tournament.new(tournament_params) - respond_to do |format| if @tournament.save + @tournament.hosts.push(current_user) format.html { redirect_to @tournament, notice: 'Tournament was successfully created.' } format.json { render action: 'show', status: :created, location: @tournament } else -- cgit v1.2.3-2-g168b From ce8b05ed8fa3466c727269daa47ba7df672fdca1 Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Thu, 6 Mar 2014 22:31:03 -0500 Subject: Redirection works as does the close tournament button. --- app/controllers/tournaments_controller.rb | 11 +++++++++-- app/models/user.rb | 2 +- app/views/tournaments/show.html.erb | 12 ++++++++++-- stop.sh | 0 4 files changed, 20 insertions(+), 5 deletions(-) mode change 100644 => 100755 stop.sh diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 3f6de26..9e6a6e6 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -11,8 +11,10 @@ class TournamentsController < ApplicationController # GET /tournaments/1 # GET /tournaments/1.json def show - unless @tournament.status - redirect_to tournament_matches_page(@tournament) + case @tournament.status + when 0 + when 1..2 + redirect_to "/tournaments/" + @tournament.id.to_s + "/matches" #tournament_matches_page(@tournament) end end @@ -25,6 +27,11 @@ class TournamentsController < ApplicationController # GET /tournaments/1/edit def edit + if params['close_action'] == 'close' + @tournament.status = 1 + @tournament.save + redirect_to "/tournaments" + end end # POST /tournaments diff --git a/app/models/user.rb b/app/models/user.rb index bad7f7b..c3a9acb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,7 +18,7 @@ class User < ActiveRecord::Base when :admin return ((groups & 2) != 0) when :host - return true #((groups & 1) != 0) + return ((groups & 1) != 0) when :player return true when :specator diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index cd111f7..a04c852 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -1,10 +1,11 @@ <% if @tournament.joinable_by?(current_user) %> <%= form_tag(tournament_path(@tournament), method: "put") do %> - <%= submit_tag("Join") %> + <%= current_user.name %><%= submit_tag("Join") %> <% end %> <% end %> +<% if current_user.in_group?(:host) %>

Game: <%= @tournament.game %> @@ -45,5 +46,12 @@ <%= @tournament.status %>

+<%= form_tag(tournaments_path.to_s + "/" + @tournament.id.to_s + "/edit", method: "get") do %> + + <%= submit_tag("Close Tournament Registration") %> +<% end %> + <%= link_to 'Edit', edit_tournament_path(@tournament) %> | -<%= link_to 'Back', tournaments_path %> \ No newline at end of file +<%= link_to 'Back', tournaments_path %> + +<% end %> \ No newline at end of file diff --git a/stop.sh b/stop.sh old mode 100644 new mode 100755 -- cgit v1.2.3-2-g168b From e1f6378a2c197a6d1c64f365dd52d2961e104cdb Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 6 Mar 2014 22:34:15 -0500 Subject: tidy up the tournament join and open controller logic --- app/controllers/tournaments_controller.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 1e26584..386a6a4 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -65,18 +65,20 @@ class TournamentsController < ApplicationController if @tournament.join(current_user) format.html { render action: 'show', notice: 'You have joined this tournament.' } format.json { head :no_content } + else + format.html { render action: 'permission_denied', status: :forbidden } + format.json { render json: "Permission denied", status: :forbidden } end - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } end when "open" respond_to do |format| if @tournament.setup - format.html { render action: 'show', notice: 'You have joined this tournament.' } + format.html { render action: 'show', notice: 'You have opend this tournament.' } format.json { head :no_content } + else + format.html { render action: 'permission_denied', status: :forbidden } + format.json { render json: "Permission denied", status: :forbidden } end - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } end #when "close" # TODO -- cgit v1.2.3-2-g168b From f959591c62d7e66454f676d9c2a9abdd6fac3a7f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 6 Mar 2014 22:35:35 -0500 Subject: TournamentsController: add stricter host access control --- app/controllers/tournaments_controller.rb | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 386a6a4..7c93346 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -1,6 +1,8 @@ class TournamentsController < ApplicationController - before_action :set_tournament, only: [:show, :edit, :update, :destroy, :join] - before_action :check_perms, only: [:new, :create, :edit, :destroy] + # put #update in with before_show, because in special cases the + # permissions are relaxed, so we do that right in the #update method + before_action :before_show, only: [:show, :update] + before_action :before_edit, only: [:new, :create, :edit, :destroy] # GET /tournaments # GET /tournaments.json @@ -46,9 +48,8 @@ class TournamentsController < ApplicationController # PATCH/PUT /tournaments/1 # PATCH/PUT /tournaments/1.json def update - if params[:update_action].nil? - check_perms + before_edit respond_to do |format| if @tournament.update(tournament_params) format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' } @@ -103,18 +104,19 @@ class TournamentsController < ApplicationController private # Use callbacks to share common setup or constraints between actions. - def set_tournament + def before_show @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 + def before_edit + @tournament = Tournament.find(params[:id]) + unless (signed_in? and (@tournament.hosts.include?(current_user) or current_user.in_group?(:admin))) + 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 -- cgit v1.2.3-2-g168b From 01c3f1af652fb32c235ad1c047d652e5148dba94 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 6 Mar 2014 22:55:10 -0500 Subject: fix thing again --- app/models/user.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index fa07b60..4d6902a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,6 @@ class User < ActiveRecord::Base - has_and_belongs_to_many :tournaments_played, class_name: "Tournament", foreign_key: "tournament_id", join_table: "players_tournaments" - has_and_belongs_to_many :tournaments_hosted, class_name: "Tournament", foreign_key: "tournament_id", join_table: "hosts_tournaments" + has_and_belongs_to_many :tournaments_played, class_name: "Tournament", foreign_key: "player_id", join_table: "players_tournaments" + has_and_belongs_to_many :tournaments_hosted, class_name: "Tournament", foreign_key: "host_id", join_table: "hosts_tournaments" before_save { self.email = email.downcase } before_save { self.user_name = user_name } -- cgit v1.2.3-2-g168b From ec351b90e1682541062c669a3f8b59131351b0a3 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 6 Mar 2014 23:06:58 -0500 Subject: provide a default value for users' groups --- app/controllers/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 907958b..70facca 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -28,7 +28,7 @@ class UsersController < ApplicationController # POST /users.json def create @user = User.new(user_params) - + @user.groups = 0 respond_to do |format| if @user.save sign_in @user -- cgit v1.2.3-2-g168b From 501e305de609313809b2641522679c17834c603f Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Thu, 6 Mar 2014 23:08:42 -0500 Subject: Fixed the registration in the tourney model and fixed a lint int the controller. --- app/controllers/tournaments_controller.rb | 2 +- app/models/tournament.rb | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 3583ec3..5155a4f 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -40,7 +40,7 @@ class TournamentsController < ApplicationController @tournament = Tournament.new(tournament_params) respond_to do |format| if @tournament.save - @tournament.hosts.push(current_user) + #@tournament.hosts.push(current_user) format.html { redirect_to @tournament, notice: 'Tournament was successfully created.' } format.json { render action: 'show', status: :created, location: @tournament } else diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 44b22f5..fe781e1 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -25,9 +25,17 @@ class Tournament < ActiveRecord::Base for i in 0..num_matches self.matches.create(name: "Match #{i}") end - #self.players.each_slice(num_teams) do |team_players| - # Team.new(users: team_players) - #end + match_num = 0 + team_num = 0 + self.players.each_slice(@tournament.max_players) do |players| + matches[match_num].teams[team_num] = Team.new(users: players) + if (team_num == 0 and team_num % @tournament.max_teams_per_match == 0) + match_num += 1 + team_num = 0 + else + team_num += 1 + end + end end -- cgit v1.2.3-2-g168b From 39ceb0e99eecd76b2cdebeb802930a98a764417a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 6 Mar 2014 23:15:53 -0500 Subject: let anyone always create a tourney --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 4d6902a..bd1a9ac 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,7 +18,7 @@ class User < ActiveRecord::Base when :admin return ((groups & 2) != 0) when :host - return ((groups & 1) != 0) + return true #((groups & 1) != 0) when :player return true when :specator -- cgit v1.2.3-2-g168b From e74879dd4769e8bed34085ee3f978fc4a31366cb Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Thu, 6 Mar 2014 23:50:58 -0500 Subject: Sorry guys. --- app/controllers/tournaments_controller.rb | 42 ++++++++++++++----------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 913ca52..3583ec3 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -1,8 +1,6 @@ class TournamentsController < ApplicationController - # put #update in with before_show, because in special cases the - # permissions are relaxed, so we do that right in the #update method - before_action :before_show, only: [:show, :update] - before_action :before_edit, only: [:new, :create, :edit, :destroy] + before_action :set_tournament, only: [:show, :edit, :update, :destroy, :join] + before_action :check_perms, only: [:new, :create, :edit, :destroy] # GET /tournaments # GET /tournaments.json @@ -42,7 +40,7 @@ class TournamentsController < ApplicationController @tournament = Tournament.new(tournament_params) respond_to do |format| if @tournament.save - #@tournament.hosts.push(current_user) + @tournament.hosts.push(current_user) format.html { redirect_to @tournament, notice: 'Tournament was successfully created.' } format.json { render action: 'show', status: :created, location: @tournament } else @@ -55,8 +53,9 @@ class TournamentsController < ApplicationController # PATCH/PUT /tournaments/1 # PATCH/PUT /tournaments/1.json def update + if params[:update_action].nil? - before_edit + check_perms respond_to do |format| if @tournament.update(tournament_params) format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' } @@ -73,20 +72,18 @@ class TournamentsController < ApplicationController if @tournament.join(current_user) format.html { render action: 'show', notice: 'You have joined this tournament.' } format.json { head :no_content } - else - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } end + format.html { render action: 'permission_denied', status: :forbidden } + format.json { render json: "Permission denied", status: :forbidden } end when "open" respond_to do |format| if @tournament.setup - format.html { render action: 'show', notice: 'You have opend this tournament.' } + format.html { render action: 'show', notice: 'You have joined this tournament.' } format.json { head :no_content } - else - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } end + format.html { render action: 'permission_denied', status: :forbidden } + format.json { render json: "Permission denied", status: :forbidden } end #when "close" # TODO @@ -111,19 +108,18 @@ class TournamentsController < ApplicationController private # Use callbacks to share common setup or constraints between actions. - def before_show + def set_tournament @tournament = Tournament.find(params[:id]) end - def before_edit - @tournament = Tournament.find(params[:id]) - unless (signed_in? and (@tournament.hosts.include?(current_user) or current_user.in_group?(:admin))) - respond_to do |format| - format.html { render action: 'permission_denied', status: :forbidden } - format.json { render json: "Permission denied", status: :forbidden } - end - end - 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 -- cgit v1.2.3-2-g168b