aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/DB/Result/Abuse.pm19
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm25
2 files changed, 44 insertions, 0 deletions
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;