aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r--perllib/FixMyStreet/DB/Result/AdminLog.pm75
1 files changed, 75 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/DB/Result/AdminLog.pm b/perllib/FixMyStreet/DB/Result/AdminLog.pm
index 221690405..5564d829a 100644
--- a/perllib/FixMyStreet/DB/Result/AdminLog.pm
+++ b/perllib/FixMyStreet/DB/Result/AdminLog.pm
@@ -61,4 +61,79 @@ __PACKAGE__->belongs_to(
# Created by DBIx::Class::Schema::Loader v0.07035 @ 2019-04-25 12:06:39
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BLPP1KitphuY56ptaXhzgg
+sub link {
+ my $self = shift;
+
+ my $type = $self->object_type;
+ my $id = $self->object_id;
+ return "/report/$id" if $type eq 'problem';
+ return "/admin/users/$id" if $type eq 'user';
+ return "/admin/body/$id" if $type eq 'body';
+ return "/admin/roles/$id" if $type eq 'role';
+ if ($type eq 'update') {
+ my $update = $self->object;
+ return "/report/" . $update->problem_id . "#update_$id";
+ }
+ if ($type eq 'moderation') {
+ my $mod = $self->object;
+ if ($mod->comment_id) {
+ my $update = $self->result_source->schema->resultset('Comment')->find($mod->comment_id);
+ return "/report/" . $update->problem_id . "#update_" . $mod->comment_id;
+ } else {
+ return "/report/" . $mod->problem_id;
+ }
+ }
+ if ($type eq 'template') {
+ my $template = $self->object;
+ return "/admin/templates/" . $template->body_id . "/$id";
+ }
+ if ($type eq 'category') {
+ my $category = $self->object;
+ return "/admin/body/" . $category->body_id . '/' . $category->category;
+ }
+ return '';
+}
+
+sub actual_object_type {
+ my $self = shift;
+ my $type = $self->object_type;
+ return $type unless $type eq 'moderation' && $self->object;
+ return $self->object->comment_id ? 'update' : 'report';
+}
+
+sub object_summary {
+ my $self = shift;
+ my $object = $self->object;
+ return unless $object;
+
+ return $object->comment_id || $object->problem_id if $self->object_type eq 'moderation';
+ return $object->email || $object->phone || $object->id if $self->object_type eq 'user';
+
+ my $type_to_thing = {
+ body => 'name',
+ role => 'name',
+ template => 'title',
+ category => 'category',
+ };
+ my $thing = $type_to_thing->{$self->object_type} || 'id';
+
+ return $object->$thing;
+}
+
+sub object {
+ my $self = shift;
+
+ my $type = $self->object_type;
+ my $id = $self->object_id;
+ my $type_to_object = {
+ moderation => 'ModerationOriginalData',
+ template => 'ResponseTemplate',
+ category => 'Contact',
+ update => 'Comment',
+ };
+ $type = $type_to_object->{$type} || ucfirst $type;
+ my $object = $self->result_source->schema->resultset($type)->find($id);
+ return $object;
+}
+
1;