From 9b2ba68551af16fa719e8165befd727179ad7c77 Mon Sep 17 00:00:00 2001 From: Prommah Date: Tue, 3 Nov 2015 07:50:14 +0000 Subject: [PATCH 1/9] Add new user API spec --- .../api/v1/users_controller_spec.rb | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/spec/controllers/api/v1/users_controller_spec.rb b/spec/controllers/api/v1/users_controller_spec.rb index 2dd4380..da03ea8 100755 --- a/spec/controllers/api/v1/users_controller_spec.rb +++ b/spec/controllers/api/v1/users_controller_spec.rb @@ -78,9 +78,23 @@ describe Api::V1::UsersController do end it "returns 404 if user does not exist" do - expect { - get :show, id: -1 - }.to raise_error(ActionController::RoutingError) + expect { get :show, id: -1 }.to raise_error(ActionController::RoutingError) + end + + it "returns 404 if user does not exist by steamid" do + expect { get :show, id: -1, format: "steamid" }.to raise_error(ActionController::RoutingError) + end + + it "queries the steam condenser for an invalid steamid" do + @user.update_attribute(:steamid, "0:0:0") + + get :show, id: @user.id + + expect(response).to be_success + expect(json["steam"]).to_not be_nil + expect(json["steam"]["id"]).to eq(@user.steamid) + expect(json["steam"]["url"]).to be_nil + expect(json["steam"]["nickname"]).to be_nil end it "returns correct ban if user muted" do From a460020a3e42aaae21e34c71304a0f90cbf863ef Mon Sep 17 00:00:00 2001 From: Prommah Date: Tue, 3 Nov 2015 08:41:25 +0000 Subject: [PATCH 2/9] Clean up Verification lib --- lib/verification.rb | 101 +++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 52 deletions(-) mode change 100644 => 100755 lib/verification.rb diff --git a/lib/verification.rb b/lib/verification.rb old mode 100644 new mode 100755 index 1820152..1d6063d --- a/lib/verification.rb +++ b/lib/verification.rb @@ -1,63 +1,60 @@ module Verification - def Verification.verify input - md5 = Digest::MD5.hexdigest("9WvcZ9hX" + input + "KF7L4luQ").upcase.split(//) - chars = ["A", "B", "C", "D", "E", "F"] - nums = [] - lastPos = md5[31].to_i - result = "" + def self.verify(input) + md5 = Digest::MD5.hexdigest("9WvcZ9hX" + input + "KF7L4luQ").upcase.split(//) + chars = %w[A B C D E F] + nums = [] + last_pos = md5[31].to_i + result = "" - for i in 0..9 - pos = md5[i].to_i + (0..9).each do |i| + pos = md5[i].to_i - if pos == 0 - pos = lastPos ** (i % 4) - elsif (pos % 4) == 0 - pos = pos * lastPos + i - elsif (pos % 3) == 0 - pos = pos ** (i % 4) - elsif (pos % 2) == 0 - pos = pos * i + pos - end + if pos == 0 + pos = last_pos**(i % 4) + elsif (pos % 4) == 0 + pos = pos * last_pos + i + elsif (pos % 3) == 0 + pos **= (i % 4) + elsif pos.even? + pos = pos * i + pos + end - pos = (pos > 31) ? (pos % 32) : pos - curChar = md5[31 - pos] - curNum = curChar.to_i + pos = (pos > 31) ? (pos % 32) : pos + cur_char = md5[31 - pos] + cur_num = cur_char.to_i - if nums.include? curNum - if curNum == 0 - curChar = chars[pos % 6] - else - curChar = (pos % 10).to_s - end - curNum = curChar.to_i - end + if nums.include? cur_num + if cur_num == 0 + cur_char = chars[pos % 6] + else + cur_char = (pos % 10).to_s + end + cur_num = cur_char.to_i + end - nums << curNum - result << curChar - lastPos = pos - end + nums << cur_num + result << cur_char + last_pos = pos + end - return result - end + result + end - def Verification.uncrap str - str.to_s.gsub(/[^A-Za-z0-9_\-]/, "") - end + def self.uncrap(str) + str.to_s.gsub(/[^A-Za-z0-9_\-]/, "") + end - def Verification.random_string len - chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a - str = "" - 1.upto(len) do |i| - str << chars[rand(chars.size-1)] - end - return str - end + def self.random_string(len) + chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a + str = "" + 1.upto(len) do + str << chars[rand(chars.size - 1)] + end + str + end # TODO: rikki? - def Verification.contain params, filter - (params.instance_of?(Array) ? params : params.keys).each do |key| - return false unless filter.include? key.to_sym - end - return true - end -end \ No newline at end of file + def self.contain(params, filter) + params.instance_of?(Array) ? (filter - params).empty? : filter.all? { |s| params.key? s } + end +end From 0b347baee7f7c35e7736ff52c355ed273bf3ceb6 Mon Sep 17 00:00:00 2001 From: Prommah Date: Tue, 3 Nov 2015 11:46:11 +0000 Subject: [PATCH 3/9] Revert Verification.contain --- lib/verification.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/verification.rb b/lib/verification.rb index 1d6063d..5b70264 100755 --- a/lib/verification.rb +++ b/lib/verification.rb @@ -54,7 +54,11 @@ module Verification end # TODO: rikki? + # Returns true if params (or its keys) are a subset of filter def self.contain(params, filter) - params.instance_of?(Array) ? (filter - params).empty? : filter.all? { |s| params.key? s } + (params.instance_of?(Array) ? params : params.keys).each do |key| + return false unless filter.include? key.to_sym + end + true end end From 9ef8b7a24bf34fd22cbae69a301f1c10d5db114d Mon Sep 17 00:00:00 2001 From: Prommah Date: Wed, 4 Nov 2015 14:17:57 +0000 Subject: [PATCH 4/9] Remove disused & hidden match score page --- app/controllers/matches_controller.rb | 6 ----- app/views/matches/score.html.erb | 37 --------------------------- 2 files changed, 43 deletions(-) mode change 100644 => 100755 app/controllers/matches_controller.rb delete mode 100644 app/views/matches/score.html.erb diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb old mode 100644 new mode 100755 index 5066916..8e0ea0c --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -24,12 +24,6 @@ class MatchesController < ApplicationController def extra end - def score - raise AccessError unless @match.can_update? cuser, [:matchers_attributes] - @contester = @match.contester1.team.is_leader?(cuser) ? @match.contester1 : @match.contester2 - @n = 0 - end - def ref raise AccessError unless @match.can_update? cuser, [:report] @n = 0 diff --git a/app/views/matches/score.html.erb b/app/views/matches/score.html.erb deleted file mode 100644 index ff1d9a0..0000000 --- a/app/views/matches/score.html.erb +++ /dev/null @@ -1,37 +0,0 @@ -

- <%= namelink @match.contester1.team %> vs <%= namelink @match.contester2.team %> -

- -
-

- Lineup -

- <%= form_for @match do |f| %> - <%= render :partial => "lineup", :locals => {:contester => @contester} %> -

- <%= f.submit "Save" %> -

- <% end %> -
- -<% if @match.can_update? cuser, [:score1, :score2] %> -
- <%= form_for(@match) do |f| %> -

- Scoring -

- - <%= f.error_messages %> -

- <%= f.label :score1, "Score" %>
- <%= f.text_field :score1, :size => 1 %> - <%= f.text_field :score2, :size => 1 %> -

-

- <%= f.submit 'Submit' %> -

- <% end %> -
-<% end %> - -<%= link_to "Back", @match %> From 7bbb1a1fb18b7d041488242393d3a8445d760229 Mon Sep 17 00:00:00 2001 From: Prommah Date: Wed, 4 Nov 2015 14:26:32 +0000 Subject: [PATCH 5/9] Clean up Verification.contain --- lib/verification.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/verification.rb b/lib/verification.rb index 5b70264..ebab58c 100755 --- a/lib/verification.rb +++ b/lib/verification.rb @@ -56,9 +56,6 @@ module Verification # TODO: rikki? # Returns true if params (or its keys) are a subset of filter def self.contain(params, filter) - (params.instance_of?(Array) ? params : params.keys).each do |key| - return false unless filter.include? key.to_sym - end - true + ((params.instance_of?(Array) ? params : params.keys) - filter).empty? end end From a4f4f074aea1a1b55dec6979ddb84219556c03ca Mon Sep 17 00:00:00 2001 From: Prommah Date: Thu, 5 Nov 2015 07:57:55 +0000 Subject: [PATCH 6/9] Cleaned up match model --- app/models/match.rb | 264 +++++++++++++++++++++++--------------------- 1 file changed, 137 insertions(+), 127 deletions(-) mode change 100644 => 100755 app/models/match.rb diff --git a/app/models/match.rb b/app/models/match.rb old mode 100644 new mode 100755 index 1059d07..50f2dc1 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -38,119 +38,118 @@ class Match < ActiveRecord::Base attr_accessor :lineup, :method, :motm_name, :friendly attr_protected :id, :updated_at, :created_at, :diff, :points1, :points2 - has_many :matchers, :dependent => :destroy - has_many :users, :through => :matchers - has_many :predictions, :dependent => :destroy - has_many :comments, :as => :commentable, :order => "created_at", :dependent => :destroy + has_many :matchers, dependent: :destroy + has_many :users, through: :matchers + has_many :predictions, dependent: :destroy + has_many :comments, as: :commentable, order: "created_at", dependent: :destroy belongs_to :challenge belongs_to :contest - belongs_to :contester1, :class_name => "Contester", :include => 'team' - belongs_to :contester2, :class_name => "Contester", :include => 'team' - belongs_to :map1, :class_name => "Map" - belongs_to :map2, :class_name => "Map" + belongs_to :contester1, class_name: "Contester", include: "team" + belongs_to :contester2, class_name: "Contester", include: "team" + belongs_to :map1, class_name: "Map" + belongs_to :map2, class_name: "Map" belongs_to :server - belongs_to :referee, :class_name => "User" - belongs_to :motm, :class_name => "User" - belongs_to :demo, :class_name => "DataFile" + belongs_to :referee, class_name: "User" + belongs_to :motm, class_name: "User" + belongs_to :demo, class_name: "DataFile" belongs_to :week - belongs_to :hltv, :class_name => "Server" - belongs_to :stream, :class_name => "Movie" - belongs_to :caster, :class_name => "User" + belongs_to :hltv, class_name: "Server" + belongs_to :stream, class_name: "Movie" + belongs_to :caster, class_name: "User" - scope :future, :conditions => ["match_time > UTC_TIMESTAMP()"] - scope :future5, :conditions => ["match_time > UTC_TIMESTAMP()"], :limit => 5 - scope :finished, :conditions => ["score1 != 0 OR score2 != 0"] - scope :realfinished, :conditions => ["score1 IS NOT NULL AND score2 IS NOT NULL"] - scope :unfinished, :conditions => ["score1 IS NULL AND score2 IS NULL"] - scope :unreffed, :conditions => ["referee_id IS NULL"] - scope :ordered, :order => "match_time DESC" - scope :chrono, :order => "match_time ASC" - scope :recent, :limit => "8" - scope :bigrecent, :limit => "50" - scope :active, :conditions => ["contest_id IN (?)", Contest.active] + scope :future, conditions: ["match_time > UTC_TIMESTAMP()"] + scope :future5, conditions: ["match_time > UTC_TIMESTAMP()"], limit: 5 + scope :finished, conditions: ["score1 != 0 OR score2 != 0"] + scope :realfinished, conditions: ["score1 IS NOT NULL AND score2 IS NOT NULL"] + scope :unfinished, conditions: ["score1 IS NULL AND score2 IS NULL"] + scope :unreffed, conditions: ["referee_id IS NULL"] + scope :ordered, order: "match_time DESC" + scope :chrono, order: "match_time ASC" + scope :recent, limit: "8" + scope :bigrecent, limit: "50" + scope :active, conditions: ["contest_id IN (?)", Contest.active] scope :on_day, - lambda { |day| { - :conditions => ["match_time > ? and match_time < ?", day.beginning_of_day, day.end_of_day]} } + ->(day) { where("match_time > ? and match_time < ?", day.beginning_of_day, day.end_of_day) } scope :on_week, - lambda { |time| { - :conditions => ["match_time > ? and match_time < ?", time.beginning_of_week, time.end_of_week]} } + lambda { |time| + where("match_time > ? and match_time < ?", time.beginning_of_week, time.end_of_week) + } scope :of_contester, - lambda { |contester| { - :conditions => ["contester1_id = ? OR contester2_id = ?", contester.id, contester.id]} } + ->contester { where("contester1_id = ? OR contester2_id = ?", contester.id, contester.id) } scope :of_user, - lambda { |user| { - :include => :matchers, - :conditions => ["matchers.user_id = ?", user.id]} } + ->user { includes(:matchers).where("matchers.user_id = ?", user.id) } scope :of_team, - lambda { |team| { - :include => {:contester1 => :team, - :contester2 => :team}, :conditions => ["teams.id = ? OR teams_contesters.id = ?", team.id, team.id]} } + lambda { |team| + includes(contester1: :team, contester2: :team) + .where("teams.id = ? OR teams_contesters.id = ?", team.id, team.id) + } scope :of_userteam, - lambda { |user, team| { - :include => {:matchers => {:contester => :team}}, - :conditions => ["teams.id = ? AND matchers.user_id = ?", team.id, user.id]} } + lambda { |user, team| + includes(matchers: { contester: :team }) + .where("teams.id = ? AND matchers.user_id = ?", team.id, user.id) + } scope :within_time, - lambda { |from, to| { - :conditions => ["match_time > ? AND match_time < ?", from.utc, to.utc]} } + ->(from, to) { where("match_time > ? AND match_time < ?", from.utc, to.utc) } scope :around, - lambda { |time| { - :conditions => ["match_time > ? AND match_time < ?", time.ago(MATCH_LENGTH).utc, time.ago(-MATCH_LENGTH).utc]} } + lambda { |time| + where("match_time > ? AND match_time < ?", + time.ago(MATCH_LENGTH).utc, time.ago(-MATCH_LENGTH).utc) + } scope :after, - lambda { |time| { - :conditions => ["match_time > ? AND match_time < ?", time.utc, time.ago(-MATCH_LENGTH).utc]} } + ->time { where("match_time > ? AND match_time < ?", time.utc, time.ago(-MATCH_LENGTH).utc) } scope :map_stats, - :select => "map1_id, COUNT(*) as num, maps.name", - :joins => "LEFT JOIN maps ON maps.id = map1_id", - :group => "map1_id", - :having => "map1_id is not null", - :order => "num DESC" + select: "map1_id, COUNT(*) as num, maps.name", + joins: "LEFT JOIN maps ON maps.id = map1_id", + group: "map1_id", + having: "map1_id is not null", + order: "num DESC" scope :year_stats, - :select => "id, DATE_FORMAT(match_time, '%Y') as year, COUNT(*) as num", - :conditions => "match_time > '2000-01-01 01:01:01'", - :group => "year", - :order => "num DESC" + select: "id, DATE_FORMAT(match_time, '%Y') as year, COUNT(*) as num", + conditions: "match_time > '2000-01-01 01:01:01'", + group: "year", + order: "num DESC" scope :month_stats, - :select => "id, DATE_FORMAT(match_time, '%m') as month_n, - DATE_FORMAT(match_time, '%M') as month, - COUNT(*) as num", - :conditions => "match_time > '2000-01-01 01:01:01'", - :group => "month", - :order => "month_n" + select: "id, DATE_FORMAT(match_time, '%m') as month_n, + DATE_FORMAT(match_time, '%M') as month, + COUNT(*) as num", + conditions: "match_time > '2000-01-01 01:01:01'", + group: "month", + order: "month_n" validates_presence_of :contester1, :contester2, :contest - validates_format_of [:score1, :score2], :with => /\A[0-9]\z/, :allow_nil => true - validates_length_of :report, :maximum => 64000, :allow_blank => true + validates_format_of [:score1, :score2], with: /\A[0-9]\z/, allow_nil: true + validates_length_of :report, maximum: 64_000, allow_blank: true before_create :set_hltv after_create :send_notifications - before_save :set_motm, :if => Proc.new {|match| match.motm_name and !match.motm_name.empty?} - before_update :reset_contest, :if => Proc.new {|match| match.score1_changed? or match.score2_changed?} + before_save :set_motm, if: proc { |match| match.motm_name && !match.motm_name.empty? } + before_update :reset_contest, if: proc { |match| match.score1_changed? || match.score2_changed? } before_destroy :reset_contest - after_save :recalculate, :if => Proc.new {|match| match.score1_changed? or match.score2_changed?} - after_save :set_predictions, :if => Proc.new {|match| match.score1_changed? or match.score2_changed?} + after_save :recalculate, if: proc { |match| match.score1_changed? || match.score2_changed? } + after_save :set_predictions, if: proc { |match| match.score1_changed? || match.score2_changed? } - accepts_nested_attributes_for :matchers, :allow_destroy => true + accepts_nested_attributes_for :matchers, allow_destroy: true def to_s contester1.to_s + " vs " + contester2.to_s end def score_color - return "black" if score1.nil? or score2.nil? or contester1.nil? or contester2.nil? + return "black" if score1.nil? || score2.nil? || contester1.nil? || contester2.nil? return "yellow" if score1 == score2 - return "green" if contester1.team == friendly and score1 > score2 - return "green" if contester2.team == friendly and score2 > score1 - return "red" if contester1.team == friendly and score1 < score2 - "red" if contester2.team == friendly and score2 < score1 + return "green" if contester1.team == friendly && score1 > score2 + return "green" if contester2.team == friendly && score2 > score1 + return "red" if contester1.team == friendly && score1 < score2 + "red" if contester2.team == friendly && score2 < score1 end - def preds contester - perc = Prediction.count(:conditions => ["match_id = ? AND score#{contester} > 2", id]) - perc != 0 ? (perc/predictions.count.to_f*100).round : 0 + def preds(contester) + perc = Prediction.count(conditions: ["match_id = ? AND score#{contester} > 2", id]) + perc != 0 ? (perc / predictions.count.to_f * 100).round : 0 end - def mercs contester - matchers.all :conditions => {:merc => true, :contester_id => contester.id} + def mercs(contester) + matchers.all conditions: { merc: true, contester_id: contester.id } end def get_hltv @@ -158,18 +157,18 @@ class Match < ActiveRecord::Base end def demo_name - Verification.uncrap(contest.short_name + "-" + self.id.to_s + "_" + contester1.to_s + "-vs-" + contester2.to_s) + Verification.uncrap("#{contest.short_name}-#{id}_#{contester1}-vs-#{contester2}") end def team1_lineup - matchers.all(:conditions => {:contester_id => contester1_id}) + matchers.all(conditions: { contester_id: contester1_id }) end def team2_lineup - matchers.all(:conditions => {:contester_id => contester2_id}) + matchers.all(conditions: { contester_id: contester2_id }) end - def get_friendly param = nil + def get_friendly(param = nil) if param.nil? friendly == contester1.team ? contester1 : contester2 elsif param == :score @@ -179,7 +178,7 @@ class Match < ActiveRecord::Base end end - def get_opponent param = nil + def get_opponent(param = nil) if param.nil? friendly == contester1.team ? contester2 : contester1 elsif param == :score @@ -194,7 +193,7 @@ class Match < ActiveRecord::Base end def send_notifications - Profile.all(:include => :user, :conditions => "notify_any_match = 1").each do |p| + Profile.all(include: :user, conditions: "notify_any_match = 1").each do |p| Notifications.match p.user, self if p.user end contester2.team.teamers.active.each do |teamer| @@ -218,10 +217,11 @@ class Match < ActiveRecord::Base contest.recalculate end - #Since ladders are broken anyway, they are not handled here + # Since ladders are broken anyway, they are not handled here def reset_contest - return if score1_was.nil? or score2_was.nil? - return if contest.contest_type == Contest::TYPE_LEAGUE and !contester2.active or !contester1.active + return if score1_was.nil? || score2_was.nil? + return if contest.contest_type == Contest::TYPE_LEAGUE && + !contester2.active || !contester1.active if score1_was == score2_was contester1.draw = contester1.draw - 1 @@ -235,16 +235,17 @@ class Match < ActiveRecord::Base end unless contest.contest_type == Contest::TYPE_BRACKET - contester1.score = contester1.score-score1_was - contester2.score = contester2.score-score2_was + contester1.score = contester1.score - score1_was + contester2.score = contester2.score - score2_was contester1.save! contester2.save! end end def recalculate - return if score1.nil? or score2.nil? - return if contest.contest_type == Contest::TYPE_LEAGUE and !contester2.active or !contester1.active + return if score1.nil? || score2.nil? + return if contest.contest_type == Contest::TYPE_LEAGUE && + !contester2.active || !contester1.active if score1 == score2 contester1.draw = contester1.draw + 1 @@ -263,7 +264,7 @@ class Match < ActiveRecord::Base contester2.trend = Contester::TREND_UP end - self.diff = diff ? diff : (contester2.score-contester1.score) + self.diff = diff ? diff : (contester2.score - contester1.score) if contest.contest_type == Contest::TYPE_LADDER self.points1 = contest.elo_score score1, score2, diff @@ -274,23 +275,24 @@ class Match < ActiveRecord::Base end if contest.contest_type == Contest::TYPE_LADDER - contester1.extra = contester1.extra + contest.modulus_base/10 - contester2.extra = contester2.extra + contest.modulus_base/10 + contester1.extra = contester1.extra + contest.modulus_base / 10 + contester2.extra = contester2.extra + contest.modulus_base / 10 end unless contest.contest_type == Contest::TYPE_BRACKET - contester1.score = contester1.score+points1 < 0 ? 0 : contester1.score+points1 - contester2.score = contester2.score+points2 < 0 ? 0 : contester2.score+points2 + contester1.score = contester1.score + points1 < 0 ? 0 : contester1.score + points1 + contester2.score = contester2.score + points2 < 0 ? 0 : contester2.score + points2 contester1.save! contester2.save! end end - def hltv_record addr, pwd - if (match_time - MATCH_LENGTH*10) > DateTime.now or (match_time + MATCH_LENGTH*10) < DateTime.now + def hltv_record(addr, pwd) + if (match_time - MATCH_LENGTH * 10) > DateTime.now || + (match_time + MATCH_LENGTH * 10) < DateTime.now raise Error, I18n.t(:hltv_request_20) end - if hltv and hltv.recording + if hltv && hltv.recording raise Error, I18n.t(:hltv_already) + hltv.addr end unless get_hltv @@ -304,47 +306,55 @@ class Match < ActiveRecord::Base hltv.save! end - def hltv_move addr, pwd - raise Error, I18n.t(:hltv_notset) if hltv.nil? or hltv.recording.nil? + def hltv_move(addr, pwd) + raise Error, I18n.t(:hltv_notset) if hltv.nil? || hltv.recording.nil? Server.move hltv.reservation, addr, pwd end def hltv_stop - raise Error, I18n.t(:hltv_notset) if hltv.nil? or hltv.recording.nil? + raise Error, I18n.t(:hltv_notset) if hltv.nil? || hltv.recording.nil? Server.stop hltv.reservation end - def can_create? cuser - cuser and cuser.admin? + def can_create?(cuser) + cuser && cuser.admin? end - def can_update? cuser, params = {} + def can_update?(cuser, params = {}) return false unless cuser return true if cuser.admin? - return true if cuser.caster? and Verification.contain params, [:caster_id] \ - and (params[:caster_id] && params[:caster_id].to_i == cuser.id && caster_id.blank?) \ - or (params[:caster_id].blank? && caster_id == cuser.id) - return true if cuser.ref? and Verification.contain params, [:referee_id] \ - and (params[:referee_id] && params[:referee_id].to_i == cuser.id && referee_id.blank?) \ - or (params[:referee_id].blank? && referee_id == cuser.id) - return true if cuser.ref? and referee == cuser \ - and Verification.contain params, [:score1, :score2, :forfeit, :report, :demo_id, :motm_name, :matchers_attributes, :server_id] - return true if match_time.past? and !score1 and !score2 and !forfeit \ - and Verification.contain(params, [:score1, :score2]) \ - and (contester1.team.is_leader? cuser or contester2.team.is_leader? cuser) - return true if match_time.today? \ - and Verification.contain(params, [:stream_id]) \ - and (contester1.team.is_leader? cuser or contester2.team.is_leader? cuser) - return true if match_time.past? \ - and Verification.contain(params, [:matchers_attributes]) \ - and (contester1.team.is_leader? cuser or contester2.team.is_leader? cuser) - return true if (cuser.ref? and referee == cuser) \ - and Verification.contain(params, [:hltv]) \ - and !demo + + if cuser.ref? + if referee == cuser + return true if Verification.contain(params, + [:score1, :score2, :forfeit, :report, :demo_id, + :motm_name, :matchers_attributes, :server_id]) + return true if Verification.contain(params, [:hltv]) && !demo + end + if Verification.contain(params, [:referee_id]) + return true if (params[:referee_id].to_i == cuser.id && referee_id.blank?) || + (params[:referee_id].blank? && referee_id == cuser.id) + end + end + + if contester1.team.is_leader?(cuser) || contester2.team.is_leader?(cuser) + if match_time.past? + return true if Verification.contain(params, [:score1, :score2]) && + !score1 && !score2 && !forfeit + return true if Verification.contain(params, [:matchers_attributes]) + end + return true if match_time.today? && Verification.contain(params, [:stream_id]) + end + + if cuser.caster? && Verification.contain(params, [:caster_id]) + return true if (params[:caster_id].to_i == cuser.id && caster_id.blank?) || + (params[:caster_id].blank? && caster_id == cuser.id) + end + false end - def can_destroy? cuser - cuser and cuser.admin? + def can_destroy?(cuser) + cuser && cuser.admin? end end From 67f603789f0a74e499947b3d4a3331bd0813981d Mon Sep 17 00:00:00 2001 From: Prommah Date: Thu, 5 Nov 2015 07:59:52 +0000 Subject: [PATCH 7/9] Fixed caster selection --- app/views/matches/admin.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 app/views/matches/admin.html.haml diff --git a/app/views/matches/admin.html.haml b/app/views/matches/admin.html.haml old mode 100644 new mode 100755 index a0e589e..047c69d --- a/app/views/matches/admin.html.haml +++ b/app/views/matches/admin.html.haml @@ -34,7 +34,7 @@ - elsif match.can_update?(cuser, {:caster_id => cuser.id}) = form_for match do |f| - if cuser.admin? - = f.collection_select :caster_id, Group.casters, :id, :username, {:include_blank => true}, {:class => "autosubmit"} + = f.collection_select :caster_id, User.casters, :id, :username, {:include_blank => true}, {:class => "autosubmit"} - else = f.hidden_field :caster_id, {:value => cuser.id} = link_to "Take!", "#form_submit" From 71424d9207ceaa5e2b00ffff3b6eb274edac3e02 Mon Sep 17 00:00:00 2001 From: Prommah Date: Thu, 5 Nov 2015 08:25:54 +0000 Subject: [PATCH 8/9] Fix rubocop offenses --- app/models/match.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/match.rb b/app/models/match.rb index 50f2dc1..c31806a 100755 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -116,9 +116,9 @@ class Match < ActiveRecord::Base group: "month", order: "month_n" - validates_presence_of :contester1, :contester2, :contest - validates_format_of [:score1, :score2], with: /\A[0-9]\z/, allow_nil: true - validates_length_of :report, maximum: 64_000, allow_blank: true + validates :contester1, :contester2, :contest, presence: true + validates :score1, :score2, format: /\A[0-9]\z/, allow_nil: true + validates :report, length: { maximum: 64_000 }, allow_blank: true before_create :set_hltv after_create :send_notifications @@ -193,7 +193,7 @@ class Match < ActiveRecord::Base end def send_notifications - Profile.all(include: :user, conditions: "notify_any_match = 1").each do |p| + Profile.all(include: :user, conditions: "notify_any_match = 1").find_each do |p| Notifications.match p.user, self if p.user end contester2.team.teamers.active.each do |teamer| @@ -288,8 +288,8 @@ class Match < ActiveRecord::Base end def hltv_record(addr, pwd) - if (match_time - MATCH_LENGTH * 10) > DateTime.now || - (match_time + MATCH_LENGTH * 10) < DateTime.now + if (match_time - MATCH_LENGTH * 10) > DateTime.now.utc || + (match_time + MATCH_LENGTH * 10) < DateTime.now.utc raise Error, I18n.t(:hltv_request_20) end if hltv && hltv.recording From 1faed511fcf342694f9456731c9d94dc5a0deece Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Fri, 6 Nov 2015 15:23:50 +0000 Subject: [PATCH 9/9] Add EU flag to teams --- app/views/teams/edit.html.erb | 2 +- app/views/teams/new.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/teams/edit.html.erb b/app/views/teams/edit.html.erb index 6d31784..d93f92c 100644 --- a/app/views/teams/edit.html.erb +++ b/app/views/teams/edit.html.erb @@ -29,7 +29,7 @@
<%= f.label :country %> - <%= country_code_select :team, :country %> + <%= country_code_select :team, :country, [['EU', 'EU']] %>
<%= f.label :comment %> diff --git a/app/views/teams/new.html.erb b/app/views/teams/new.html.erb index 07dc6f2..463fa5f 100644 --- a/app/views/teams/new.html.erb +++ b/app/views/teams/new.html.erb @@ -21,7 +21,7 @@
<%= f.label :country %> - <%= country_code_select :team, :country %> + <%= country_code_select :team, :country, [['EU', 'EU']] %>
<%= f.label :comment %>