From e59e8ac8e7eb5dd7b997dd3531557de120445f7f Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Wed, 18 Mar 2020 05:38:17 +0200 Subject: [PATCH] Lots of rails 4 updates - Add .params to models and update controllers - Add afk time to gather - Reannotate models - Fix rspec problem by using latest rspec plugins from github --- Gemfile | 10 +- Gemfile.lock | 73 +++++--- app/controllers/articles_controller.rb | 2 +- app/controllers/bans_controller.rb | 8 +- app/controllers/brackets_controller.rb | 4 +- app/controllers/categories_controller.rb | 5 +- app/controllers/challenges_controller.rb | 4 +- app/controllers/comments_controller.rb | 4 +- app/controllers/contesters_controller.rb | 4 +- app/controllers/contests_controller.rb | 4 +- app/controllers/data_files_controller.rb | 4 +- app/controllers/directories_controller.rb | 4 +- app/controllers/forumers_controller.rb | 4 +- app/controllers/forums_controller.rb | 4 +- app/controllers/gatherers_controller.rb | 8 +- app/controllers/gathers_controller.rb | 2 +- app/controllers/groupers_controller.rb | 4 +- app/controllers/groups_controller.rb | 4 +- app/controllers/issues_controller.rb | 4 +- app/controllers/locks_controller.rb | 2 +- app/controllers/maps_controller.rb | 4 +- app/controllers/match_proposals_controller.rb | 5 +- app/controllers/matches_controller.rb | 6 +- app/controllers/messages_controller.rb | 2 +- app/controllers/movies_controller.rb | 4 +- app/controllers/options_controller.rb | 4 +- app/controllers/polls_controller.rb | 4 +- app/controllers/posts_controller.rb | 4 +- app/controllers/predictions_controller.rb | 2 +- app/controllers/servers_controller.rb | 4 +- app/controllers/shoutmsgs_controller.rb | 2 +- app/controllers/teamers_controller.rb | 4 +- app/controllers/teams_controller.rb | 4 +- app/controllers/topics_controller.rb | 2 +- app/controllers/users_controller.rb | 10 +- app/controllers/votes_controller.rb | 2 +- app/controllers/weeks_controller.rb | 4 +- app/models/article.rb | 19 ++- app/models/ban.rb | 21 ++- app/models/bracket.rb | 12 +- app/models/bracketer.rb | 11 +- app/models/category.rb | 11 +- app/models/challenge.rb | 27 ++- app/models/comment.rb | 19 ++- app/models/contest.rb | 36 ++-- app/models/contester.rb | 25 ++- app/models/custom_url.rb | 23 ++- app/models/data_file.rb | 16 +- app/models/directory.rb | 15 +- app/models/forum.rb | 13 +- app/models/forumer.rb | 13 +- app/models/gather.rb | 26 ++- app/models/gather_map.rb | 7 +- app/models/gatherer.rb | 18 +- app/models/group.rb | 9 +- app/models/grouper.rb | 11 +- app/models/issue.rb | 25 ++- app/models/lock.rb | 10 +- app/models/map.rb | 10 +- app/models/match.rb | 60 ++++--- app/models/match_proposal.rb | 17 ++ app/models/matcher.rb | 14 +- app/models/message.rb | 20 ++- app/models/movie.rb | 156 ++++++++++-------- app/models/option.rb | 13 +- app/models/poll.rb | 14 +- app/models/post.rb | 18 +- app/models/prediction.rb | 15 +- app/models/profile.rb | 96 ++++++----- app/models/server.rb | 46 ++++-- app/models/shoutmsg.rb | 13 +- app/models/team.rb | 35 ++-- app/models/teamer.rb | 13 +- app/models/topic.rb | 15 +- app/models/user.rb | 37 +++-- app/models/view_count.rb | 8 +- app/models/vote.rb | 13 +- app/models/week.rb | 14 +- app/views/gathers/_running.html.erb | 1 + lib/tasks/auto_annotate_models.rake | 59 +++++++ spec/models/ban_spec.rb | 17 +- spec/models/forum_spec.rb | 10 +- spec/models/forumer_spec.rb | 9 +- spec/models/issue_spec.rb | 20 ++- spec/models/message_spec.rb | 15 +- spec/models/post_spec.rb | 13 +- spec/models/server_spec.rb | 40 +++-- spec/models/topic_spec.rb | 11 +- spec/models/user_spec.rb | 30 ++-- 89 files changed, 991 insertions(+), 453 deletions(-) create mode 100644 lib/tasks/auto_annotate_models.rake diff --git a/Gemfile b/Gemfile index efe2eb0..b97468b 100644 --- a/Gemfile +++ b/Gemfile @@ -38,6 +38,7 @@ gem 'dynamic_form' gem 'public_suffix' gem 'sanitize' gem 'will_paginate' +gem 'time_difference' # External APIs gem 'google-api-client', '~> 0.10.3' @@ -94,8 +95,6 @@ group :test do gem 'factory_bot_rails', '4.10.0' gem 'phantomjs', require: 'phantomjs/poltergeist' gem 'poltergeist' - gem 'rspec' - gem 'rspec-rails' gem 'selenium-webdriver' # Fix FF issue gem 'geckodriver-helper' @@ -104,6 +103,13 @@ group :test do gem 'simplecov', require: false gem 'test-unit' gem 'timecop' + + # Use dev versions because of rspec bug + gem 'rspec-core', git: 'https://github.com/rspec/rspec-core' + gem 'rspec-expectations', git: 'https://github.com/rspec/rspec-expectations' + gem 'rspec-mocks', git: 'https://github.com/rspec/rspec-mocks' + gem 'rspec-rails', git: 'https://github.com/rspec/rspec-rails' + gem 'rspec-support', git: 'https://github.com/rspec/rspec-support' end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index de6434c..d479133 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,6 +6,48 @@ GIT multi_json (~> 1.6) multi_xml (~> 0.5) +GIT + remote: https://github.com/rspec/rspec-core + revision: 725b0d2eadaa9ac9f816a6d2d7ef1e507a6705cd + specs: + rspec-core (3.10.0.pre) + rspec-support (= 3.10.0.pre) + +GIT + remote: https://github.com/rspec/rspec-expectations + revision: 3c997d98f49731b2d28d01e070b88aef6bb3c68b + specs: + rspec-expectations (3.10.0.pre) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (= 3.10.0.pre) + +GIT + remote: https://github.com/rspec/rspec-mocks + revision: 81c17e89b2722cb225d602e08b600e4a4f6148a4 + specs: + rspec-mocks (3.10.0.pre) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (= 3.10.0.pre) + +GIT + remote: https://github.com/rspec/rspec-rails + revision: 84e79259c8978fdff34ea2a327316b638ff00b85 + specs: + rspec-rails (4.0.0.pre) + actionpack (>= 4.2) + activesupport (>= 4.2) + railties (>= 4.2) + rspec-core (= 3.10.0.pre) + rspec-expectations (= 3.10.0.pre) + rspec-mocks (= 3.10.0.pre) + rspec-support (= 3.10.0.pre) + +GIT + remote: https://github.com/rspec/rspec-support + revision: 9cec8e858228ee1d1395e4e6186ac39c2a83d705 + specs: + rspec-support (3.10.0.pre) + GEM remote: http://rubygems.org/ specs: @@ -306,27 +348,6 @@ GEM retriable (3.1.2) rexml (3.2.4) rmagick (4.0.0) - rspec (3.9.0) - rspec-core (~> 3.9.0) - rspec-expectations (~> 3.9.0) - rspec-mocks (~> 3.9.0) - rspec-core (3.9.1) - rspec-support (~> 3.9.1) - rspec-expectations (3.9.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-mocks (3.9.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-rails (3.9.1) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.9.0) - rspec-expectations (~> 3.9.0) - rspec-mocks (~> 3.9.0) - rspec-support (~> 3.9.0) - rspec-support (3.9.2) rubocop (0.80.1) jaro_winkler (~> 1.5.1) parallel (~> 1.10) @@ -384,6 +405,8 @@ GEM thor (1.0.1) thread_safe (0.3.6) tilt (2.0.10) + time_difference (0.5.0) + activesupport timecop (0.9.1) tinymce-rails (5.2.0) railties (>= 3.1.1) @@ -454,8 +477,11 @@ DEPENDENCIES rake (< 11.0) responders rmagick - rspec - rspec-rails + rspec-core! + rspec-expectations! + rspec-mocks! + rspec-rails! + rspec-support! rubocop sanitize sass-rails (~> 5.0.3) @@ -465,6 +491,7 @@ DEPENDENCIES spring (= 2.0.2) steam-condenser! test-unit + time_difference timecop tinymce-rails uglifier (~> 2.5.0) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 334aa45..4a259e2 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -53,7 +53,7 @@ class ArticlesController < ApplicationController def update raise AccessError unless @article.can_update? cuser, Article.article_params(params, cuser) - if @article.update_attributes(article_params) + if @article.update_attributes(Article.article_params(params, cuser)) flash[:notice] = t(:articles_update) redirect_to @article else diff --git a/app/controllers/bans_controller.rb b/app/controllers/bans_controller.rb index bf67f1c..0fac2ac 100644 --- a/app/controllers/bans_controller.rb +++ b/app/controllers/bans_controller.rb @@ -18,7 +18,7 @@ class BansController < ApplicationController end def create - @ban = Ban.new(params[:ban]) + @ban = Ban.new(Ban.params(params, cuser)) raise AccessError unless @ban.can_create? cuser @ban.creator = cuser @@ -32,7 +32,7 @@ class BansController < ApplicationController def update raise AccessError unless @ban.can_update? cuser - if @ban.update_attributes(ban_params(ban_params)) + if @ban.update_attributes(Ban.params(params, cuser)) flash[:notice] = t(:bans_update) redirect_to(@ban) else @@ -51,8 +51,4 @@ class BansController < ApplicationController def get_ban @ban = Ban.find(params[:id]) end - - def ban_params - params.permit(:steamid, :user_id, :addr, :server_id, :expiry, :reason, :ban_type, :ip) - end end diff --git a/app/controllers/brackets_controller.rb b/app/controllers/brackets_controller.rb index 4140127..56db789 100644 --- a/app/controllers/brackets_controller.rb +++ b/app/controllers/brackets_controller.rb @@ -7,7 +7,7 @@ class BracketsController < ApplicationController end def create - @bracket = Bracket.new params[:bracket] + @bracket = Bracket.new Bracket.params(params, cuser) raise AccessError unless @bracket.can_create? cuser if @bracket.save @@ -20,7 +20,7 @@ class BracketsController < ApplicationController def update raise AccessError unless @bracket.can_update? cuser - if @bracket.update_attributes params[:bracket] and @bracket.update_cells(params[:cell]) + if @bracket.update_attributes(Bracket.params(params, cuser)) and @bracket.update_cells(params.permit(:cell)[:cell]) flash[:notice] = t(:brackets_update) end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 5272f9d..20f47eb 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -23,10 +23,11 @@ class CategoriesController < ApplicationController end def create - @category = Category.new params[:category] + @category = Category.new Category.params(params, cuser) raise AccessError unless @category.can_create? cuser if @category.save + # FIXME: move to model @category.update_attribute :sort, @category.id flash[:notice] = t(:articles_category) redirect_to :categories @@ -37,7 +38,7 @@ class CategoriesController < ApplicationController def update raise AccessError unless @category.can_update? cuser - if @category.update_attributes params[:category] + if @category.update_attributes Category.params(params, cuser) flash[:notice] = t(:articles_category_update) redirect_to :categories end diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 4b1f169..5fae970 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -29,7 +29,7 @@ class ChallengesController < ApplicationController end def create - @challenge = Challenge.new params[:challenge] + @challenge = Challenge.new(Challenge.params(params, cuser)) @challenge.user = cuser raise AccessError unless @challenge.can_create? cuser @@ -55,7 +55,7 @@ class ChallengesController < ApplicationController @challenge.status = Challenge::STATUS_DECLINED end - if @challenge.update_attributes params[:challenge] + if @challenge.update_attributes(Challenge.params(params, cuser)) flash[:notice] = t(:challenges_update) end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 24c2423..ee6e034 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -16,7 +16,7 @@ class CommentsController < ApplicationController end def create - @comment = Comment.new params[:comment] + @comment = Comment.new Comment.params(parmas, cuser) @comment.user = cuser raise AccessError unless @comment.can_create? cuser @@ -33,7 +33,7 @@ class CommentsController < ApplicationController def update raise AccessError unless @comment.can_update? cuser - if @comment.update_attributes params[:comment] + if @comment.update_attributes(Comment.params(parmas, cuser)) flash[:notice] = t(:comments_update) return_to else diff --git a/app/controllers/contesters_controller.rb b/app/controllers/contesters_controller.rb index d330c07..4d7b233 100644 --- a/app/controllers/contesters_controller.rb +++ b/app/controllers/contesters_controller.rb @@ -19,7 +19,7 @@ class ContestersController < ApplicationController end def create - @contester = Contester.new params[:contester] + @contester = Contester.new(Contester.params(params, cuser)) @contester.user = cuser raise AccessError unless @contester.can_create? cuser if @contester.contest.contest_type == Contest::TYPE_LADDER @@ -48,7 +48,7 @@ class ContestersController < ApplicationController end end - if @contester.update_attributes params[:contester] + if @contester.update_attributes(Contester.params(params, cuser)) flash[:notice] = t(:contests_contester_update) redirect_to @contester.contest else diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index 4d5fa4d..5acd705 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -53,7 +53,7 @@ class ContestsController < ApplicationController end def create - @contest = Contest.new params[:contest] + @contest = Contest.new(Contest.params(params, cuser)) raise AccessError unless @contest.can_create? cuser if @contest.save @@ -67,7 +67,7 @@ class ContestsController < ApplicationController def update raise AccessError unless @contest.can_update? cuser if update_type == "contest" - if @contest.update_attributes(params[:contest]) + if @contest.update_attributes(Contest.params(params, cuser)) flash[:notice] = t(:contests_update) redirect_to @contest else diff --git a/app/controllers/data_files_controller.rb b/app/controllers/data_files_controller.rb index 41129bb..7faa1f1 100644 --- a/app/controllers/data_files_controller.rb +++ b/app/controllers/data_files_controller.rb @@ -27,7 +27,7 @@ class DataFilesController < ApplicationController end def create - @file = DataFile.new params[:data_file] + @file = DataFile.new(DataFile.params(params, cuser)) @file.size = 0 raise AccessError unless @file.can_create? cuser @@ -47,7 +47,7 @@ class DataFilesController < ApplicationController def update raise AccessError unless @file.can_update? cuser - if @file.update_attributes params[:data_file] + if @file.update_attributes(DataFile.params(params, cuser)) flash[:notice] = t(:files_update) redirect_to(@file) else diff --git a/app/controllers/directories_controller.rb b/app/controllers/directories_controller.rb index 9bfecad..677fa4b 100644 --- a/app/controllers/directories_controller.rb +++ b/app/controllers/directories_controller.rb @@ -26,7 +26,7 @@ class DirectoriesController < ApplicationController end def create - @directory = Directory.new params[:directory] + @directory = Directory.new(Directory.params(params, cuser)) raise AccessError unless @directory.can_create? cuser if @directory.save @@ -39,7 +39,7 @@ class DirectoriesController < ApplicationController def update raise AccessError unless @directory.can_update? cuser - if @directory.update_attributes(params[:directory]) + if @directory.update_attributes(Directory.params(params, cuser)) flash[:notice] = t(:directories_update) redirect_to @directory else diff --git a/app/controllers/forumers_controller.rb b/app/controllers/forumers_controller.rb index 55cb46e..221cf85 100644 --- a/app/controllers/forumers_controller.rb +++ b/app/controllers/forumers_controller.rb @@ -1,6 +1,6 @@ class ForumersController < ApplicationController def create - @forumer = Forumer.new params[:forumer] + @forumer = Forumer.new(Forumer.params(params, cuser)) raise AccessError unless @forumer.can_create? cuser if @forumer.save @@ -16,7 +16,7 @@ class ForumersController < ApplicationController @forumer = Forumer.find params[:id] raise AccessError unless @forumer.can_update? cuser - if @forumer.update_attributes params[:forumer] + if @forumer.update_attributes(Forumer.params(params, cuser)) flash[:notice] = t(:groups_acl_update) else flash[:error] = @forumer.errors.full_messages.to_s diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 8e8bd3b..57e451b 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -31,7 +31,7 @@ class ForumsController < ApplicationController end def create - @forum = Forum.new(params[:forum]) + @forum = Forum.new(Forum.params(params, cuser)) raise AccessError unless @forum.can_create? cuser if @forum.save @@ -44,7 +44,7 @@ class ForumsController < ApplicationController def update raise AccessError unless @forum.can_update? cuser - if @forum.update_attributes(params[:forum]) + if @forum.update_attributes(Forum.params(params, cuser)) flash[:notice] = t(:forums_update) redirect_to(@forum) else diff --git a/app/controllers/gatherers_controller.rb b/app/controllers/gatherers_controller.rb index b178262..e1f744b 100644 --- a/app/controllers/gatherers_controller.rb +++ b/app/controllers/gatherers_controller.rb @@ -4,9 +4,9 @@ class GatherersController < ApplicationController def create Gather.transaction do Gatherer.transaction do - @gatherer = Gatherer.new params[:gatherer] + @gatherer = Gatherer.new(Gatherer.params(params, cuser)) @gatherer.gather.lock! - raise AccessError unless @gatherer.can_create? cuser, params[:gatherer] + raise AccessError unless @gatherer.can_create?(cuser, Gatherer.params(params, cuser)) if @gatherer.save flash[:notice] = t(:gathers_join) @@ -21,9 +21,9 @@ class GatherersController < ApplicationController def update @gatherer = Gatherer.find params[:gatherer][:id] - raise AccessError unless @gatherer.can_update? cuser, params[:gatherer] + raise AccessError unless @gatherer.can_update?(cuser, Gatherer.params(params, cuser)) - if @gatherer.update_attributes params[:gatherer] + if @gatherer.update_attributes(Gatherer.params(params, cuser)) flash[:notice] = t(:gatherers_update) else flash[:error] = @gatherer.errors.full_messages.to_s diff --git a/app/controllers/gathers_controller.rb b/app/controllers/gathers_controller.rb index 45bd78d..0703678 100644 --- a/app/controllers/gathers_controller.rb +++ b/app/controllers/gathers_controller.rb @@ -37,7 +37,7 @@ class GathersController < ApplicationController Gatherer.transaction do Gather.transaction do - if @gather.update_attributes params[:gather] + if @gather.update_attributes(Gather.params(params, cuser)) flash[:notice] = 'Gather was successfully updated.' end end diff --git a/app/controllers/groupers_controller.rb b/app/controllers/groupers_controller.rb index 91a577d..84ce356 100644 --- a/app/controllers/groupers_controller.rb +++ b/app/controllers/groupers_controller.rb @@ -1,6 +1,6 @@ class GroupersController < ApplicationController def create - @grouper = Grouper.new params[:grouper] + @grouper = Grouper.new(Grouper.params(params, cuser)) raise AccessError unless @grouper.can_create? cuser if @grouper.save @@ -16,7 +16,7 @@ class GroupersController < ApplicationController @grouper = Grouper.find params[:id] raise AccessError unless @grouper.can_update? cuser - if @grouper.update_attributes params[:grouper] + if @grouper.update_attributes(Grouper.params(params, cuser)) flash[:notice] = t(:groups_user_update) else flash[:error] = @grouper.errors.full_messages.to_s diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index ffc915e..8d38338 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -19,7 +19,7 @@ class GroupsController < ApplicationController end def create - @group = Group.new params[:group] + @group = Group.new(Group.params(params, cuser)) @group.founder = cuser raise AccessError unless @group.can_create? cuser if @group.save @@ -32,7 +32,7 @@ class GroupsController < ApplicationController def update raise AccessError unless @group.can_update? cuser - if @group.update_attributes params[:group] + if @group.update_attributes(Group.params(params, cuser)) flash[:notice] = t(:groups_update) redirect_to @group else diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 3e9d395..891823e 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -36,7 +36,7 @@ class IssuesController < ApplicationController end def create - @issue = Issue.new(params[:issue]) + @issue = Issue.new(Issue.params(params, cuser)) @issue.author = cuser if cuser raise AccessError unless @issue.can_create? cuser @@ -54,7 +54,7 @@ class IssuesController < ApplicationController def update raise AccessError unless @issue.can_update?(cuser, params[:issue]) - if @issue.update_attributes(params[:issue]) + if @issue.update_attributes(Issue.params(params, cuser)) flash[:notice] = t(:issues_update) redirect_to(@issue) else diff --git a/app/controllers/locks_controller.rb b/app/controllers/locks_controller.rb index c336cd4..a792eac 100644 --- a/app/controllers/locks_controller.rb +++ b/app/controllers/locks_controller.rb @@ -1,6 +1,6 @@ class LocksController < ApplicationController def create - @lock = Lock.new params[:lock] + @lock = Lock.new(Lock.params(params, cuser)) raise AccessError unless @lock.can_create? cuser if @lock.save diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 0161d93..7608aec 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -18,7 +18,7 @@ class MapsController < ApplicationController end def create - @map = Map.new params[:map] + @map = Map.new(Map.params(params, cuser)) raise AccessError unless @map.can_create? cuser if @map.save @@ -31,7 +31,7 @@ class MapsController < ApplicationController def update raise AccessError unless @map.can_update? cuser - if @map.update_attributes(params[:map]) + if @map.update_attributes(Map.params(params, cuser)) flash[:notice] = t(:maps_update) redirect_to @map else diff --git a/app/controllers/match_proposals_controller.rb b/app/controllers/match_proposals_controller.rb index ddbd615..ccc23ad 100644 --- a/app/controllers/match_proposals_controller.rb +++ b/app/controllers/match_proposals_controller.rb @@ -1,5 +1,6 @@ class MatchProposalsController < ApplicationController before_action :get_match + def index raise AccessError unless cuser.admin? || @match.user_in_match?(cuser) end @@ -19,7 +20,7 @@ class MatchProposalsController < ApplicationController end def create - @proposal = MatchProposal.new(params[:match_proposal]) + @proposal = MatchProposal.new(MatchProposal.params(params, cuser)) @proposal.match = @match raise AccessError unless @proposal.can_create? cuser @proposal.team = cuser.team @@ -49,7 +50,7 @@ class MatchProposalsController < ApplicationController } render(json: rjson, status: :not_found) && return end - unless proposal.can_update?(cuser, params[:match_proposal]) + unless proposal.can_update?(cuser, MatchProposal.params(params, cuser)) rjson[:error] = { code: 403, message: "You are not allowed to update the state to #{MatchProposal.status_strings[params[:match_proposal][:status].to_i]}" diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 6e58f22..c5d11bb 100755 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -6,7 +6,7 @@ class MatchesController < ApplicationController end def show - @ownpred = @match.predictions.first conditions: { user_id: cuser.id } if cuser + @ownpred = @match.predictions.where(user_id: cuser.id) if cuser @newpred = @match.predictions.build end @@ -35,7 +35,7 @@ class MatchesController < ApplicationController end def create - @match = Match.new params[:match] + @match = Match.new(Match.params(params, cuser)) raise AccessError unless @match.can_create? cuser if @match.save @@ -59,7 +59,7 @@ class MatchesController < ApplicationController end end - if @match.update_attributes params[:match] + if @match.update_attributes(Match.params(params, cuser)) respond_to do |format| format.xml { head :ok } format.html do diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 2eb729e..35a1f00 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -29,7 +29,7 @@ class MessagesController < ApplicationController end def create - @message = Message.new(params[:message]) + @message = Message.new(Message.params(params, cuser)) @message.sender = @message.sender_raw == "" ? cuser : cuser.active_teams.find(@message.sender_raw) raise AccessError unless @message.can_create? cuser diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 347ef6c..8506b34 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -25,7 +25,7 @@ class MoviesController < ApplicationController end def create - @movie = Movie.new(params[:movie]) + @movie = Movie.new(Movie.params(params, cuser)) raise AccessError unless @movie.can_create? cuser if @movie.save @@ -39,7 +39,7 @@ class MoviesController < ApplicationController def update raise AccessError unless @movie.can_update? cuser - if @movie.update_attributes(params[:movie]) + if @movie.update_attributes(Movie.params(params, cuser)) flash[:notice] = t(:movies_update) redirect_to(@movie) else diff --git a/app/controllers/options_controller.rb b/app/controllers/options_controller.rb index 383aeab..1547790 100644 --- a/app/controllers/options_controller.rb +++ b/app/controllers/options_controller.rb @@ -6,7 +6,7 @@ class PollsController < ApplicationController end def create - @poll = Poll.new params[:poll] + @poll = Poll.new(Poll.params(params, cuser)) @poll.user = cuser raise AccessError unless @poll.can_create? cuser @@ -21,7 +21,7 @@ class PollsController < ApplicationController def update raise AccessError unless @poll.can_update? cuser - if @poll.update_attributes params[:poll] + if @poll.update_attributes(Poll.params(params, cuser)) flash[:notice] = t(:polls_update) redirect_to @poll else diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 6082249..415b443 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -19,7 +19,7 @@ class PollsController < ApplicationController end def create - @poll = Poll.new params[:poll] + @poll = Poll.new(Poll.params(params, cuser)) @poll.user = cuser raise AccessError unless @poll.can_create? cuser @@ -34,7 +34,7 @@ class PollsController < ApplicationController def update raise AccessError unless @poll.can_update? cuser - if @poll.update_attributes params[:poll] + if @poll.update_attributes(Poll.params(params, cuser)) flash[:notice] = t(:polls_update) redirect_to @poll else diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index bfe0a7a..3404883 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -19,7 +19,7 @@ class PostsController < ApplicationController end def create - @post = Post.new(params[:post]) + @post = Post.new(Post.params(params, cuser)) @post.user = cuser raise AccessError unless @post.can_create? cuser @@ -36,7 +36,7 @@ class PostsController < ApplicationController def update raise AccessError unless @post.can_update? cuser, params[:post] - if @post.update_attributes(params[:post]) + if @post.update_attributes(Post.params(params, cuser)) flash[:notice] = t(:posts_update) redirect_to @post.topic else diff --git a/app/controllers/predictions_controller.rb b/app/controllers/predictions_controller.rb index 5335884..4971202 100644 --- a/app/controllers/predictions_controller.rb +++ b/app/controllers/predictions_controller.rb @@ -1,6 +1,6 @@ class PredictionsController < ApplicationController def create - @prediction = Prediction.new params[:prediction] + @prediction = Prediction.new(Prediction.params(params, cuser)) @prediction.user = cuser raise AccessError unless @prediction.can_create? cuser diff --git a/app/controllers/servers_controller.rb b/app/controllers/servers_controller.rb index 44199ee..9b3aa5a 100644 --- a/app/controllers/servers_controller.rb +++ b/app/controllers/servers_controller.rb @@ -20,7 +20,7 @@ class ServersController < ApplicationController end def create - @server = Server.new params[:server] + @server = Server.new(Server.params(params, cuser)) @server.user = cuser raise AccessError unless @server.can_create? cuser @@ -35,7 +35,7 @@ class ServersController < ApplicationController def update raise AccessError unless @server.can_update? cuser - if @server.update_attributes params[:server] + if @server.update_attributes(Server.params(params, cuser)) flash[:notice] = t(:server_update) redirect_to @server else diff --git a/app/controllers/shoutmsgs_controller.rb b/app/controllers/shoutmsgs_controller.rb index e381842..b1b5631 100644 --- a/app/controllers/shoutmsgs_controller.rb +++ b/app/controllers/shoutmsgs_controller.rb @@ -14,7 +14,7 @@ class ShoutmsgsController < ApplicationController end def create - @shoutmsg = Shoutmsg.new params[:shoutmsg] + @shoutmsg = Shoutmsg.new(Shoutmsg.params(params, cuser)) @shoutmsg.user = cuser raise AccessError unless @shoutmsg.can_create? cuser diff --git a/app/controllers/teamers_controller.rb b/app/controllers/teamers_controller.rb index a482d80..fdb66ba 100644 --- a/app/controllers/teamers_controller.rb +++ b/app/controllers/teamers_controller.rb @@ -4,8 +4,8 @@ class TeamersController < ApplicationController def create @old_application = (cuser.teamers.joining.count == 0) ? nil : cuser.teamers.joining.first - @teamer = Teamer.new params[:teamer] - raise AccessError unless @teamer.can_create? cuser, params[:teamer] + @teamer = Teamer.new(Teamer.params(params, cuser)) + raise AccessError unless @teamer.can_create?(cuser, Teamer.params(params, cuser)) @teamer.user = cuser unless cuser.admin? if @teamer.save diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index ec081bf..6cf409e 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -24,7 +24,7 @@ class TeamsController < ApplicationController end def create - @team = Team.new params[:team] + @team = Team.new(Team.params(params, cuser)) @team.founder = cuser raise AccessError unless @team.can_create? cuser @@ -38,7 +38,7 @@ class TeamsController < ApplicationController def update raise AccessError unless @team.can_update? cuser - if @team.update_attributes params[:team] + if @team.update_attributes(Team.params(params, cuser)) if params[:rank] @team.teamers.present.each do |member| # Contains new rank as given by submitted parameters diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index f5f4044..fd77f1c 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -42,7 +42,7 @@ class TopicsController < ApplicationController end def create - @topic = Topic.new(params[:topic]) + @topic = Topic.new(Topic.params(params, cuser)) @topic.user = cuser raise AccessError unless @topic.can_create? cuser diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0952b63..cb4ae4e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -53,7 +53,8 @@ class UsersController < ApplicationController end def create - @user = User.new params[:user] + @user = User.new(User.params(params, cuser)) + # FIXME: move to model @user.lastvisit = Date.today @user.lastip = request.env['REMOTE_ADDR'] @@ -72,8 +73,9 @@ class UsersController < ApplicationController def update raise AccessError unless @user.can_update? cuser + # FIXME: use permit params[:user].delete(:username) unless @user.can_change_name? cuser - if @user.update_attributes params[:user] + if @user.update_attributes(User.params(params, cuser)) flash[:notice] = t(:users_update) redirect_to_back else @@ -127,10 +129,6 @@ class UsersController < ApplicationController private - def user_params - params.require(:user).permit(:raw_password, :firstname, :lastname, :email, :steamid, :country, :birthdate, :timezone, :public_email, :filter) - end - def get_user @user = User.find(params[:id]) end diff --git a/app/controllers/votes_controller.rb b/app/controllers/votes_controller.rb index 052925d..5ea7c85 100644 --- a/app/controllers/votes_controller.rb +++ b/app/controllers/votes_controller.rb @@ -1,6 +1,6 @@ class VotesController < ApplicationController def create - @vote = Vote.new(params[:vote]) + @vote = Vote.new(Vote.params(params, cuser)) @vote.user = cuser raise AccessError unless @vote.can_create? cuser diff --git a/app/controllers/weeks_controller.rb b/app/controllers/weeks_controller.rb index fd8687d..65ada05 100644 --- a/app/controllers/weeks_controller.rb +++ b/app/controllers/weeks_controller.rb @@ -12,7 +12,7 @@ class WeeksController < ApplicationController end def create - @week = Week.new(params[:week]) + @week = Week.new(Weeks.params(params, cuser)) raise AccessError unless @week.can_create? cuser if @week.save @@ -26,7 +26,7 @@ class WeeksController < ApplicationController def update raise AccessError unless @week.can_update? cuser - if @week.update_attributes(params[:week]) + if @week.update_attributes(Week.params(params, cuser)) flash[:notice] = t(:weeks_update) redirect_to @week.contest else diff --git a/app/models/article.rb b/app/models/article.rb index 49fba25..20f7e54 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -3,16 +3,23 @@ # Table name: articles # # id :integer not null, primary key -# title :string(255) # status :integer not null -# category_id :integer # text :text(16777215) -# user_id :integer +# text_coding :integer default("0"), not null +# text_parsed :text(16777215) +# title :string(255) +# version :integer # created_at :datetime # updated_at :datetime -# version :integer -# text_parsed :text(16777215) -# text_coding :integer default(0), not null +# category_id :integer +# user_id :integer +# +# Indexes +# +# index_articles_on_category_id (category_id) +# index_articles_on_created_at (created_at) +# index_articles_on_created_at_and_status (created_at,status) +# index_articles_on_user_id (user_id) # class Article < ActiveRecord::Base diff --git a/app/models/ban.rb b/app/models/ban.rb index bf5c406..b0ea5c0 100755 --- a/app/models/ban.rb +++ b/app/models/ban.rb @@ -3,17 +3,24 @@ # Table name: bans # # id :integer not null, primary key -# steamid :string(255) -# user_id :integer # addr :string(255) -# server_id :integer +# ban_type :integer # expiry :datetime +# ip :string(255) # reason :string(255) +# steamid :string(255) # created_at :datetime # updated_at :datetime -# ban_type :integer -# ip :string(255) # creator_id :integer +# server_id :integer +# user_id :integer +# +# Indexes +# +# index_bans_on_creator_id (creator_id) +# index_bans_on_server_id (server_id) +# index_bans_on_user_id (user_id) +# class Ban < ActiveRecord::Base include Extra @@ -96,4 +103,8 @@ class Ban < ActiveRecord::Base def can_destroy? cuser cuser and (cuser.admin? or (self.creator == cuser and cuser.allowed_to_ban?)) end + + def self.params params, cuser + params.require(:ban).permit(:steamid, :user_id, :addr, :server_id, :expiry, :reason, :ban_type, :ip) + end end diff --git a/app/models/bracket.rb b/app/models/bracket.rb index 605708b..9cb8c8f 100644 --- a/app/models/bracket.rb +++ b/app/models/bracket.rb @@ -3,11 +3,15 @@ # Table name: brackets # # id :integer not null, primary key -# contest_id :integer +# name :string(255) # slots :integer # created_at :datetime # updated_at :datetime -# name :string(255) +# contest_id :integer +# +# Indexes +# +# index_brackets_on_contest_id (contest_id) # class Bracket < ActiveRecord::Base @@ -78,4 +82,8 @@ class Bracket < ActiveRecord::Base def can_destroy? cuser cuser and cuser.admin? end + + def self.params params, cuser + params.require(:bracket).permit(:contest_id, :slots, :name) + end end diff --git a/app/models/bracketer.rb b/app/models/bracketer.rb index 6ca06db..07db263 100644 --- a/app/models/bracketer.rb +++ b/app/models/bracketer.rb @@ -3,13 +3,18 @@ # Table name: bracketers # # id :integer not null, primary key -# bracket_id :integer # column :integer # row :integer -# match_id :integer -# team_id :integer # created_at :datetime # updated_at :datetime +# bracket_id :integer +# match_id :integer +# team_id :integer +# +# Indexes +# +# index_bracketers_on_match_id (match_id) +# index_bracketers_on_team_id (team_id) # class Bracketer < ActiveRecord::Base diff --git a/app/models/category.rb b/app/models/category.rb index 06e4935..ca3e7c9 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -3,11 +3,16 @@ # Table name: categories # # id :integer not null, primary key +# domain :integer # name :string(255) # sort :integer # created_at :datetime # updated_at :datetime -# domain :integer +# +# Indexes +# +# index_categories_on_domain (domain) +# index_categories_on_sort (sort) # class Category < ActiveRecord::Base @@ -79,4 +84,8 @@ class Category < ActiveRecord::Base def can_destroy? cuser cuser and cuser.admin? end + + def self.params(params, cuser) + params.require(:ban).permit(:name, :sort, :domain) + end end diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 70cc879..d518c6d 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -3,20 +3,29 @@ # Table name: challenges # # id :integer not null, primary key -# contester1_id :integer -# contester2_id :integer -# match_time :datetime # default_time :datetime -# mandatory :boolean -# server_id :integer -# user_id :integer # details :string(255) +# mandatory :boolean +# match_time :datetime # response :string(255) +# status :integer default("0"), not null # created_at :datetime # updated_at :datetime +# contester1_id :integer +# contester2_id :integer # map1_id :string(255) # map2_id :string(255) -# status :integer default(0), not null +# server_id :integer +# user_id :integer +# +# Indexes +# +# index_challenges_on_contester1_id (contester1_id) +# index_challenges_on_contester2_id (contester2_id) +# index_challenges_on_map1_id (map1_id) +# index_challenges_on_map2_id (map2_id) +# index_challenges_on_server_id (server_id) +# index_challenges_on_user_id (user_id) # class Challenge < ActiveRecord::Base @@ -256,4 +265,8 @@ class Challenge < ActiveRecord::Base def can_destroy? cuser cuser and (contester1.team.is_leader? cuser or cuser.admin?) and status == STATUS_PENDING# and autodefault.future? end + + def self.params params, cuser + params.require(:challenge).permit(:contester1_id, :contester2_id, :match_time, :mandatory, :server_id, :details, :response, :map1_id, :map2_id) + end end diff --git a/app/models/comment.rb b/app/models/comment.rb index e16cb7a..feae503 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -3,13 +3,20 @@ # Table name: comments # # id :integer not null, primary key -# text :text -# user_id :integer # commentable_type :string(255) -# commentable_id :integer +# text :text(65535) +# text_parsed :text(65535) # created_at :datetime # updated_at :datetime -# text_parsed :text +# commentable_id :integer +# user_id :integer +# +# Indexes +# +# index_comments_on_commentable_type (commentable_type) +# index_comments_on_commentable_type_and_commentable_id (commentable_type,commentable_id) +# index_comments_on_commentable_type_and_id (commentable_type,id) +# index_comments_on_user_id (user_id) # class Comment < ActiveRecord::Base @@ -58,4 +65,8 @@ class Comment < ActiveRecord::Base def can_destroy? cuser cuser and cuser.admin? end + + def self.params params, cuser + params.require(:ban).permit(:text, :user_id, :commentable_type, :commentable_id) + end end diff --git a/app/models/contest.rb b/app/models/contest.rb index 6cc2565..cc5e9ef 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -3,23 +3,30 @@ # Table name: contests # # id :integer not null, primary key -# name :string(255) -# start :datetime +# contest_type :integer default("0"), not null +# default_time :time # end :datetime +# modulus_3to1 :float(24) +# modulus_4to0 :float(24) +# modulus_base :integer +# modulus_even :float(24) +# name :string(255) +# short_name :string(255) +# start :datetime # status :integer +# weight :integer # created_at :datetime # updated_at :datetime -# default_time :time -# contest_type :integer default(0), not null -# winner_id :integer # demos_id :integer -# short_name :string(255) -# weight :integer -# modulus_base :integer -# modulus_even :float -# modulus_3to1 :float -# modulus_4to0 :float # rules_id :integer +# winner_id :integer +# +# Indexes +# +# index_contests_on_demos_id (demos_id) +# index_contests_on_rules_id (rules_id) +# index_contests_on_status (status) +# index_contests_on_winner_id (winner_id) # class Contest < ActiveRecord::Base @@ -139,4 +146,11 @@ class Contest < ActiveRecord::Base def can_destroy? cuser cuser and cuser.admin? end + + def self.params params, cuser + params.require(:contest).permit(:name, :start, :end, :status, :default_time, + :contest_type, :winner_id, :demos_id, :short_name, + :weight, :modulus_base, :modulus_even, + :modulus_3to1, :modulus_4to0, :rules_id) + end end diff --git a/app/models/contester.rb b/app/models/contester.rb index 7d9c271..f2f25ec 100644 --- a/app/models/contester.rb +++ b/app/models/contester.rb @@ -3,17 +3,22 @@ # Table name: contesters # # id :integer not null, primary key -# team_id :integer +# active :boolean default("1"), not null +# draw :integer default("0"), not null +# extra :integer not null +# loss :integer default("0"), not null +# score :integer default("0"), not null +# trend :integer not null +# win :integer default("0"), not null # created_at :datetime # updated_at :datetime -# score :integer default(0), not null -# win :integer default(0), not null -# loss :integer default(0), not null -# draw :integer default(0), not null # contest_id :integer -# trend :integer not null -# extra :integer not null -# active :boolean default(TRUE), not null +# team_id :integer +# +# Indexes +# +# index_contesters_on_contest_id (contest_id) +# index_contesters_on_team_id (team_id) # class Contester < ActiveRecord::Base @@ -121,4 +126,8 @@ class Contester < ActiveRecord::Base def can_destroy? cuser cuser and team.is_leader? cuser or cuser.admin? end + + def self.params params, cuser + params.require(:contester).permit(:team_id, :score, :win, :lowss, :draw, :contest_id, :active, :extra) + end end diff --git a/app/models/custom_url.rb b/app/models/custom_url.rb index 231ceee..9bf5081 100644 --- a/app/models/custom_url.rb +++ b/app/models/custom_url.rb @@ -1,3 +1,20 @@ +# == Schema Information +# +# Table name: custom_urls +# +# id :integer not null, primary key +# name :string(255) +# created_at :datetime not null +# updated_at :datetime not null +# article_id :integer +# +# Indexes +# +# index_custom_urls_on_article_id (article_id) +# index_custom_urls_on_name (name) +# + +# FIXME: move this to a gem class CustomUrl < ActiveRecord::Base belongs_to :article # FIXME: attr_accessible :name @@ -9,4 +26,8 @@ class CustomUrl < ActiveRecord::Base validates :article_id, presence: true -end + + def self.params(params, cuser) + params.require(:custom_url).permit(:name, :article_id) + end +end \ No newline at end of file diff --git a/app/models/data_file.rb b/app/models/data_file.rb index 0009ad9..2a70721 100644 --- a/app/models/data_file.rb +++ b/app/models/data_file.rb @@ -3,16 +3,22 @@ # Table name: data_files # # id :integer not null, primary key -# name :string(255) # description :string(255) +# md5 :string(255) +# name :string(255) # path :string(255) # size :integer not null -# md5 :string(255) # created_at :datetime # updated_at :datetime +# article_id :integer # directory_id :integer # related_id :integer -# article_id :integer +# +# Indexes +# +# index_data_files_on_article_id (article_id) +# index_data_files_on_directory_id (directory_id) +# index_data_files_on_related_id (related_id) # require 'digest/md5' @@ -150,4 +156,8 @@ class DataFile < ActiveRecord::Base def can_destroy? cuser cuser and cuser.admin? or (article and article.can_create? cuser) end + + def self.params(params, cuser) + params.require(:data_file).permit(:description, :name, :article_id, :related_id, :directory_id) + end end diff --git a/app/models/directory.rb b/app/models/directory.rb index 89764bf..3e2057a 100644 --- a/app/models/directory.rb +++ b/app/models/directory.rb @@ -1,15 +1,20 @@ + # == Schema Information # # Table name: directories # # id :integer not null, primary key -# name :string(255) # description :string(255) +# hidden :boolean default("0"), not null +# name :string(255) # path :string(255) # created_at :datetime # updated_at :datetime # parent_id :integer -# hidden :boolean default(FALSE), not null +# +# Indexes +# +# index_directories_on_parent_id (parent_id) # class Directory < ActiveRecord::Base @@ -59,7 +64,7 @@ class Directory < ActiveRecord::Base def update_timestamp self.created_at = File.mtime(path) if File.exists?(path) end - + def remove_files files.each do |subdir| subdir.destroy @@ -113,4 +118,8 @@ class Directory < ActiveRecord::Base def can_destroy? cuser cuser and cuser.admin? end + + def self.params(params, cuser) + params.require(:directory).permit(:description, :hidden, :name, :parent_id) + end end diff --git a/app/models/forum.rb b/app/models/forum.rb index 1234d2b..f5c1c7c 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -3,12 +3,16 @@ # Table name: forums # # id :integer not null, primary key -# title :string(255) # description :string(255) -# category_id :integer +# position :integer +# title :string(255) # created_at :datetime # updated_at :datetime -# position :integer +# category_id :integer +# +# Indexes +# +# index_forums_on_category_id (category_id) # class Forum < ActiveRecord::Base @@ -78,4 +82,7 @@ class Forum < ActiveRecord::Base id IN (SELECT q.id from (#{Forum.public_forums.to_sql}) q )") end + def self.params(params, cuser) + params.require(:data_file).permit(:description, :position, :title, :category_id) + end end diff --git a/app/models/forumer.rb b/app/models/forumer.rb index 1f767c1..923049d 100644 --- a/app/models/forumer.rb +++ b/app/models/forumer.rb @@ -3,11 +3,16 @@ # Table name: forumers # # id :integer not null, primary key -# forum_id :integer -# group_id :integer # access :integer # created_at :datetime # updated_at :datetime +# forum_id :integer +# group_id :integer +# +# Indexes +# +# index_forumers_on_forum_id (forum_id) +# index_forumers_on_group_id (group_id) # class Forumer < ActiveRecord::Base @@ -36,4 +41,8 @@ class Forumer < ActiveRecord::Base def accesses {ACCESS_READ => "Read", ACCESS_REPLY => "Reply", ACCESS_TOPIC => "Post a Topic"} end + + def self.params(params, cuser) + params.require(:forumer).permit(:access, :forum_id, :group_id) + end end diff --git a/app/models/gather.rb b/app/models/gather.rb index bd165bc..ae7d8ae 100644 --- a/app/models/gather.rb +++ b/app/models/gather.rb @@ -3,19 +3,27 @@ # Table name: gathers # # id :integer not null, primary key +# lastpick1 :datetime +# lastpick2 :datetime # status :integer +# turn :integer +# votes :integer default("0"), not null +# created_at :datetime +# updated_at :datetime # captain1_id :integer # captain2_id :integer +# category_id :integer # map1_id :integer # map2_id :integer # server_id :integer -# created_at :datetime -# updated_at :datetime -# turn :integer -# lastpick1 :datetime -# lastpick2 :datetime -# votes :integer default(0), not null -# category_id :integer +# +# Indexes +# +# index_gathers_on_captain1_id (captain1_id) +# index_gathers_on_captain2_id (captain2_id) +# index_gathers_on_map1_id (map1_id) +# index_gathers_on_map2_id (map2_id) +# index_gathers_on_server_id (server_id) # class Gather < ActiveRecord::Base @@ -192,4 +200,8 @@ class Gather < ActiveRecord::Base game.gathers.ordered.first end end + + def self.params(params, cuser) + params.require(:gather).permit(:status, :captain1_id, :captain2_id, :map1_id, :map2_id, :server_id) + end end diff --git a/app/models/gather_map.rb b/app/models/gather_map.rb index e63ab4a..d5816be 100644 --- a/app/models/gather_map.rb +++ b/app/models/gather_map.rb @@ -3,9 +3,14 @@ # Table name: gather_maps # # id :integer not null, primary key +# votes :integer # gather_id :integer # map_id :integer -# votes :integer +# +# Indexes +# +# index_gather_maps_on_gather_id (gather_id) +# index_gather_maps_on_map_id (map_id) # class GatherMap < ActiveRecord::Base diff --git a/app/models/gatherer.rb b/app/models/gatherer.rb index ed8e6dd..d5bf740 100644 --- a/app/models/gatherer.rb +++ b/app/models/gatherer.rb @@ -3,13 +3,19 @@ # Table name: gatherers # # id :integer not null, primary key -# user_id :integer -# gather_id :integer +# status :integer default("0"), not null # team :integer +# votes :integer default("0"), not null # created_at :datetime # updated_at :datetime -# votes :integer default(0), not null -# status :integer default(0), not null +# gather_id :integer +# user_id :integer +# +# Indexes +# +# index_gatherers_on_gather_id (gather_id) +# index_gatherers_on_updated_at_and_gather_id (updated_at,gather_id) +# index_gatherers_on_user_id (user_id) # class Gatherer < ActiveRecord::Base @@ -163,4 +169,8 @@ class Gatherer < ActiveRecord::Base def can_destroy? cuser cuser and ((user == cuser or cuser.admin? or cuser.gather_moderator?) and gather.status == Gather::STATE_RUNNING) end + + def self.params(params, cuser) + params.require(:gatherer).permit(:status, :user_id, :gather_id, :team, :votes) + end end diff --git a/app/models/group.rb b/app/models/group.rb index 699d096..f260184 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -8,6 +8,10 @@ # updated_at :datetime # founder_id :integer # +# Indexes +# +# index_groups_on_founder_id (founder_id) +# class Group < ActiveRecord::Base include Extra @@ -24,7 +28,6 @@ class Group < ActiveRecord::Base GATHER_MODERATORS = 14 CONTRIBUTORS = 16 - #attr_protected :id, :updated_at, :created_at, :founder_id validates_length_of :name, :maximum => 20 has_and_belongs_to_many :users @@ -118,4 +121,8 @@ class Group < ActiveRecord::Base end contributors end + + def self.params(params, cuser) + params.require(:gather).permit(:task) + end end diff --git a/app/models/grouper.rb b/app/models/grouper.rb index bb2bd59..b181bfa 100644 --- a/app/models/grouper.rb +++ b/app/models/grouper.rb @@ -3,11 +3,16 @@ # Table name: groupers # # id :integer not null, primary key -# group_id :integer -# user_id :integer # task :string(255) # created_at :datetime # updated_at :datetime +# group_id :integer +# user_id :integer +# +# Indexes +# +# index_groupers_on_group_id (group_id) +# index_groupers_on_user_id (user_id) # class Grouper < ActiveRecord::Base @@ -44,4 +49,6 @@ class Grouper < ActiveRecord::Base def can_destroy? cuser cuser and cuser.admin? end + + end diff --git a/app/models/issue.rb b/app/models/issue.rb index 237d2cf..f0ad319 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -3,16 +3,22 @@ # Table name: issues # # id :integer not null, primary key -# title :string(255) +# solution :text(65535) # status :integer -# assigned_id :integer -# category_id :integer -# text :text -# author_id :integer +# text :text(65535) +# text_parsed :text(65535) +# title :string(255) # created_at :datetime # updated_at :datetime -# solution :text -# text_parsed :text +# assigned_id :integer +# author_id :integer +# category_id :integer +# +# Indexes +# +# index_issues_on_assigned_id (assigned_id) +# index_issues_on_author_id (author_id) +# index_issues_on_category_id (category_id) # class Issue < ActiveRecord::Base @@ -126,5 +132,8 @@ class Issue < ActiveRecord::Base allowed end - + def self.params(params, cuser) + params.require(:issue).permit(:solution, :status, :text, :title, + :assigned_id, :author_id, :category_id) + end end diff --git a/app/models/lock.rb b/app/models/lock.rb index f852e01..064ddc5 100644 --- a/app/models/lock.rb +++ b/app/models/lock.rb @@ -3,10 +3,14 @@ # Table name: locks # # id :integer not null, primary key -# lockable_id :integer # lockable_type :string(255) # created_at :datetime # updated_at :datetime +# lockable_id :integer +# +# Indexes +# +# index_locks_on_lockable_id_and_lockable_type (lockable_id,lockable_type) # class Lock < ActiveRecord::Base @@ -20,4 +24,8 @@ class Lock < ActiveRecord::Base def can_destroy? cuser cuser and cuser.admin? end + + def self.params(params, cuser) + params.require(:lock).permit(:lockable_type, :lockable_id) + end end diff --git a/app/models/map.rb b/app/models/map.rb index ac8e29d..88f090a 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -3,12 +3,12 @@ # Table name: maps # # id :integer not null, primary key -# name :string(255) +# deleted :boolean default("0"), not null # download :string(255) +# name :string(255) +# picture :string(255) # created_at :datetime # updated_at :datetime -# deleted :boolean default(FALSE), not null -# picture :string(255) # category_id :integer # @@ -50,4 +50,8 @@ class Map < ActiveRecord::Base def can_destroy? cuser cuser and cuser.admin? end + + def self.params(params, cuser) + params.require(:map).permit(:name, :download, :picture, :category_id) + end end diff --git a/app/models/match.rb b/app/models/match.rb index 69e8b1a..69910b8 100755 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -3,29 +3,46 @@ # Table name: matches # # id :integer not null, primary key -# contester1_id :integer -# contester2_id :integer -# score1 :integer -# score2 :integer -# match_time :datetime -# challenge_id :integer -# contest_id :integer -# report :text -# created_at :datetime -# updated_at :datetime -# map1_id :integer -# map2_id :integer -# server_id :integer -# motm_id :integer -# demo_id :integer -# week_id :integer -# referee_id :integer -# forfeit :boolean # diff :integer +# forfeit :boolean +# match_time :datetime # points1 :integer # points2 :integer -# hltv_id :integer +# report :text(65535) +# score1 :integer +# score2 :integer +# created_at :datetime +# updated_at :datetime # caster_id :string(255) +# challenge_id :integer +# contest_id :integer +# contester1_id :integer +# contester2_id :integer +# demo_id :integer +# hltv_id :integer +# map1_id :integer +# map2_id :integer +# motm_id :integer +# referee_id :integer +# server_id :integer +# week_id :integer +# +# Indexes +# +# index_matches_on_challenge_id (challenge_id) +# index_matches_on_contest_id (contest_id) +# index_matches_on_contester1_id (contester1_id) +# index_matches_on_contester2_id (contester2_id) +# index_matches_on_demo_id (demo_id) +# index_matches_on_hltv_id (hltv_id) +# index_matches_on_map1_id (map1_id) +# index_matches_on_map2_id (map2_id) +# index_matches_on_match_time (match_time) +# index_matches_on_motm_id (motm_id) +# index_matches_on_referee_id (referee_id) +# index_matches_on_score1_and_score2 (score1,score2) +# index_matches_on_server_id (server_id) +# index_matches_on_week_id (week_id) # class Match < ActiveRecord::Base @@ -361,4 +378,9 @@ class Match < ActiveRecord::Base def user_in_match?(user) user && (user.team == contester1.team || user.team == contester2.team) end + + def self.params(params, cuser) + # FIXME: check this + params.require(:match).permit(:diff, :forfeit, :match_time, :points1, :points2, :report, :score1, :score2, :caster_id, :challenge_id, :contest_id, :contester1_id, :contester2_id, :demo_id, :hltv_id, :map1_id, :map2_id, :motm_id, :referee_id, :server_Id, :week_id) + end end diff --git a/app/models/match_proposal.rb b/app/models/match_proposal.rb index b04db86..bf42226 100644 --- a/app/models/match_proposal.rb +++ b/app/models/match_proposal.rb @@ -1,3 +1,17 @@ +# == Schema Information +# +# Table name: match_proposals +# +# id :integer not null, primary key +# proposed_time :datetime +# status :integer +# match_id :integer +# team_id :integer +# +# Indexes +# +# index_match_proposals_on_status (status) +# class MatchProposal < ActiveRecord::Base STATUS_PENDING = 0 @@ -84,4 +98,7 @@ class MatchProposal < ActiveRecord::Base end end + def self.params(params, cuser) + params.require(:match_proposal).permit(:status, :match_id, :team_id, :proposed_time) + end end diff --git a/app/models/matcher.rb b/app/models/matcher.rb index e491ff0..fb19657 100644 --- a/app/models/matcher.rb +++ b/app/models/matcher.rb @@ -3,12 +3,18 @@ # Table name: matchers # # id :integer not null, primary key -# match_id :integer not null -# user_id :integer not null -# contester_id :integer not null +# merc :boolean not null # created_at :datetime # updated_at :datetime -# merc :boolean not null +# contester_id :integer not null +# match_id :integer not null +# user_id :integer not null +# +# Indexes +# +# index_matchers_on_contester_id (contester_id) +# index_matchers_on_match_id (match_id) +# index_matchers_on_user_id (user_id) # class Matcher < ActiveRecord::Base diff --git a/app/models/message.rb b/app/models/message.rb index 8c89770..6edad89 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -3,15 +3,20 @@ # Table name: messages # # id :integer not null, primary key -# sender_type :string(255) -# sender_id :integer # recipient_type :string(255) -# recipient_id :integer +# sender_type :string(255) +# text :text(65535) +# text_parsed :text(65535) # title :string(255) -# text :text # created_at :datetime # updated_at :datetime -# text_parsed :text +# recipient_id :integer +# sender_id :integer +# +# Indexes +# +# index_messages_on_recipient_id_and_recipient_type (recipient_id,recipient_type) +# index_messages_on_sender_id_and_sender_type (sender_id,sender_type) # class Message < ActiveRecord::Base @@ -90,4 +95,9 @@ class Message < ActiveRecord::Base def can_create? cuser cuser and !cuser.banned?(Ban::TYPE_MUTE) end + + def self.params(params, cuser) + # FIXME: check this + params.require(:message).permit(:recipient_type, :sender_type, :title, :text, :recipient_id, :sender_id) + end end diff --git a/app/models/movie.rb b/app/models/movie.rb index 0702c98..566ff4d 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -3,19 +3,27 @@ # Table name: movies # # id :integer not null, primary key -# name :string(255) # content :string(255) # format :string(255) -# user_id :integer -# file_id :integer +# length :integer +# name :string(255) +# picture :string(255) +# status :integer # created_at :datetime # updated_at :datetime -# picture :string(255) -# preview_id :integer -# length :integer -# match_id :integer -# status :integer # category_id :integer +# file_id :integer +# match_id :integer +# preview_id :integer +# user_id :integer +# +# Indexes +# +# index_movies_on_file_id (file_id) +# index_movies_on_match_id (match_id) +# index_movies_on_preview_id (preview_id) +# index_movies_on_status (status) +# index_movies_on_user_id (user_id) # # Rails.root.join('lib/plugins/acts_as_rateable/init.rb') @@ -100,75 +108,79 @@ class Movie < ActiveRecord::Base # self.file.save! # make_stream #end -end - -def make_preview x, y - result = file.full_path.gsub(/\.\w{3}$/, "") + "_preview.mp4" - params = "-vcodec libx264 -vpre hq -b 1200k -bt 1200k -acodec libmp3lame -ab 128k -ac 2" - cmd = "#{SCREEN} -d -m #{FFMPEG} -y -i \"#{file.full_path}\" #{params} \"#{result}\"" - system cmd - cmd -end - -def make_snapshot secs - image = File.join(Rails.root, "public", "images", MOVIES, id.to_s + ".png") - params = "-ss #{secs} -vcodec png -vframes 1 -an -f rawvideo -s 160x120" - Movie.update_all({:picture => "#{id}.png"}, {:id => id}) - cmd = "#{FFMPEG} -y -i \"#{file.full_path}\" #{params} \"#{image}\"" - system cmd - cmd -end - -def make_stream - ip = stream_ip.match(/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/)[0] - port = stream_port.match(/[0-9]{1,5}/)[0] - cmd = "#{SCREEN} -d -m #{VLC} http://#{ip}:#{port} --sout \"#duplicate{dst=std{access=file,mux=mp4,dst=#{file.full_path}},dst=std{access=http,mux=ts,dst=#{LOCAL}}}\" vlc://quit" - system cmd - update_attribute :status, $?.pid - cmd -end - -def self.filter_or_all order, filter - order = case order - when "date" then "data_files.created_at DESC" - when "author" then "users.username ASC" - when "ratings" then "total_ratings DESC" - else "total_ratings DESC" end - # FIXME: use new system - #movies = [] - #if filter - # Movie.index.order(order).each do |movie| - # if movie.file and movie.file.average_rating_round >= filter.to_i - # movies << movie - # end - # end - # return movies - #else - return with_ratings.order(order) + def make_preview x, y + result = file.full_path.gsub(/\.\w{3}$/, "") + "_preview.mp4" + params = "-vcodec libx264 -vpre hq -b 1200k -bt 1200k -acodec libmp3lame -ab 128k -ac 2" + cmd = "#{SCREEN} -d -m #{FFMPEG} -y -i \"#{file.full_path}\" #{params} \"#{result}\"" + system cmd + cmd + end + + def make_snapshot secs + image = File.join(Rails.root, "public", "images", MOVIES, id.to_s + ".png") + params = "-ss #{secs} -vcodec png -vframes 1 -an -f rawvideo -s 160x120" + Movie.update_all({:picture => "#{id}.png"}, {:id => id}) + cmd = "#{FFMPEG} -y -i \"#{file.full_path}\" #{params} \"#{image}\"" + system cmd + cmd + end + + def make_stream + ip = stream_ip.match(/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/)[0] + port = stream_port.match(/[0-9]{1,5}/)[0] + cmd = "#{SCREEN} -d -m #{VLC} http://#{ip}:#{port} --sout \"#duplicate{dst=std{access=file,mux=mp4,dst=#{file.full_path}},dst=std{access=http,mux=ts,dst=#{LOCAL}}}\" vlc://quit" + system cmd + update_attribute :status, $?.pid + cmd + end + + def self.filter_or_all order, filter + order = case order + when "date" then "data_files.created_at DESC" + when "author" then "users.username ASC" + when "ratings" then "total_ratings DESC" + else "total_ratings DESC" + end + + # FIXME: use new system + #movies = [] + #if filter + # Movie.index.order(order).each do |movie| + # if movie.file and movie.file.average_rating_round >= filter.to_i + # movies << movie + # end + # end + # return movies + #else + return with_ratings.order(order) + #end + end + + #def update_status + # if status and status > 0 + # begin + # Process.getpgid(status) != -1 + # rescue Errno::ESRCH + # update_attribute :status, 0 + # end + # end #end -end -#def update_status -# if status and status > 0 -# begin -# Process.getpgid(status) != -1 -# rescue Errno::ESRCH -# update_attribute :status, 0 -# end -# end -#end + def can_create? cuser + cuser and cuser.admin? or cuser.groups.exists? :id => Group::MOVIES + end -def can_create? cuser - cuser and cuser.admin? or cuser.groups.exists? :id => Group::MOVIES -end + def can_update? cuser + cuser and cuser.admin? or user == cuser + end -def can_update? cuser - cuser and cuser.admin? or user == cuser -end + def can_destroy? cuser + cuser and cuser.admin? + end -def can_destroy? cuser - cuser and cuser.admin? -end + def self.params(params, cuser) + params.require(:movie).permit(:content, :format, :length, :name, :picture, :status, :category_id, :file_id, :match_id, :preview_id, :user_id) + end end diff --git a/app/models/option.rb b/app/models/option.rb index 2964088..21caf65 100644 --- a/app/models/option.rb +++ b/app/models/option.rb @@ -4,10 +4,14 @@ # # id :integer not null, primary key # option :string(255) -# poll_id :integer +# votes :integer default("0"), not null # created_at :datetime # updated_at :datetime -# votes :integer default(0), not null +# poll_id :integer +# +# Indexes +# +# index_options_on_poll_id (poll_id) # class Option < ActiveRecord::Base @@ -23,4 +27,9 @@ class Option < ActiveRecord::Base def to_s self.option end + + def self.params(params, cuser) + # FIXME: check this + params.require(:option).permit(:option, :votes, :poll_id) + end end diff --git a/app/models/poll.rb b/app/models/poll.rb index b529702..48d0150 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -3,12 +3,16 @@ # Table name: polls # # id :integer not null, primary key -# question :string(255) # end_date :datetime -# user_id :integer +# question :string(255) +# votes :integer default("0"), not null # created_at :datetime # updated_at :datetime -# votes :integer default(0), not null +# user_id :integer +# +# Indexes +# +# index_polls_on_user_id (user_id) # class Poll < ActiveRecord::Base @@ -42,4 +46,8 @@ class Poll < ActiveRecord::Base def can_destroy? cuser cuser and cuser.admin? end + + def self.params(params, cuser) + params.require(:poll).permit(:end_date, :question) + end end diff --git a/app/models/post.rb b/app/models/post.rb index 617fee7..bea1d17 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -3,12 +3,17 @@ # Table name: posts # # id :integer not null, primary key -# text :text -# topic_id :integer -# user_id :integer +# text :text(65535) +# text_parsed :text(65535) # created_at :datetime # updated_at :datetime -# text_parsed :text +# topic_id :integer +# user_id :integer +# +# Indexes +# +# index_posts_on_topic_id (topic_id) +# index_posts_on_user_id (user_id) # class Post < ActiveRecord::Base @@ -65,4 +70,9 @@ class Post < ActiveRecord::Base def can_destroy? cuser cuser and cuser.admin? end + + def self.params(params, cuser) + # FIXME: check this + params.require(:post).permit(:text, :topic_id) + end end diff --git a/app/models/prediction.rb b/app/models/prediction.rb index 604431e..7a2ec0d 100644 --- a/app/models/prediction.rb +++ b/app/models/prediction.rb @@ -3,13 +3,18 @@ # Table name: predictions # # id :integer not null, primary key -# match_id :integer -# user_id :integer +# result :integer # score1 :integer # score2 :integer # created_at :datetime # updated_at :datetime -# result :integer +# match_id :integer +# user_id :integer +# +# Indexes +# +# index_predictions_on_match_id (match_id) +# index_predictions_on_user_id (user_id) # class Prediction < ActiveRecord::Base @@ -30,4 +35,8 @@ class Prediction < ActiveRecord::Base def can_create? cuser cuser and match.match_time.future? and !match.score1 and !match.score2 and !cuser.predictions.exists?(:match_id => match.id) end + + def self.params(params, cuser) + params.require(:prediction).permit(:result, :score1, :score2, :match_id, :user_id) + end end diff --git a/app/models/profile.rb b/app/models/profile.rb index 8e3b305..dea5252 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -3,57 +3,61 @@ # Table name: profiles # # id :integer not null, primary key -# user_id :integer -# msn :string(255) +# achievements :text(65535) +# achievements_parsed :string(400) +# avatar :string(255) +# beverage :string(255) +# book :string(255) +# case :string(255) +# clan_search :string(255) +# cpu :string(255) +# food :string(255) +# gpu :string(255) +# hdd :string(255) +# head_phones :string(255) +# hobby :string(255) # icq :string(255) # irc :string(255) -# web :string(255) -# town :string(255) -# singleplayer :string(255) -# multiplayer :string(255) -# food :string(255) -# beverage :string(255) -# hobby :string(255) -# music :string(255) -# book :string(255) -# movie :string(255) -# tvseries :string(255) -# res :string(255) -# sensitivity :string(255) -# monitor_hz :string(255) -# scripts :string(255) -# cpu :string(255) -# gpu :string(255) -# ram :string(255) -# psu :string(255) -# motherboard :string(255) -# soundcard :string(255) -# hdd :string(255) -# case :string(255) +# keyboard :string(255) +# layout :string(255) # monitor :string(255) +# monitor_hz :string(255) +# motherboard :string(255) # mouse :string(255) # mouse_pad :string(255) -# keyboard :string(255) -# head_phones :string(255) -# speakers :string(255) -# achievements :text -# updated_at :datetime -# signature :string(255) -# avatar :string(255) -# clan_search :string(255) -# notify_news :boolean -# notify_articles :boolean -# notify_movies :boolean -# notify_gather :boolean -# notify_own_match :boolean +# movie :string(255) +# msn :string(255) +# multiplayer :string(255) +# music :string(255) # notify_any_match :boolean -# notify_pms :boolean default(TRUE), not null -# notify_challenge :boolean default(TRUE), not null +# notify_articles :boolean +# notify_challenge :boolean default("1"), not null +# notify_gather :boolean +# notify_movies :boolean +# notify_news :boolean +# notify_own_match :boolean +# notify_pms :boolean default("1"), not null +# psu :string(255) +# ram :string(255) +# res :string(255) +# scripts :string(255) +# sensitivity :string(255) +# signature :string(255) +# signature_parsed :text(65535) +# singleplayer :string(255) +# soundcard :string(255) +# speakers :string(255) # steam_profile :string(255) -# achievements_parsed :string(255) -# signature_parsed :string(255) # stream :string(255) -# layout :string(255) +# town :string(255) +# tvseries :string(255) +# web :string(255) +# updated_at :datetime +# user_id :integer +# +# Indexes +# +# index_profiles_on_user_id (user_id) # class Profile < ActiveRecord::Base @@ -97,4 +101,10 @@ class Profile < ActiveRecord::Base self.achievements_parsed = bbcode_to_html(achievements) if self.achievements self.signature_parsed = bbcode_to_html(signature) if self.signature end + + def self.params(params, cuser) + # FIXME: check this, add user_id + # TEST + params.require(:profile).except!(:id, :updated_at).permit! + end end diff --git a/app/models/server.rb b/app/models/server.rb index b366b4a..039b777 100644 --- a/app/models/server.rb +++ b/app/models/server.rb @@ -3,31 +3,37 @@ # Table name: servers # # id :integer not null, primary key -# name :string(255) +# active :boolean default("1"), not null # description :string(255) # dns :string(255) +# domain :integer default("0"), not null +# idle :datetime # ip :string(255) -# port :string(255) -# password :string(255) # irc :string(255) -# user_id :integer +# map :string(255) +# max_players :integer +# name :string(255) # official :boolean +# password :string(255) +# ping :string(255) +# players :integer +# port :string(255) +# recordable_type :string(255) +# recording :string(255) +# reservation :string(255) +# version :integer # created_at :datetime # updated_at :datetime -# map :string(255) -# players :integer -# max_players :integer -# ping :string(255) -# version :integer -# domain :integer default(0), not null -# reservation :string(255) -# recording :string(255) -# idle :datetime -# default_id :integer -# active :boolean default(TRUE), not null -# recordable_type :string(255) -# recordable_id :integer # category_id :integer +# default_id :integer +# recordable_id :integer +# user_id :integer +# +# Indexes +# +# index_servers_on_default_id (default_id) +# index_servers_on_players_and_domain (players,domain) +# index_servers_on_user_id (user_id) # require "yaml" @@ -138,4 +144,10 @@ class Server < ActiveRecord::Base hltv.save! end end + + def self.params(params, cuser) + # FIXME: check this, add user_id + # TEST + params.require(:server).except!(:id, :created_at, :user_id, :map, :players, :maxplayers, :ping, :version, :updated_at).permit! + end end diff --git a/app/models/shoutmsg.rb b/app/models/shoutmsg.rb index a35722a..a7bc712 100644 --- a/app/models/shoutmsg.rb +++ b/app/models/shoutmsg.rb @@ -3,12 +3,17 @@ # Table name: shoutmsgs # # id :integer not null, primary key -# user_id :integer +# shoutable_type :string(255) # text :string(255) # created_at :datetime # updated_at :datetime -# shoutable_type :string(255) # shoutable_id :integer +# user_id :integer +# +# Indexes +# +# index_shoutmsgs_on_shoutable_type_and_shoutable_id (shoutable_type,shoutable_id) +# index_shoutmsgs_on_user_id (user_id) # class Shoutmsg < ActiveRecord::Base @@ -49,4 +54,8 @@ class Shoutmsg < ActiveRecord::Base end return true end + + def self.params(params, cuser) + params.require(:shoutmsg).permit(:shoutable_id, :shoutable_type, :text) + end end diff --git a/app/models/team.rb b/app/models/team.rb index 7f602ba..611e1da 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -2,19 +2,24 @@ # # Table name: teams # -# id :integer not null, primary key -# name :string(255) -# irc :string(255) -# web :string(255) -# tag :string(255) -# country :string(255) -# comment :string(255) -# created_at :datetime -# updated_at :datetime -# logo :string(255) -# founder_id :integer -# active :boolean default(TRUE), not null -# recruiting :string(255) +# id :integer not null, primary key +# active :boolean default("1"), not null +# comment :string(255) +# country :string(255) +# irc :string(255) +# logo :string(255) +# name :string(255) +# recruiting :string(255) +# tag :string(255) +# teamers_count :integer +# web :string(255) +# created_at :datetime +# updated_at :datetime +# founder_id :integer +# +# Indexes +# +# index_teams_on_founder_id (founder_id) # class Team < ActiveRecord::Base @@ -126,4 +131,8 @@ class Team < ActiveRecord::Base def can_destroy? cuser cuser and cuser.admin? end + + def self.params(params, cuser) + params.require(:team).except(:id, :active, :founder_id, :created_at, :updated_at).permit! + end end diff --git a/app/models/teamer.rb b/app/models/teamer.rb index 48c47b0..90068e6 100644 --- a/app/models/teamer.rb +++ b/app/models/teamer.rb @@ -3,12 +3,17 @@ # Table name: teamers # # id :integer not null, primary key -# team_id :integer not null -# user_id :integer not null # comment :string(255) # rank :integer not null # created_at :datetime # updated_at :datetime +# team_id :integer not null +# user_id :integer not null +# +# Indexes +# +# index_teamers_on_team_id (team_id) +# index_teamers_on_user_id (user_id) # class Teamer < ActiveRecord::Base @@ -92,4 +97,8 @@ class Teamer < ActiveRecord::Base def can_destroy? cuser cuser and (user == cuser or team.is_leader? cuser or cuser.admin?) end + + def self.params(params, cuser) + params.require(:teamer).permit(:comment, :rank, :team_id, :user_id) + end end diff --git a/app/models/topic.rb b/app/models/topic.rb index 840b30b..1345d36 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -3,12 +3,17 @@ # Table name: topics # # id :integer not null, primary key +# state :integer default("0"), not null # title :string(255) -# user_id :integer -# forum_id :integer # created_at :datetime # updated_at :datetime -# state :integer default(0), not null +# forum_id :integer +# user_id :integer +# +# Indexes +# +# index_topics_on_forum_id (forum_id) +# index_topics_on_user_id (user_id) # class Topic < ActiveRecord::Base @@ -122,4 +127,8 @@ class Topic < ActiveRecord::Base def states {STATE_NORMAL => "Normal", STATE_STICKY => "Sticky"} end + + def self.params(params, cuser) + params.permit(:state, :title, :forum_id, :user_id) + end end diff --git a/app/models/user.rb b/app/models/user.rb index bfe60dd..96d4ad1 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,22 +3,27 @@ # Table name: users # # id :integer not null, primary key -# username :string(255) -# password :string(255) -# firstname :string(255) -# lastname :string(255) +# birthdate :date +# country :string(255) # email :string(255) -# steamid :string(255) -# team_id :integer +# firstname :string(255) +# lastip :string(255) +# lastname :string(255) # lastvisit :datetime +# password :string(255) +# public_email :boolean default("0"), not null +# steamid :string(255) +# time_zone :string(255) +# username :string(255) +# version :integer # created_at :datetime # updated_at :datetime -# lastip :string(255) -# country :string(255) -# birthdate :date -# time_zone :string(255) -# version :integer -# public_email :boolean default(FALSE), not null +# team_id :integer +# +# Indexes +# +# index_users_on_lastvisit (lastvisit) +# index_users_on_team_id (team_id) # require 'digest/md5' @@ -181,6 +186,10 @@ class User < ActiveRecord::Base a end + def idle + "%d m" % [TimeDifference.between(DateTime.now, lastvisit).in_minutes.floor] + end + def current_layout profile.layout || 'default' end @@ -344,4 +353,8 @@ class User < ActiveRecord::Base def self.casters Group.find(Group::CASTERS).users.order(:username) end + + def self.params(params, cuser) + params.require(:user).permit(:raw_password, :firstname, :lastname, :email, :steamid, :country, :birthdate, :timezone, :public_email, :filter) + end end diff --git a/app/models/view_count.rb b/app/models/view_count.rb index 4944415..fa9201a 100644 --- a/app/models/view_count.rb +++ b/app/models/view_count.rb @@ -3,11 +3,15 @@ # Table name: view_counts # # id :integer not null, primary key -# viewable_id :integer -# viewable_type :string(255) # ip_address :string(255) # logged_in :boolean +# viewable_type :string(255) # created_at :date +# viewable_id :integer +# +# Indexes +# +# index_view_counts_on_viewable_type_and_viewable_id (viewable_type,viewable_id) # class ViewCount < ActiveRecord::Base diff --git a/app/models/vote.rb b/app/models/vote.rb index ec6bdd5..2d60c60 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -3,10 +3,15 @@ # Table name: votes # # id :integer not null, primary key +# votable_type :string(255) +# poll_id :integer # user_id :integer # votable_id :integer -# poll_id :integer -# votable_type :string(255) +# +# Indexes +# +# index_votes_on_user_id (user_id) +# index_votes_on_votable_id_and_votable_type (votable_id,votable_type) # class Vote < ActiveRecord::Base @@ -65,4 +70,8 @@ class Vote < ActiveRecord::Base return true end + + def self.params(params, cuser) + params.require(:vote).permit(:votable_type, :votable_id, :poll_id, :user_id) + end end diff --git a/app/models/week.rb b/app/models/week.rb index 61c35f8..d58d843 100644 --- a/app/models/week.rb +++ b/app/models/week.rb @@ -5,11 +5,17 @@ # id :integer not null, primary key # name :string(255) # start_date :date +# created_at :datetime +# updated_at :datetime # contest_id :integer # map1_id :integer # map2_id :integer -# created_at :datetime -# updated_at :datetime +# +# Indexes +# +# index_weeks_on_contest_id (contest_id) +# index_weeks_on_map1_id (map1_id) +# index_weeks_on_map2_id (map2_id) # class Week < ActiveRecord::Base @@ -42,4 +48,8 @@ class Week < ActiveRecord::Base def can_destroy? cuser cuser and cuser.admin? end + + def self.params(params, cuser) + params.require(:week).permit(:name, :start_date, :contest_id, :map1_id, :map2_id) + end end diff --git a/app/views/gathers/_running.html.erb b/app/views/gathers/_running.html.erb index 529e917..5347d18 100644 --- a/app/views/gathers/_running.html.erb +++ b/app/views/gathers/_running.html.erb @@ -9,6 +9,7 @@ 0 %> class="away"<% end %>> <%= flag gatherer.user.country %> <%= namelink gatherer.user %> + ( <%= gatherer.user.idle %> ) <% if cuser and gatherer.can_destroy?(cuser) %> <%= link_to gatherer, method: :delete, class: 'delete' do %> <%= icon 'times' %> diff --git a/lib/tasks/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake new file mode 100644 index 0000000..e96283e --- /dev/null +++ b/lib/tasks/auto_annotate_models.rake @@ -0,0 +1,59 @@ +# NOTE: only doing this in development as some production environments (Heroku) +# NOTE: are sensitive to local FS writes, and besides -- it's just not proper +# NOTE: to have a dev-mode tool do its thing in production. +if Rails.env.development? + require 'annotate' + task :set_annotation_options do + # You can override any of these by setting an environment variable of the + # same name. + Annotate.set_defaults( + 'active_admin' => 'false', + 'additional_file_patterns' => [], + 'routes' => 'false', + 'models' => 'true', + 'position_in_routes' => 'before', + 'position_in_class' => 'before', + 'position_in_test' => 'before', + 'position_in_fixture' => 'before', + 'position_in_factory' => 'before', + 'position_in_serializer' => 'before', + 'show_foreign_keys' => 'true', + 'show_complete_foreign_keys' => 'false', + 'show_indexes' => 'true', + 'simple_indexes' => 'false', + 'model_dir' => 'app/models', + 'root_dir' => '', + 'include_version' => 'false', + 'require' => '', + 'exclude_tests' => 'false', + 'exclude_fixtures' => 'false', + 'exclude_factories' => 'false', + 'exclude_serializers' => 'false', + 'exclude_scaffolds' => 'true', + 'exclude_controllers' => 'true', + 'exclude_helpers' => 'true', + 'exclude_sti_subclasses' => 'false', + 'ignore_model_sub_dir' => 'false', + 'ignore_columns' => nil, + 'ignore_routes' => nil, + 'ignore_unknown_models' => 'false', + 'hide_limit_column_types' => 'integer,bigint,boolean', + 'hide_default_column_types' => 'json,jsonb,hstore', + 'skip_on_db_migrate' => 'false', + 'format_bare' => 'true', + 'format_rdoc' => 'false', + 'format_yard' => 'false', + 'format_markdown' => 'false', + 'sort' => 'false', + 'force' => 'false', + 'frozen' => 'false', + 'classified_sort' => 'true', + 'trace' => 'false', + 'wrapper_open' => nil, + 'wrapper_close' => nil, + 'with_comment' => 'true' + ) + end + + Annotate.load_tasks +end diff --git a/spec/models/ban_spec.rb b/spec/models/ban_spec.rb index 460090c..35dee42 100644 --- a/spec/models/ban_spec.rb +++ b/spec/models/ban_spec.rb @@ -3,16 +3,23 @@ # Table name: bans # # id :integer not null, primary key -# steamid :string(255) -# user_id :integer # addr :string(255) -# server_id :integer +# ban_type :integer # expiry :datetime +# ip :string(255) # reason :string(255) +# steamid :string(255) # created_at :datetime # updated_at :datetime -# ban_type :integer -# ip :string(255) +# creator_id :integer +# server_id :integer +# user_id :integer +# +# Indexes +# +# index_bans_on_creator_id (creator_id) +# index_bans_on_server_id (server_id) +# index_bans_on_user_id (user_id) # require "rails_helper" diff --git a/spec/models/forum_spec.rb b/spec/models/forum_spec.rb index daa7edd..c4e4426 100644 --- a/spec/models/forum_spec.rb +++ b/spec/models/forum_spec.rb @@ -3,12 +3,16 @@ # Table name: forums # # id :integer not null, primary key -# title :string(255) # description :string(255) -# category_id :integer +# position :integer +# title :string(255) # created_at :datetime # updated_at :datetime -# position :integer +# category_id :integer +# +# Indexes +# +# index_forums_on_category_id (category_id) # require "rails_helper" diff --git a/spec/models/forumer_spec.rb b/spec/models/forumer_spec.rb index 48a2a4e..484d6c6 100644 --- a/spec/models/forumer_spec.rb +++ b/spec/models/forumer_spec.rb @@ -3,11 +3,16 @@ # Table name: forumers # # id :integer not null, primary key -# forum_id :integer -# group_id :integer # access :integer # created_at :datetime # updated_at :datetime +# forum_id :integer +# group_id :integer +# +# Indexes +# +# index_forumers_on_forum_id (forum_id) +# index_forumers_on_group_id (group_id) # require "rails_helper" diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 0072971..c7093ff 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -3,16 +3,22 @@ # Table name: issues # # id :integer not null, primary key -# title :string(255) +# solution :text(65535) # status :integer -# assigned_id :integer -# category_id :integer -# text :text -# author_id :integer +# text :text(65535) +# text_parsed :text(65535) +# title :string(255) # created_at :datetime # updated_at :datetime -# solution :text -# text_parsed :text +# assigned_id :integer +# author_id :integer +# category_id :integer +# +# Indexes +# +# index_issues_on_assigned_id (assigned_id) +# index_issues_on_author_id (author_id) +# index_issues_on_category_id (category_id) # require "rails_helper" diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index c980cfc..ffccc07 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -3,15 +3,20 @@ # Table name: messages # # id :integer not null, primary key -# sender_type :string(255) -# sender_id :integer # recipient_type :string(255) -# recipient_id :integer +# sender_type :string(255) +# text :text(65535) +# text_parsed :text(65535) # title :string(255) -# text :text # created_at :datetime # updated_at :datetime -# text_parsed :text +# recipient_id :integer +# sender_id :integer +# +# Indexes +# +# index_messages_on_recipient_id_and_recipient_type (recipient_id,recipient_type) +# index_messages_on_sender_id_and_sender_type (sender_id,sender_type) # require "rails_helper" diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index eac28c0..ee37dc4 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -3,12 +3,17 @@ # Table name: posts # # id :integer not null, primary key -# text :text -# topic_id :integer -# user_id :integer +# text :text(65535) +# text_parsed :text(65535) # created_at :datetime # updated_at :datetime -# text_parsed :text +# topic_id :integer +# user_id :integer +# +# Indexes +# +# index_posts_on_topic_id (topic_id) +# index_posts_on_user_id (user_id) # require "rails_helper" diff --git a/spec/models/server_spec.rb b/spec/models/server_spec.rb index d385c82..14a8caa 100644 --- a/spec/models/server_spec.rb +++ b/spec/models/server_spec.rb @@ -3,31 +3,37 @@ # Table name: servers # # id :integer not null, primary key -# name :string(255) +# active :boolean default("1"), not null # description :string(255) # dns :string(255) +# domain :integer default("0"), not null +# idle :datetime # ip :string(255) -# port :string(255) -# password :string(255) # irc :string(255) -# user_id :integer +# map :string(255) +# max_players :integer +# name :string(255) # official :boolean +# password :string(255) +# ping :string(255) +# players :integer +# port :string(255) +# recordable_type :string(255) +# recording :string(255) +# reservation :string(255) +# version :integer # created_at :datetime # updated_at :datetime -# map :string(255) -# players :integer -# max_players :integer -# ping :string(255) -# version :integer -# domain :integer default(0), not null -# reservation :string(255) -# recording :string(255) -# idle :datetime -# default_id :integer -# active :boolean default(TRUE), not null -# recordable_type :string(255) -# recordable_id :integer # category_id :integer +# default_id :integer +# recordable_id :integer +# user_id :integer +# +# Indexes +# +# index_servers_on_default_id (default_id) +# index_servers_on_players_and_domain (players,domain) +# index_servers_on_user_id (user_id) # require "rails_helper" diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 437c409..d196443 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -3,12 +3,17 @@ # Table name: topics # # id :integer not null, primary key +# state :integer default("0"), not null # title :string(255) -# user_id :integer -# forum_id :integer # created_at :datetime # updated_at :datetime -# state :integer default(0), not null +# forum_id :integer +# user_id :integer +# +# Indexes +# +# index_topics_on_forum_id (forum_id) +# index_topics_on_user_id (user_id) # require "spec_helper" diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b89d3aa..9a7ba72 100755 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -3,23 +3,27 @@ # Table name: users # # id :integer not null, primary key -# username :string(255) -# password :string(255) -# firstname :string(255) -# lastname :string(255) +# birthdate :date +# country :string(255) # email :string(255) -# steamid :string(255) -# team_id :integer +# firstname :string(255) +# lastip :string(255) +# lastname :string(255) # lastvisit :datetime +# password :string(255) +# public_email :boolean default("0"), not null +# steamid :string(255) +# time_zone :string(255) +# username :string(255) +# version :integer # created_at :datetime # updated_at :datetime -# lastip :string(255) -# country :string(255) -# birthdate :date -# time_zone :string(255) -# version :integer -# public_email :boolean default(FALSE), not null -# salt :string(255) +# team_id :integer +# +# Indexes +# +# index_users_on_lastvisit (lastvisit) +# index_users_on_team_id (team_id) # require 'rails_helper'