Change user.rb to fix migration

Gracefully fix nil team value
This commit is contained in:
Ari Timonen 2020-11-17 04:15:07 +02:00
parent 0a6879230f
commit a081db3ba0
2 changed files with 9 additions and 3 deletions

View file

@ -4,7 +4,7 @@
# Add changes only specific to dev. env.
# Scrypt max time to reduce migration time
SCRYPT_MAX_TIME=0.001
SCRYPT_MAX_TIME=0.0005
MYSQL_DATABASE=ensl_development
@ -13,4 +13,4 @@ RACK_ENV=development
RAILS_ENV=development
# Set this to higher to enable debugging
PUMA_TIMEOUT=300
PUMA_TIMEOUT=300

View file

@ -335,6 +335,11 @@ class User < ActiveRecord::Base
issues.unread_by(self)
end
def duplicates
# TODO: user arel
User.where('lower(username) = ? AND users.id != ?', username.downcase, id)
end
def correct_steamid_universe
if steamid.present?
steamid[0] = "0"
@ -344,8 +349,9 @@ class User < ActiveRecord::Base
# FIXME: if team has been removed
def validate_team
if team and !active_teams.exists?({:id => team.id})
# Attempts to fix team, gracefully
self.team = nil
self.save!
self.save
errors.add :team
end
end