FEATURE: introduce dedicated storage and DB constraints for anon users

Previously we used custom fields to denote a user was anonymous, this was
risky in that custom fields are prone to race conditions and are not
properly dedicated, missing constraints and so on.

The new table `anonymous_users` is properly protected. There is only one
possible shadow account per user, which is enforced using a constraint.

Every anonymous user will have a unique row in the new table.
This commit is contained in:
Sam Saffron
2019-05-29 14:26:06 +10:00
parent a206da8e18
commit 5c524ea8a4
6 changed files with 129 additions and 32 deletions

View File

@ -34,6 +34,9 @@ describe AnonymousShadowCreator do
expect(shadow.id).to eq(shadow2.id)
create_post(user: shadow)
user.reload
shadow.reload
freeze_time 4.minutes.from_now
shadow3 = AnonymousShadowCreator.get(user)
@ -56,6 +59,7 @@ describe AnonymousShadowCreator do
expect(shadow.created_at).not_to eq(user.created_at)
p = create_post
expect(Guardian.new(shadow).post_can_act?(p, :like)).to eq(false)
expect(Guardian.new(user).post_can_act?(p, :like)).to eq(true)