diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-03-28 14:21:10 +0100 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-03-28 14:21:10 +0100 |
commit | 632dd7b8e84faa4bcb19401678565751677729cc (patch) | |
tree | 8ac7b0fc80023694f8c104f483a30763c8ceb8fe /perllib/FixMyStreet/DB/Result/Problem.pm | |
parent | 8f87691e3bb328879a1ff8c1baa1aa6748368f68 (diff) |
Add 'abuse' table and put abuse logic into problem
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index bf05bd7bd..5873a9b7f 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -140,3 +140,28 @@ sub check_for_errors { return \%errors; } +=head2 is_from_abuser + + $bool = $problem->is_from_abuser( ); + +Returns true if the user's email or its domain is listed in the 'abuse' table. + +=cut + +sub is_from_abuser { + my $self = shift; + + # get the domain + my $email = $self->user->email; + my ($domain) = $email =~ m{ @ (.*) \z }x; + + # search for an entry in the abuse table + my $abuse_rs = $self->result_source->schema->resultset('Abuse'); + + return + $abuse_rs->find( { email => $email } ) + || $abuse_rs->find( { email => $domain } ) + || undef; +} + +1; |