diff options
author | guntasgrewal <guntasgrewal@gmail.com> | 2014-04-06 20:09:54 -0400 |
---|---|---|
committer | guntasgrewal <guntasgrewal@gmail.com> | 2014-04-06 20:09:54 -0400 |
commit | f3c395c56a644d976aa9a5608300557600bc683e (patch) | |
tree | 83cb961a721fa8c50903c70bb08ae14dd15ca58c /app/controllers | |
parent | 7575d8cc70a28b323db0486ed06ab8af33b1f21a (diff) | |
parent | f85943114dba527a1f87abb03229553472f57c0c (diff) |
solved merge conflicts
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/matches_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/servers_controller.rb | 53 | ||||
-rw-r--r-- | app/controllers/tournaments_controller.rb | 17 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 36 |
4 files changed, 48 insertions, 62 deletions
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 diff --git a/app/controllers/servers_controller.rb b/app/controllers/servers_controller.rb index 6596dc6..83a9f31 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,24 +22,15 @@ 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. def server_params - params[:server] + params.require(:server).permit(:default_user_permissions, :default_user_abilities => User.permission_bits.keys) end end diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 010f279..2fc82ed 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 { redirect_to @tournament, notice: "You don't have permission to start 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 else respond_to do |format| diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bcb45aa..637480f 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 = Server.first.default_user_permissions + 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 |