diff options
author | Matthew Somerville <matthew@mysociety.org> | 2016-03-04 18:46:53 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2016-03-04 18:46:53 +0000 |
commit | 38a75cdb259b37e42313e8202eee6bee3f5c4868 (patch) | |
tree | ec2f8efa27856d10dfc774e478d3dee4d3c53c1f /perllib/FixMyStreet/DB | |
parent | 2fc65ef99e7591f4f570c5102f46583a0ce9a793 (diff) |
Remember user's last anonymous state.
If a user is logged in, use their last report/update to set the default
anonymity state.
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index ddf986c47..6bce415a6 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -104,6 +104,16 @@ __PACKAGE__->add_columns( use mySociety::EmailUtil; +sub latest_anonymity { + my $self = shift; + my $p = $self->problems->search(undef, { order_by => { -desc => 'id' } } )->first; + my $c = $self->comments->search(undef, { order_by => { -desc => 'id' } } )->first; + my $p_created = $p ? $p->created->epoch : 0; + my $c_created = $c ? $c->created->epoch : 0; + my $obj = $p_created >= $c_created ? $p : $c; + return $obj ? $obj->anonymous : 0; +} + =head2 check_for_errors $error_hashref = $user->check_for_errors(); |