aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/Result
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/DB/Result')
-rw-r--r--perllib/FixMyStreet/DB/Result/Body.pm18
-rw-r--r--perllib/FixMyStreet/DB/Result/Contact.pm6
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm65
-rw-r--r--perllib/FixMyStreet/DB/Result/ResponseTemplate.pm6
-rw-r--r--perllib/FixMyStreet/DB/Result/Session.pm21
-rw-r--r--perllib/FixMyStreet/DB/Result/User.pm52
6 files changed, 131 insertions, 37 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm
index 07bea276c..74a38f225 100644
--- a/perllib/FixMyStreet/DB/Result/Body.pm
+++ b/perllib/FixMyStreet/DB/Result/Body.pm
@@ -44,6 +44,14 @@ __PACKAGE__->add_columns(
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
"external_url",
{ data_type => "text", is_nullable => 1 },
+ "fetch_problems",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "blank_updates_permitted",
+ { data_type => "boolean", default_value => \"false", is_nullable => 1 },
+ "convert_latlong",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "extra",
+ { data_type => "text", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->has_many(
@@ -118,13 +126,17 @@ __PACKAGE__->has_many(
);
-# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-02-13 15:11:11
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BOJANVwg3kR/1VjDq0LykA
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2018-04-05 14:29:33
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:HV8IM2C1ErrpvXoRTZ1B1Q
+
+__PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn");
+__PACKAGE__->rabx_column('extra');
use Moo;
use namespace::clean;
-with 'FixMyStreet::Roles::Translatable';
+with 'FixMyStreet::Roles::Translatable',
+ 'FixMyStreet::Roles::Extra';
sub url {
my ( $self, $c, $args ) = @_;
diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm
index f9cbf1c44..c544f084a 100644
--- a/perllib/FixMyStreet/DB/Result/Contact.pm
+++ b/perllib/FixMyStreet/DB/Result/Contact.pm
@@ -97,7 +97,11 @@ sub category_display {
sub get_metadata_for_input {
my $self = shift;
my $id_field = $self->id_field;
- my @metadata = grep { $_->{code} !~ /^(easting|northing|closest_address|$id_field)$/ } @{$self->get_extra_fields};
+ my @metadata = @{$self->get_extra_fields};
+ # First, ones we always want to ignore (hard-coded, old system)
+ @metadata = grep { $_->{code} !~ /^(easting|northing|closest_address|$id_field)$/ } @metadata;
+ # Also ignore any we have with a 'server_set' automated attribute
+ @metadata = grep { !$_->{automated} || $_->{automated} ne 'server_set' } @metadata;
# Just in case the extra data is in an old parsed format
foreach (@metadata) {
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index c73f7efca..f67e0b0f8 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -341,7 +341,7 @@ around service => sub {
sub title_safe {
my $self = shift;
- return _('Awaiting moderation') if $self->cobrand eq 'zurich' && $self->state eq 'unconfirmed';
+ return _('Awaiting moderation') if $self->cobrand eq 'zurich' && $self->state eq 'submitted';
return $self->title;
}
@@ -509,6 +509,18 @@ sub tokenised_url {
return "/M/". $token->token;
}
+=head2 is_hidden
+
+Returns 1 if the problem is in an hidden state otherwise 0.
+
+=cut
+
+sub is_hidden {
+ my $self = shift;
+
+ return exists $self->hidden_states->{ $self->state } ? 1 : 0;
+}
+
=head2 is_open
Returns 1 if the problem is in a open state otherwise 0.
@@ -641,22 +653,27 @@ sub body {
my $body;
if ($problem->external_body) {
if ($problem->cobrand eq 'zurich') {
- $body = $c->model('DB::Body')->find({ id => $problem->external_body });
+ my $cache = $problem->result_source->schema->cache;
+ return $cache->{bodies}{$problem->external_body} //= $c->model('DB::Body')->find({ id => $problem->external_body });
} else {
$body = $problem->external_body;
}
} else {
my $bodies = $problem->bodies;
- $body = join( _(' and '),
- map {
- my $name = $_->name;
- if ($c and FixMyStreet->config('AREA_LINKS_FROM_PROBLEMS')) {
- '<a href="' . $_->url($c) . '">' . $name . '</a>';
- } else {
- $name;
- }
- } values %$bodies
- );
+ my @body_names = sort map {
+ my $name = $_->name;
+ if ($c and FixMyStreet->config('AREA_LINKS_FROM_PROBLEMS')) {
+ '<a href="' . $_->url($c) . '">' . $name . '</a>';
+ } else {
+ $name;
+ }
+ } values %$bodies;
+ if ( scalar @body_names > 2 ) {
+ $body = join( ', ', splice @body_names, 0, -1);
+ $body = join( ',' . _(' and '), ($body, $body_names[-1]));
+ } else {
+ $body = join( _(' and '), @body_names);
+ }
}
return $body;
}
@@ -906,12 +923,11 @@ sub add_send_method {
}
sub as_hashref {
- my $self = shift;
- my $c = shift;
+ my ($self, $c, $cols) = @_;
my $state_t = FixMyStreet::DB->resultset("State")->display($self->state);
- return {
+ my $out = {
id => $self->id,
title => $self->title,
category => $self->category,
@@ -923,16 +939,17 @@ sub as_hashref {
state => $self->state,
state_t => $state_t,
used_map => $self->used_map,
- is_fixed => $self->fixed_states->{ $self->state } ? 1 : 0,
- photos => [ map { $_->{url} } @{$self->photos} ],
- meta => $self->confirmed ? $self->meta_line( $c ) : '',
- ($self->confirmed ? (
- confirmed => $self->confirmed,
- confirmed_pp => $c->cobrand->prettify_dt( $self->confirmed ),
- ) : ()),
- created => $self->created,
- created_pp => $c->cobrand->prettify_dt( $self->created ),
+ created => $self->created,
};
+ $out->{is_fixed} = $self->fixed_states->{ $self->state } ? 1 : 0 if !$cols || $cols->{is_fixed};
+ $out->{photos} = [ map { $_->{url} } @{$self->photos} ] if !$cols || $cols->{photos};
+ $out->{meta} = $self->confirmed ? $self->meta_line( $c ) : '' if !$cols || $cols->{meta};
+ $out->{created_pp} = $c->cobrand->prettify_dt( $self->created ) if !$cols || $cols->{created_pp};
+ if ($self->confirmed) {
+ $out->{confirmed} = $self->confirmed if !$cols || $cols->{confirmed};
+ $out->{confirmed_pp} = $c->cobrand->prettify_dt( $self->confirmed ) if !$cols || $cols->{confirmed_pp};
+ }
+ return $out;
}
=head2 latest_moderation_log_entry
diff --git a/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm b/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm
index 5a2029eb1..73e0d898e 100644
--- a/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm
+++ b/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm
@@ -35,6 +35,8 @@ __PACKAGE__->add_columns(
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
"state",
{ data_type => "text", is_nullable => 1 },
+ "external_status_code",
+ { data_type => "text", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("response_templates_body_id_title_key", ["body_id", "title"]);
@@ -52,8 +54,8 @@ __PACKAGE__->has_many(
);
-# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-12-01 15:10:52
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ySPzQpFwJNki8XBjCNiqZQ
+# Created by DBIx::Class::Schema::Loader v0.07048 @ 2018-03-22 11:18:36
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:p0+/jFma6H9eZ3MZAJQRaQ
__PACKAGE__->many_to_many( contacts => 'contact_response_templates', 'contact' );
diff --git a/perllib/FixMyStreet/DB/Result/Session.pm b/perllib/FixMyStreet/DB/Result/Session.pm
index 4713c99eb..a478c5444 100644
--- a/perllib/FixMyStreet/DB/Result/Session.pm
+++ b/perllib/FixMyStreet/DB/Result/Session.pm
@@ -24,5 +24,24 @@ __PACKAGE__->set_primary_key("id");
# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:MVmCn4gLQWXTDIIaDHiVmA
-# You can replace this text with custom code or comments, and it will be preserved on regeneration
+use Storable;
+use MIME::Base64;
+
+sub id_code {
+ my $self = shift;
+ my $id = $self->id;
+ $id =~ s/^session://;
+ $id =~ s/\s+$//;
+ return $id;
+}
+
+sub user {
+ my $self = shift;
+ return unless $self->session_data;
+ my $data = Storable::thaw(MIME::Base64::decode($self->session_data));
+ return unless $data->{__user};
+ my $user = $self->result_source->schema->resultset("User")->find($data->{__user}{id});
+ return $user;
+}
+
1;
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm
index db68236bf..8b539f85d 100644
--- a/perllib/FixMyStreet/DB/Result/User.pm
+++ b/perllib/FixMyStreet/DB/Result/User.pm
@@ -20,10 +20,14 @@ __PACKAGE__->add_columns(
},
"email",
{ data_type => "text", is_nullable => 1 },
+ "email_verified",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
"name",
{ data_type => "text", is_nullable => 1 },
"phone",
{ data_type => "text", is_nullable => 1 },
+ "phone_verified",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
"password",
{ data_type => "text", default_value => "", is_nullable => 0 },
"from_body",
@@ -42,10 +46,20 @@ __PACKAGE__->add_columns(
{ data_type => "integer", is_nullable => 1 },
"extra",
{ data_type => "text", is_nullable => 1 },
- "email_verified",
- { data_type => "boolean", default_value => \"false", is_nullable => 0 },
- "phone_verified",
- { data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "created",
+ {
+ data_type => "timestamp",
+ default_value => \"current_timestamp",
+ is_nullable => 0,
+ original => { default_value => \"now()" },
+ },
+ "last_active",
+ {
+ data_type => "timestamp",
+ default_value => \"current_timestamp",
+ is_nullable => 0,
+ original => { default_value => \"now()" },
+ },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("users_facebook_id_key", ["facebook_id"]);
@@ -105,8 +119,8 @@ __PACKAGE__->has_many(
);
-# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-09-19 18:02:17
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OKHKCSahWD3Ov6ulj+2f/w
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2018-05-23 18:54:36
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/V7+Ygv/t6VX8dDhNGN16w
# These are not fully unique constraints (they only are when the *_verified
# is true), but this is managed in ResultSet::User's find() wrapper.
@@ -442,6 +456,25 @@ sub adopt {
$other->delete;
}
+sub anonymize_account {
+ my $self = shift;
+
+ $self->problems->update({ anonymous => 1, name => '', send_questionnaire => 0 });
+ $self->comments->update({ anonymous => 1, name => '' });
+ $self->alerts->update({ whendisabled => \'current_timestamp' });
+ $self->password('', 1);
+ $self->update({
+ email => 'removed-' . $self->id . '@' . FixMyStreet->config('EMAIL_DOMAIN'),
+ email_verified => 0,
+ name => '',
+ phone => '',
+ phone_verified => 0,
+ title => undef,
+ twitter_id => undef,
+ facebook_id => undef,
+ });
+}
+
# Planned reports / shortlist
# Override the default auto-created function as we only want one live entry so
@@ -511,4 +544,11 @@ has categories => (
},
);
+sub set_last_active {
+ my $self = shift;
+ my $time = shift;
+ $self->unset_extra_metadata('inactive_email_sent');
+ $self->last_active($time or \'current_timestamp');
+}
+
1;