From 18d76defd43cb747824a355b2d320c5cf2c55d6a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 4 Apr 2014 23:51:32 -0400 Subject: fix issues in tournaments controller --- app/controllers/tournaments_controller.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 010f279..a9e91b0 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -70,23 +70,25 @@ class TournamentsController < ApplicationController end end when "join" - check_permission(:join) + # permission checking for join is done in the Tournament model respond_to do |format| if @tournament.join(current_user) format.html { redirect_to @tournament, notice: 'You have joined this tournament.' } format.json { head :no_content } + else + format.html { redirect_to @tournament, notice: "You can't join this tournament." } + 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 "leave" respond_to do |format| if @tournament.leave(current_user) format.html { redirect_to tournaments_url, notice: 'You have left the tournament.' } format.json { head :no_content } + else + format.html { redirect_to @tournament, notice: 'You were\'t a part of this tournament.' } + format.json { render json: "Permission denied", status: :forbidden } end - format.html {redirect_to @tournament, notice: 'You were\'t a part of this tournament.' } - format.json { render json: "Permission denied", status: :forbidden } end when "start" check_permission(:edit, @tournament) @@ -96,9 +98,10 @@ class TournamentsController < ApplicationController if @tournament.setup format.html { redirect_to @tournament, 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 else respond_to do |format| -- cgit v1.2.3-2-g168b From 0d42079611ed2aeacd71b926580fdc3b943cf1ba Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 6 Apr 2014 12:22:11 -0400 Subject: make editing user permissions work --- app/controllers/users_controller.rb | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bcb45aa..dd66c18 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -24,17 +24,29 @@ class UsersController < ApplicationController # POST /users # POST /users.json def create - if simple_captcha_valid? - @user = User.new(user_params) + @user = User.new(user_params) + unless (simple_captcha_valid?) respond_to do |format| - if @user.save - sign_in @user - format.html { redirect_to root_path, notice: 'User was successfully created.' } - format.json { render action: 'show', status: :created, location: @user } - else - format.html { render action: 'new', status: :unprocessable_entity } - format.json { render json: @user.errors, status: :unprocessable_entity } + format.html { render action: 'new', status: :unprocessable_entity } + format.json { render json: @user.errors, status: :unprocessable_entity } + end + return + end + + @user.permissions = 0 + respond_to do |format| + if @user.save + sign_in @user + if @user.id == 1 + # This is the first user, so give them all the power + @user.permissions = 0xFFFFFFFF + @user.save end + format.html { redirect_to root_path, notice: 'User was successfully created.' } + format.json { render action: 'show', status: :created, location: @user } + else + format.html { render action: 'new', status: :unprocessable_entity } + format.json { render json: @user.errors, status: :unprocessable_entity } end end end @@ -75,6 +87,10 @@ class UsersController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def user_params - params.require(:user).permit(:name, :email, :user_name, :password, :password_confirmation) + permitted = [ :name, :email, :user_name, :password, :password_confirmation ] + if current_user.can? :edit_permissions + permitted.push(:abilities => User.permission_bits.keys) + end + params.require(:user).permit(permitted) end end -- cgit v1.2.3-2-g168b From d2e4f58410c20f5e7b9e8e0dde3fd55d201af4bb Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 6 Apr 2014 13:18:00 -0400 Subject: run generate --- app/controllers/servers_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/servers_controller.rb b/app/controllers/servers_controller.rb index 43999c4..4c12c7e 100644 --- a/app/controllers/servers_controller.rb +++ b/app/controllers/servers_controller.rb @@ -69,6 +69,6 @@ class ServersController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def server_params - params[:server] + params.require(:server).permit(:default_user_permissions) end end -- cgit v1.2.3-2-g168b From a81c1ca571b0bb41f0acba6594559c7405fc2bb1 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 6 Apr 2014 13:58:00 -0400 Subject: Simplify the server controller and views, as it is a singular resource --- app/controllers/servers_controller.rb | 51 +++++------------------------------ 1 file changed, 7 insertions(+), 44 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/servers_controller.rb b/app/controllers/servers_controller.rb index 27c6f9f..e3850b8 100644 --- a/app/controllers/servers_controller.rb +++ b/app/controllers/servers_controller.rb @@ -1,43 +1,15 @@ class ServersController < ApplicationController - - # GET /servers - # GET /servers.json - def index - @servers = Server.all - end - - # GET /servers/1 - # GET /servers/1.json + # GET /server + # GET /server.json def show end - # GET /servers/new - def new - @server = Server.new - end - - # GET /servers/1/edit + # GET /server/edit def edit end - # POST /servers - # POST /servers.json - def create - @server = Server.new(server_params) - - respond_to do |format| - if @server.save - format.html { redirect_to @server, notice: 'Server was successfully created.' } - format.json { render action: 'show', status: :created, location: @server } - else - format.html { render action: 'new' } - format.json { render json: @server.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /servers/1 - # PATCH/PUT /servers/1.json + # PATCH/PUT /server + # PATCH/PUT /server.json def update respond_to do |format| if @server.update(server_params) @@ -50,20 +22,11 @@ class ServersController < ApplicationController end end - # DELETE /servers/1 - # DELETE /servers/1.json - def destroy - @server.destroy - respond_to do |format| - format.html { redirect_to servers_url } - format.json { head :no_content } - end - end - private + # Use callbacks to share common setup or constraints between actions. def set_server - @server = Server.find(params[:id]) + @server = Server.first end # Never trust parameters from the scary internet, only allow the white list through. -- cgit v1.2.3-2-g168b From cfaff7870d0348b25b3b4b2597950894ab25d989 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 6 Apr 2014 14:32:38 -0400 Subject: implement editing the default user permissions --- app/controllers/servers_controller.rb | 2 +- app/controllers/users_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/servers_controller.rb b/app/controllers/servers_controller.rb index e3850b8..83a9f31 100644 --- a/app/controllers/servers_controller.rb +++ b/app/controllers/servers_controller.rb @@ -31,6 +31,6 @@ class ServersController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def server_params - params.require(:server).permit(:default_user_permissions) + params.require(:server).permit(:default_user_permissions, :default_user_abilities => User.permission_bits.keys) end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index dd66c18..637480f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -33,7 +33,7 @@ class UsersController < ApplicationController return end - @user.permissions = 0 + @user.permissions = Server.first.default_user_permissions respond_to do |format| if @user.save sign_in @user -- cgit v1.2.3-2-g168b From 8f1a442b8f647ddca49572c8deb63f035d85ccf8 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 6 Apr 2014 17:32:34 -0400 Subject: I swear I have fixed this before --- app/controllers/tournaments_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index a9e91b0..2fc82ed 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -99,7 +99,7 @@ class TournamentsController < ApplicationController format.html { redirect_to @tournament, notice: 'You have joined this tournament.' } format.json { head :no_content } else - format.html { render action: 'permission_denied', status: :forbidden } + format.html { redirect_to @tournament, notice: "You don't have permission to start this tournament." } format.json { render json: "Permission denied", status: :forbidden } end end -- cgit v1.2.3-2-g168b From f85943114dba527a1f87abb03229553472f57c0c Mon Sep 17 00:00:00 2001 From: tkimia Date: Sun, 6 Apr 2014 18:45:41 -0400 Subject: started SVG generation --- app/controllers/matches_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 31fc9ad..e773667 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -8,6 +8,10 @@ class MatchesController < ApplicationController def index @matches = @tournament.matches + # width of SVG + @width = 300 * (Math.log2(@matches.count).floor + 1) + 300; + # height of SVG + @height = 200 * 2**Math.log2(@matches.count).floor + 100; end def get_riot_info -- cgit v1.2.3-2-g168b