More progress on Rails 4.1 update

Just fix scopes mostly.

Add binstubs.
This commit is contained in:
Ari Timonen 2019-06-03 15:38:24 -04:00
parent 768d3faa1b
commit ce9797aed8
20 changed files with 189 additions and 213 deletions

3
.gitignore vendored
View file

@ -20,6 +20,7 @@
/public/files/*
/public/local
/public/uploads
/public/assets/
# RubyMine
/.idea
@ -43,4 +44,4 @@ rerun.txt
pickle-email-*.html
# Direnv
.envrc
.envrc

View file

@ -10,9 +10,9 @@ class ContestsController < ApplicationController
def historical
case params[:id]
when "NS1"
@contests = Contest.with_contesters.ordered.where ["name LIKE ? OR name LIKE ?", "S%:%", "%Night%"]
@contests = Contest.all.ordered.includes(:contesters).where("name LIKE ? OR name LIKE ?", "S%:%", "%Night%")
else
@contests = Contest.with_contesters.ordered.where ["id > ?", "113"]
@contests = Contest.all.ordered.includes(:contesters).where("id > ?", "113")
end
end

View file

@ -2,7 +2,7 @@ class TeamsController < ApplicationController
before_filter :get_team, only: [:show, :edit, :update, :destroy, :recover]
def index
@teams = Team.with_teamers_num(0).search(params[:search]).paginate(per_page: 80, page: params[:page]).ordered
@teams = Team.non_empty_teams.search(params[:search]).paginate(per_page: 80, page: params[:page]).ordered
end
def show

View file

@ -35,30 +35,30 @@ class Contest < ActiveRecord::Base
attr_protected :id, :updated_at, :created_at
scope :active, :conditions => ["status != ?", STATUS_CLOSED]
scope :inactive, :conditions => {:status => STATUS_CLOSED}
scope :joinable, :conditions => {:status => STATUS_OPEN}
scope :with_contesters, :include => :contesters
scope :ordered, :order => "start DESC"
scope :nsls1, :conditions => ["name LIKE ?", "NSL S1:%"]
scope :nsls2, :conditions => ["name LIKE ?", "NSL S2:%"]
scope :ns1seasons, :conditions => ["name LIKE ?", "S%:%"]
scope :active, -> { where.not(status: STATUS_CLOSED) }
scope :inactive, -> { where(status: STATUS_CLOSED) }
scope :joinable, -> { where(status: STATUS_OPEN) }
scope :with_contesters, -> { includes(:contesters) }
scope :ordered, -> { order("start DESC") }
scope :nsls1, -> { where("name LIKE ?", "NSL S1:%") }
scope :nsls2, -> { where("name LIKE ?", "NSL S2:%") }
scope :ns1seasons, -> { where("name LIKE ?", "S%:%") }
has_many :matches, :dependent => :destroy
has_many :weeks, :dependent => :destroy
has_many :contesters, :dependent => :destroy, :include => :team
has_many :contesters, -> { includes(:team) }, :dependent => :destroy
has_many :predictions, :through => :matches
has_many :brackets
has_many :preds_with_score,
:source => :predictions,
:through => :matches,
:select => "predictions.id, predictions.user_id,
SUM(result) AS correct,
SUM(result)/COUNT(*)*100 AS score,
COUNT(*) AS total",
:conditions => "result IS NOT NULL",
:group => "predictions.user_id",
:order => "correct DESC"
has_many :preds_with_score, -> {
select("predictions.id, predictions.user_id
SUM(result) AS correct,
SUM(result)/COUNT(*)*100 AS score,
COUNT(*) AS total")
.where("result IS NOT NULL")
.group("predictions.user_id")
.order("correct DESC") },
:source => :predictions,
:through => :matches
has_and_belongs_to_many :maps
belongs_to :demos, :class_name => "Directory"
belongs_to :winner, :class_name => "Contester"

View file

@ -26,22 +26,24 @@ class Contester < ActiveRecord::Base
attr_protected :id, :updated_at, :created_at, :trend
attr_accessor :user
scope :active, :include => :team, :conditions => {"contesters.active" => true}
belongs_to :team
belongs_to :contest
scope :active, -> { includes(:team).where(active: true) }
# ranked is used for ladder. lower score the higher the rank
scope :ranked, :select => "contesters.*", :order => "score ASC, win DESC, loss ASC"
scope :ordered, :select => "contesters.*, (score + extra) AS total_score", :order => "total_score DESC, score DESC, win DESC, loss ASC"
scope :chronological, :order => "created_at DESC"
scope :of_contest, lambda { |contest| {:conditions => {"contesters.contest_id" => contest.id}} }
scope :ranked, -> { order("score ASC, win DESC, loss ASC").select("contesters.*") }
scope :ordered, -> { select("contesters.*, (score + extra) AS total_score").order("total_score DESC, score DESC, win DESC, loss ASC") }
scope :chronological, -> { order("created_at DESC") }
scope :of_contest, -> (contest) { where("contesters.contest_id", contest.id) }
has_many :challenges_sent, :class_name => "Challenge", :foreign_key => "contester1_id"
has_many :challenges_received, :class_name => "Challenge", :foreign_key => "contester2_id"
has_many :matches, :through => :contest, :conditions => "(contester1_id = contesters.id OR contester2_id = contesters.id)"
belongs_to :team
belongs_to :contest
has_many :matches, -> { where("(contester1_id = contesters.id OR contester2_id = contesters.id)") }, :through => :contest
validates_presence_of :team, :contest
validates_inclusion_of [:score, :win, :loss, :draw, :extra], :in => 0..9999, :allow_nil => true
validates_uniqueness_of :team_id, :scope => :contest_id, :message => "You can't join same contest twice."
#validate_on_create:validate_member_participation
#validate_on_create:validate_contest
#validate_on_create:validate_playernumber
@ -93,7 +95,7 @@ class Contester < ActiveRecord::Base
end
def validate_playernumber
if team.teamers.active.distinct.count < 6
if team.teamers.active.unique_by_team.count < 6
errors.add :team, I18n.t(:contests_join_need6)
end
end

View file

@ -19,13 +19,11 @@ class Forum < ActiveRecord::Base
attr_protected :id, :updated_at, :created_at
scope :public,
:select => "forums.*",
:joins => "LEFT JOIN forumers ON forumers.forum_id = forums.id AND forumers.access = #{Forumer::ACCESS_READ}",
:conditions => "forumers.id IS NULL"
scope :of_forum,
lambda { |forum| {:conditions => {"forums.id" => forum.id}} }
scope :ordered, :order => "position"
scope :public_forums, -> { select("forums.*")
.joins("LEFT JOIN forumers ON forumers.forum_id = forums.id AND forumers.access = #{Forumer::ACCESS_READ}")
.where("forumers.id IS NULL") }
scope :of_forum, -> (forum) { where("forums.id", forum.id) }
scope :ordered, -> { order("position") }
has_many :topics
has_many :posts, :through => :topics
@ -50,7 +48,7 @@ class Forum < ActiveRecord::Base
if cuser
Forum.available_to(cuser, Forumer::ACCESS_READ).of_forum(self).first
else
Forum.public.of_forum(self).first
Forum.public_forums.where(id: self.id).exists?
end
end

View file

@ -30,7 +30,7 @@ class Gather < ActiveRecord::Base
attr_accessor :admin
scope :ordered, -> { order("id DESC") }
scope :basic, -> { include(:captain1, :captain2, :map1, :map2, :server) }
scope :basic, -> { includes(:captain1, :captain2, :map1, :map2, :server) }
scope :active, -> { where("gathers.status IN (?, ?, ?) AND gathers.updated_at > ?",
STATE_VOTING, STATE_PICKING, STATE_RUNNING, 12.hours.ago.utc) }

View file

@ -41,11 +41,11 @@ class Match < ActiveRecord::Base
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 :comments, -> { order("created_at") }, :as => :commentable, :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 :contester1, -> { includes('team') }, :class_name => "Contester"
belongs_to :contester2, -> { includes('team') }, :class_name => "Contester"
belongs_to :map1, :class_name => "Map"
belongs_to :map2, :class_name => "Map"
belongs_to :server
@ -57,65 +57,41 @@ class Match < ActiveRecord::Base
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 :on_day,
lambda { |day| {
:conditions => ["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]} }
scope :of_contester,
lambda { |contester| {
:conditions => ["contester1_id = ? OR contester2_id = ?", contester.id, contester.id]} }
scope :of_user,
lambda { |user| {
:include => :matchers,
:conditions => ["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]} }
scope :of_userteam,
lambda { |user, team| {
:include => {:matchers => {:contester => :team}},
:conditions => ["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]} }
scope :around,
lambda { |time| {
:conditions => ["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]} }
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"
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"
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"
scope :future, -> { where("match_time > UTC_TIMESTAMP()") }
scope :future5, -> { where("match_time > UTC_TIMESTAMP()").limit(5) }
scope :finished, -> { where("score1 != 0 OR score2 != 0") }
scope :realfinished, -> { where("score1 IS NOT NULL AND score2 IS NOT NULL") }
scope :unfinished, -> { where("score1 IS NULL AND score2 IS NULL") }
scope :unreffed, -> { where.not(referee_id: nil) }
scope :ordered, -> { order("match_time DESC") }
scope :chrono, -> { order("match_time ASC") }
scope :recent, -> { limit("8") }
scope :bigrecent, -> { limit("50") }
scope :active, -> { where("contest_id IN (?)", Contest.active) }
scope :on_day, -> (day) { where("match_time > ? and match_time < ?", day.beginning_of_day, day.end_of_day) }
scope :on_week, -> (time) { where("match_time > ? and match_time < ?", time.beginning_of_week, time.end_of_week) }
scope :of_contester, -> (contester) { where("contester1_id = ? OR contester2_id = ?", contester.id, contester.id) }
scope :of_user, -> (user) { includes(:matchers).where("matchers.user_id = ?", user.id) }
scope :of_team, -> (team) { includes({:contester1 => :team, :contester2 => :team}).where("teams.id = ? OR teams_contesters.id = ?", team.id, team.id) }
scope :of_userteam, -> (user, team) { includes({:matchers => {:contester => :team}}).where("teams.id = ? AND matchers.user_id = ?", team.id, user.id) }
scope :within_time, -> (from, to) { where("match_time > ? AND match_time < ?", from.utc, to.utc) }
scope :around, -> (time) { where("match_time > ? AND match_time < ?", time.ago(MATCH_LENGTH).utc, time.ago(-MATCH_LENGTH).utc) }
scope :after, -> (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") }
scope :year_stats, -> { select("id, DATE_FORMAT(match_time, '%Y') as year, COUNT(*) as num").
where("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").
where("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
@ -145,12 +121,12 @@ class Match < ActiveRecord::Base
end
def preds contester
perc = Prediction.count(:conditions => ["match_id = ? AND score#{contester} > 2", id])
perc = Prediction.where("match_id = ? AND score#{contester} > 2", id).count()
perc != 0 ? (perc/predictions.count.to_f*100).round : 0
end
def mercs contester
matchers.all :conditions => {:merc => true, :contester_id => contester.id}
matchers.where(merc: true, contester_id: contester.id)
end
def get_hltv
@ -162,11 +138,11 @@ class Match < ActiveRecord::Base
end
def team1_lineup
matchers.all(:conditions => {:contester_id => contester1_id})
matchers.where(contester_id: contester1_id)
end
def team2_lineup
matchers.all(:conditions => {:contester_id => contester2_id})
matchers.where(contester_id: contester2_id)
end
def get_friendly param = nil
@ -194,7 +170,7 @@ class Match < ActiveRecord::Base
end
def send_notifications
Profile.all(:include => :user, :conditions => "notify_any_match = 1").each do |p|
Profile.where("notify_any_match", 1).includes(:user).each do |p|
Notifications.match p.user, self if p.user
end
contester2.team.teamers.active.each do |teamer|

View file

@ -18,8 +18,6 @@
# category_id :integer
#
require 'data_file'
class Movie < ActiveRecord::Base
include Extra

View file

@ -14,6 +14,8 @@
class Poll < ActiveRecord::Base
include Extra
default_scope -> { order("created_at DESC") }
attr_protected :id, :updated_at, :created_at, :votes, :user_id
validates_length_of :question, :in => 1..50

View file

@ -33,33 +33,36 @@ class Team < ActiveRecord::Base
validates_format_of :country, :with => /\A[A-Z]{2}\z/, :allow_blank => true
validates_length_of [:comment, :recruiting], :in => 0..75, :allow_blank => true
scope :with_teamers_num,
lambda { |num| {
:select => "teams.*, COUNT(T.id) AS teamers_num",
:joins => "LEFT JOIN teamers T ON T.team_id = teams.id AND T.rank >= #{Teamer::RANK_MEMBER}",
:group => "teams.id",
:having => ["teamers_num >= ?", num]} }
scope :with_teamers, :include => :teamers
scope :active, :conditions => {:active => true}
scope :inactive, :conditions => {:active => false}
scope :ordered, :order => "name"
scope :recruiting, :conditions => "recruiting IS NOT NULL AND recruiting != ''"
scope :with_teamers_num, -> (num) {
select("teams.*, COUNT(T.id) AS teamers_num").
joins("LEFT JOIN teamers T ON T.team_id = teams.id AND T.rank >= #{Teamer::RANK_MEMBER}").
group("teams.id").
having("teamers_num >= ?", num) }
scope :non_empty_teams, -> { joins(:teamers).where("teamers.rank >= #{Teamer::RANK_MEMBER}").distinct }
scope :with_teamers, -> { includes(:teamers) }
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
scope :ordered, -> { order("name") }
scope :recruiting, -> { where("recruiting IS NOT NULL AND recruiting != ''") }
belongs_to :founder, :class_name => "User"
has_many :active_teamers, -> { where("rank >= ?", Teamer::RANK_MEMBER) }
has_many :teamers, :dependent => :destroy
has_many :leaders, :class_name => "Teamer", :conditions => ["rank = ?", Teamer::RANK_LEADER]
has_many :leaders, -> { where("rank = ?", Teamer::RANK_LEADER) }, :class_name => "Teamer"
has_many :contesters, :dependent => :destroy
has_many :contests, :through => :contesters, :conditions => {"contesters.active" => true}
has_many :contests, -> { where("contesters.active", true) }, :through => :contesters
has_many :received_messages, :class_name => "Message", :as => "recipient"
has_many :sent_messages, :class_name => "Message", :as => "sender"
has_many :matches, :through => :contesters
has_many :matches_finished, :through => :contesters, :source => :matches, :conditions => "(score1 != 0 OR score2 != 0)"
has_many :matches_won, :through => :contesters, :source => :matches,
:conditions => "((score1 > score2 AND contester1_id = contesters.id) OR (score2 > score1 AND contester2_id = contesters.id)) AND (score1 != 0 OR score2 != 0)"
has_many :matches_lost, :through => :contesters, :source => :matches,
:conditions => "((score1 < score2 AND contester1_id = contesters.id) OR (score2 < score1 AND contester2_id = contesters.id)) AND (score1 != 0 OR score2 != 0)"
has_many :matches_draw, :through => :contesters, :source => :matches,
:conditions => "(score1 = score2 AND score1 > 0) AND (score1 != 0 OR score2 != 0)"
has_many :matches_finished, -> { where("(score1 != 0 OR score2 != 0)") },
:through => :contesters, :source => :matches
has_many :matches_won, -> { where("((score1 > score2 AND contester1_id = contesters.id) OR (score2 > score1 AND contester2_id = contesters.id)) AND (score1 != 0 OR score2 != 0)") },
:through => :contesters, :source => :matches
has_many :matches_lost, -> { where("((score1 < score2 AND contester1_id = contesters.id) OR (score2 < score1 AND contester2_id = contesters.id)) AND (score1 != 0 OR score2 != 0)") },
:through => :contesters, :source => :matches
has_many :matches_draw, -> { where("(score1 = score2 AND score1 > 0) AND (score1 != 0 OR score2 != 0)") },
:through => :contesters, :source => :matches
mount_uploader :logo, TeamUploader
@ -89,7 +92,7 @@ class Team < ActiveRecord::Base
end
def self.search(search)
search ? where("LOWER(name) LIKE LOWER(?)", "%#{search}%") : scoped
search ? where("LOWER(name) LIKE LOWER(?)", "%#{search}%") : all
end
def destroy

View file

@ -29,80 +29,67 @@ class Teamer < ActiveRecord::Base
#validate_on_create:validate_contests
validate :validate_team
scope :basic,
:include => :user,
:order => "rank DESC, created_at ASC"
scope :past,
:conditions => ["teamers.rank = ?", RANK_REMOVED]
scope :joining,
:conditions => ["teamers.rank = ?", RANK_JOINER]
scope :present,
:conditions => ["teamers.rank >= ?", RANK_JOINER]
scope :active,
:conditions => ["teamers.rank >= ?", RANK_MEMBER]
scope :leaders,
:conditions => ["teamers.rank >= ?", RANK_DEPUTEE]
scope :of_team,
lambda { |team| {:conditions => {"teamers.team_id" => team.id}} }
scope :active_teams,
:include => :team,
:conditions => ["teams.active = ?", true]
scope :distinct,
:group => "user_id, team_id"
scope :ordered,
:order => "rank DESC, created_at ASC"
scope :historic,
lambda { |user, time|
{:conditions => ["user_id = ? AND created_at < ? AND ((updated_at > ? AND rank = ?) OR rank >= ?)",
user.id, time.utc, time.utc, RANK_REMOVED, RANK_MEMBER]} }
scope :basic, -> { includes(:user).order("rank DESC, created_at ASC") }
scope :past, -> { where("teamers.rank = ?", RANK_REMOVED) }
scope :joining,-> { where("teamers.rank = ?", RANK_JOINER) }
scope :present, -> { where("teamers.rank >= ?", RANK_JOINER) }
scope :active, -> { where("teamers.rank >= ?", RANK_MEMBER) }
scope :leaders, -> { where("teamers.rank >= ?", RANK_DEPUTEE) }
scope :of_team, -> (team) { where("teamers.team_id" => team.id) }
scope :active_teams, -> { includes(:team).where("teams.active = ?", true) }
scope :unique_by_team, -> { group("user_id, team_id") }
scope :ordered, -> { order("rank DESC, created_at ASC") }
scope :historic, -> (user, time) {
where("user_id = ? AND created_at < ? AND ((updated_at > ? AND rank = ?) OR rank >= ?)",
user.id, time.utc, time.utc, RANK_REMOVED, RANK_MEMBER) }
belongs_to :user
belongs_to :team
has_many :other_teamers, :through => :user, :source => :teamers, :conditions => ["teamers.id != ?", object_id]
has_many :contesters, :through => :team
belongs_to :user
belongs_to :team
has_many :other_teamers, -> { where("teamers.id != ?", object_id) }, :through => :user, :source => :teamers
has_many :contesters, :through => :team
before_create :init_variables
before_create :init_variables
def to_s
user.to_s
def to_s
user.to_s
end
def ranks
{RANK_JOINER => "Joining", RANK_MEMBER => "Member", RANK_DEPUTEE => "Deputee", RANK_LEADER => "Leader"}
end
def validate_team
if user.teamers.of_team(team).present.count > 0
errors.add :team, I18n.t(:teams_join_twice)
end
end
def ranks
{RANK_JOINER => "Joining", RANK_MEMBER => "Member", RANK_DEPUTEE => "Deputee", RANK_LEADER => "Leader"}
end
def validate_contests
# TODO
end
def validate_team
if user.teamers.of_team(team).present.count > 0
errors.add :team, I18n.t(:teams_join_twice)
end
end
def init_variables
self.rank = RANK_JOINER unless self.rank
end
def validate_contests
# TODO
def destroy
user.update_attribute :team, nil if user.team == team
if rank == Teamer::RANK_JOINER
super
else
update_attribute :rank, Teamer::RANK_REMOVED
end
end
def init_variables
self.rank = RANK_JOINER unless self.rank
end
def can_create? cuser, params
cuser and Verification.contain params, [:user_id, :team_id]
end
def destroy
user.update_attribute :team, nil if user.team == team
if rank == Teamer::RANK_JOINER
super
else
update_attribute :rank, Teamer::RANK_REMOVED
end
end
def can_update? cuser
cuser and cuser.admin?
end
def can_create? cuser, params
cuser and Verification.contain params, [:user_id, :team_id]
end
def can_update? cuser
cuser and cuser.admin?
end
def can_destroy? cuser
cuser and (user == cuser or team.is_leader? cuser or cuser.admin?)
end
def can_destroy? cuser
cuser and (user == cuser or team.is_leader? cuser or cuser.admin?)
end
end

View file

@ -90,23 +90,23 @@ class User < ActiveRecord::Base
.joins("LEFT JOIN posts ON posts.user_id = users.id")
.group("users.id")
.order("num DESC") }
scope :banned,
:joins => "LEFT JOIN bans ON bans.user_id = users.id AND expiry > UTC_TIMESTAMP()",
:conditions => "bans.id IS NOT NULL"
scope :idle,
:conditions => ["lastvisit < ?", 30.minutes.ago.utc]
scope :banned, -> {
joins("LEFT JOIN bans ON bans.user_id = users.id AND expiry > UTC_TIMESTAMP()")
.conditions("bans.id IS NOT NULL") }
scope :idle, -> {
joins("lastvisit < ?", 30.minutes.ago.utc) }
validates_uniqueness_of :username, :email, :steamid
validates_length_of :firstname, :in => 1..15, :allow_blank => true
validates_length_of :lastname, :in => 1..25, :allow_blank => true
validates_length_of :username, :in => 2..20
validates_format_of :username, :with => /\A[A-Za-z0-9_\-\+]{2,20}\Z/
validates_presence_of :raw_password, :on => :create
validates_presence_of :raw_password, :on => :create
validates_length_of :email, :maximum => 50
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
validates_length_of :steamid, :maximum => 30
validates_format_of :steamid, :with => /\A([0-9]{1,10}:){2}[0-9]{1,10}\Z/
validates_length_of :time_zone, :maximum => 100, :allow_blank => true, :allow_nil => true
validates_length_of :time_zone, :maximum => 100, :allow_blank => true, :allow_nil => true
validates_inclusion_of [:public_email], :in => [true, false], :allow_nil => true
validate :validate_team
@ -292,7 +292,7 @@ class User < ActiveRecord::Base
end
def self.search(search)
search ? where("LOWER(username) LIKE LOWER(?) OR steamid LIKE ?", "%#{search}%", "%#{search}%") : scoped
search ? where("LOWER(username) LIKE LOWER(?) OR steamid LIKE ?", "%#{search}%", "%#{search}%") : all
end
def self.refadmins

View file

@ -2,7 +2,7 @@
<div id="categories">
<% @categories.each do |cat| %>
<% forums = cuser ? cat.forums.available_to(cuser, Forumer::ACCESS_READ).ordered : cat.forums.public.ordered %>
<% forums = cuser ? cat.forums.available_to(cuser, Forumer::ACCESS_READ).ordered : cat.forums.public_forums.ordered %>
<% next if forums.length == 0 %>
<div class="category">
@ -58,7 +58,7 @@
<strong><%= Topic.count %></strong> topics, and <strong><%= User.count %></strong> users.
</p>
<p>
Our newest member is <%= namelink User.last %> and most active member is <%= namelink User.posts_stats.first %>.
Our newest member is <%= namelink User.last %> and most active member is <%= namelink User.posts_stats(1).first %>.
</p>
</div>

View file

@ -10,7 +10,6 @@
</tr>
<% for team in teams %>
<% if team.teamers_num > 0 %>
<tr>
<td><%= flag team.country %></td>
<td><%= namelink team %></td>
@ -33,6 +32,5 @@
</td>
<% end %>
</tr>
<% end %>
<% end %>
</table>

View file

@ -58,14 +58,14 @@
</div>
<div class="tab" id="members">
<% if @team.teamers.active.ordered.distinct.length > 0 %>
<% if @team.teamers.active.ordered.unique_by_team.length > 0 %>
<h3>Current Members</h3>
<%= render partial: "teamers/list", locals: { teamers: @team.teamers.active.ordered.distinct, blacklist: false, comment: true } %>
<%= render partial: "teamers/list", locals: { teamers: @team.teamers.active.ordered.unique_by_team, blacklist: false, comment: true } %>
<% end %>
<% if @team.teamers.past.distinct.length > 0 %>
<% if @team.teamers.past.unique_by_team.length > 0 %>
<h3>Past Members</h3>
<%= render partial: "teamers/list", locals: { teamers: @team.teamers.past.distinct, blacklist: @team.teamers.active.ordered.distinct, comment: false } %>
<%= render partial: "teamers/list", locals: { teamers: @team.teamers.past.unique_by_team, blacklist: @team.teamers.active.ordered.unique_by_team, comment: false } %>
<% end %>
</div>

View file

@ -2,7 +2,7 @@
<div class="widget poll">
<h4><%= t('widget.poll') %></h4>
<% @poll = Poll.first(order: "created_at DESC") %>
<% @poll = Poll.first %>
<%= render(partial: "polls/show") if @poll %>
</div>
<% end %>

3
bin/bundle Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')

4
bin/rails Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'

4
bin/rake Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run