aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/Result/Comment.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/Comment.pm')
-rw-r--r--perllib/FixMyStreet/DB/Result/Comment.pm35
1 files changed, 35 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm
index 68e267d00..c876f3459 100644
--- a/perllib/FixMyStreet/DB/Result/Comment.pm
+++ b/perllib/FixMyStreet/DB/Result/Comment.pm
@@ -110,6 +110,41 @@ with 'FixMyStreet::Roles::Abuser',
'FixMyStreet::Roles::Moderation',
'FixMyStreet::Roles::PhotoSet';
+=head2 FOREIGNBUILDARGS
+
+Make sure that when creating a new Comment object, certain
+other fields are set based upon the supplied data.
+
+=cut
+
+sub FOREIGNBUILDARGS {
+ my ($class, $opts) = @_;
+
+ if (my $user = $opts->{user}) {
+ my $name;
+ if ($user->is_superuser) {
+ $opts->{extra}->{is_superuser} = 1;
+ $name = _('an administrator');
+ } elsif (my $body = $user->from_body) {
+ $opts->{extra}->{is_body_user} = $body->id;
+ $name = $body->name;
+ $name = 'Island Roads' if $name eq 'Isle of Wight Council';
+ } else {
+ $name = $user->name;
+ }
+ $opts->{name} //= $name;
+ }
+
+ $opts->{anonymous} //= 0;
+ $opts->{mark_fixed} //= 0;
+ $opts->{state} //= 'confirmed'; # it's only public updates that need to be unconfirmed
+ if ($opts->{state} eq 'confirmed') {
+ $opts->{confirmed} //= \'current_timestamp';
+ }
+
+ return $opts;
+};
+
=head2 get_cobrand_logged
Get a cobrand object for the cobrand the update was made on.