From a081db3ba02de59385d01a9e8bfb58236fca4725 Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Tue, 17 Nov 2020 04:15:07 +0200 Subject: [PATCH] Change user.rb to fix migration Gracefully fix nil team value --- .env.development | 4 ++-- app/models/user.rb | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.env.development b/.env.development index a89afc0..6dbc8d6 100644 --- a/.env.development +++ b/.env.development @@ -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 \ No newline at end of file +PUMA_TIMEOUT=300 diff --git a/app/models/user.rb b/app/models/user.rb index 6da21e4..c90500d 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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