diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Alert.pm | 31 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 30 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 32 | ||||
-rw-r--r-- | perllib/FixMyStreet/Roles/Abuser.pm | 29 |
4 files changed, 50 insertions, 72 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Alert.pm b/perllib/FixMyStreet/DB/Result/Alert.pm index d780e91fd..e0017b94d 100644 --- a/perllib/FixMyStreet/DB/Result/Alert.pm +++ b/perllib/FixMyStreet/DB/Result/Alert.pm @@ -57,32 +57,10 @@ __PACKAGE__->belongs_to( # You can replace this text with custom code or comments, and it will be preserved on regeneration -# FIXME: this is more or less duplicated from problem. need to stick somewhere common +use Moose; +use namespace::clean -except => [ 'meta' ]; - -=head2 is_from_abuser - - $bool = $alert->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; -} +with 'FixMyStreet::Roles::Abuser'; =head2 confirm @@ -103,4 +81,7 @@ sub confirm { return 1; } +# need the inline_constuctor bit as we don't inherit from Moose +__PACKAGE__->meta->make_immutable( inline_constructor => 0 ); + 1; diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 9b5feb37d..4c70dd902 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -72,6 +72,11 @@ __PACKAGE__->belongs_to( # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:71bSUgPf3uW607g2EGl/Vw use DateTime::TimeZone; +use Moose; +use namespace::clean -except => [ 'meta' ]; + +with 'FixMyStreet::Roles::Abuser'; + my $tz = DateTime::TimeZone->new( name => "local" ); sub created_local { @@ -134,28 +139,7 @@ sub get_photo_params { return $photo; } -=head2 is_from_abuser - - $bool = $update->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; -} +# we need the inline_constructor bit as we don't inherit from Moose +__PACKAGE__->meta->make_immutable( inline_constructor => 0 ); 1; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 25cf6e8b2..c1ecd6576 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -104,6 +104,11 @@ __PACKAGE__->has_many( # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:U3aYCRwE4etekKaHdhEkIw use DateTime::TimeZone; +use Moose; +use namespace::clean -except => [ 'meta' ]; + +with 'FixMyStreet::Roles::Abuser'; + my $tz = DateTime::TimeZone->new( name => "local" ); sub confirmed_local { @@ -178,30 +183,6 @@ 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; -} - =head2 confirm $bool = $problem->confirm( ); @@ -366,4 +347,7 @@ sub duration_string { ); } +# we need the inline_constructor bit as we don't inherit from Moose +__PACKAGE__->meta->make_immutable( inline_constructor => 0 ); + 1; diff --git a/perllib/FixMyStreet/Roles/Abuser.pm b/perllib/FixMyStreet/Roles/Abuser.pm new file mode 100644 index 000000000..b9e951305 --- /dev/null +++ b/perllib/FixMyStreet/Roles/Abuser.pm @@ -0,0 +1,29 @@ +package FixMyStreet::Roles::Abuser; + +use Moose::Role; + +=head2 is_from_abuser + + $bool = $alert->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; |