mysociety / ipvtheme

The Alaveteli theme for Informace pro vsechny (Czech Republic)
http://infoprovsechny.cz
MIT License
3 stars 4 forks source link

User has created an account with a blank address field #35

Open crowbot opened 7 years ago

crowbot commented 7 years ago

This is causing validation errors when they try to confirm their account:

An ActiveRecord::RecordInvalid occurred in user#confirm:

Validace je neúspešná: Address Musíte vložit adresu. activerecord (3.2.22.3) lib/active_record/validations.rb:56:in `save!'

Actually looks like this is an older account, so they've somehow been able to delete the address information.

garethrees commented 7 years ago

I was just looking at this.

ID  622
Created at  2016-04-07 09:29:06 +0200
Updated at  2017-04-18 02:09:25 +0200

Looks like they're following a PostRedirect (created yesterday).

crowbot commented 7 years ago

OK, I'll let you dig into it.

garethrees commented 7 years ago

I think this is what's happening:

garethrees commented 7 years ago

IMO, the above code flow is a bit broken. We shouldn't be updating the record when a user just wants to follow a "log me in to do X" URL.

As a quick fix, I've just updated all users without an address:

User.where(:address => nil).update_all(:address => '-')
#  SQL (4.1ms)  UPDATE "users" SET "address" = '-' WHERE "users"."address" IS NULL
#=> 6
User.where(:address => nil).count
#   (1.4ms)  SELECT COUNT(*) FROM "users" WHERE "users"."address" IS NULL
#=> 0
User.where(:address => '').update_all(:address => '-')
#  SQL (224.0ms)  UPDATE "users" SET "address" = '-' WHERE "users"."address" = ''
#=> 81
User.where(:address => '').count
#   (1.5ms)  SELECT COUNT(*) FROM "users" WHERE "users"."address" = ''
#=> 0