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 | |
parent | 8f87691e3bb328879a1ff8c1baa1aa6748368f68 (diff) |
Add 'abuse' table and put abuse logic into problem
-rwxr-xr-x | db/rerun_dbic_loader.pl | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Abuse.pm | 19 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 25 |
3 files changed, 44 insertions, 1 deletions
diff --git a/db/rerun_dbic_loader.pl b/db/rerun_dbic_loader.pl index 2b98560ee..13316ad09 100755 --- a/db/rerun_dbic_loader.pl +++ b/db/rerun_dbic_loader.pl @@ -13,7 +13,6 @@ use DBIx::Class::Schema::Loader qw/ make_schema_at /; # create a exclude statement that filters out the table that we are not # interested in my @tables_to_ignore = ( - 'abuse', # 'admin_log', # 'alert', # 'alert_sent', # diff --git a/perllib/FixMyStreet/DB/Result/Abuse.pm b/perllib/FixMyStreet/DB/Result/Abuse.pm new file mode 100644 index 000000000..55b22d433 --- /dev/null +++ b/perllib/FixMyStreet/DB/Result/Abuse.pm @@ -0,0 +1,19 @@ +package FixMyStreet::DB::Result::Abuse; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +__PACKAGE__->load_components("FilterColumn"); +__PACKAGE__->table("abuse"); +__PACKAGE__->add_columns( "email", { data_type => "text", is_nullable => 0 } ); + +# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-03-28 12:14:16 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:fCIpGt51z5iDH9LmHeuRYQ + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +1; 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; |