aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2018-08-22 14:12:44 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-08-28 13:17:30 +0100
commit71e86b456f99418cc646dac3f8bffe87ec4fc7f6 (patch)
tree5d999c35e2d95c5c6a85be9bbdcac1f4ecba3752
parent2d916ec746f5d7091bb98890bf035ab1c0f14443 (diff)
Move moderation check to own function, tidy up.
-rw-r--r--perllib/FixMyStreet/App/Controller/Moderate.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm2
-rw-r--r--perllib/FixMyStreet/DB/Result/User.pm13
-rw-r--r--templates/web/base/report/_inspect.html2
-rw-r--r--templates/web/base/report/display.html2
5 files changed, 15 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Moderate.pm b/perllib/FixMyStreet/App/Controller/Moderate.pm
index b32f38e13..17e4c6dd2 100644
--- a/perllib/FixMyStreet/App/Controller/Moderate.pm
+++ b/perllib/FixMyStreet/App/Controller/Moderate.pm
@@ -51,7 +51,7 @@ sub report : Chained('moderate') : PathPart('report') : CaptureArgs(1) {
# ... and immediately, if the user isn't authorized
$c->detach unless $c->user_exists;
- $c->detach unless $c->user->has_permission_to(moderate => $problem->bodies_str_ids);
+ $c->detach unless $c->user->can_moderate($problem);
$c->forward('/auth/check_csrf_token');
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index e285687bc..854dbf3ea 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -140,7 +140,7 @@ sub load_problem_or_display_error : Private {
}
$c->stash->{problem} = $problem;
- if ( $c->user_exists && $c->user->has_permission_to(moderate => $problem->bodies_str_ids) ) {
+ if ( $c->user_exists && $c->user->can_moderate($problem) ) {
$c->stash->{problem_original} = $problem->find_or_new_related(
moderation_original_data => {
title => $problem->title,
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm
index 5ba597f74..625092740 100644
--- a/perllib/FixMyStreet/DB/Result/User.pm
+++ b/perllib/FixMyStreet/DB/Result/User.pm
@@ -330,6 +330,12 @@ sub split_name {
return { first => $first || '', last => $last || '' };
}
+sub can_moderate {
+ my ($self, $problem) = @_;
+
+ return 1 if $self->has_permission_to(moderate => $problem->bodies_str_ids);
+}
+
has body_permissions => (
is => 'ro',
lazy => 1,
@@ -340,13 +346,16 @@ has body_permissions => (
);
sub permissions {
- my ($self, $c, $body_id) = @_;
+ my ($self, $problem) = @_;
+ my $cobrand = $self->result_source->schema->cobrand;
if ($self->is_superuser) {
- my $perms = $c->cobrand->available_permissions;
+ my $perms = $cobrand->available_permissions;
return { map { %$_ } values %$perms };
}
+ my $body_id = $problem->bodies_str;
+
return unless $self->belongs_to_body($body_id);
my @permissions = grep { $_->body_id == $self->from_body->id } @{$self->body_permissions};
diff --git a/templates/web/base/report/_inspect.html b/templates/web/base/report/_inspect.html
index adb56190d..e5094d02e 100644
--- a/templates/web/base/report/_inspect.html
+++ b/templates/web/base/report/_inspect.html
@@ -1,4 +1,4 @@
-[% permissions = c.user.permissions(c, problem.bodies_str) %]
+[% permissions = c.user.permissions(problem) %]
[% second_column = BLOCK -%]
<div id="side-inspect">
diff --git a/templates/web/base/report/display.html b/templates/web/base/report/display.html
index ebe969994..eedbc4f85 100644
--- a/templates/web/base/report/display.html
+++ b/templates/web/base/report/display.html
@@ -40,7 +40,7 @@
[% INCLUDE 'report/banner.html' %]
[% IF c.user_exists %]
- [% DEFAULT permissions = c.user.permissions(c, problem.bodies_str) %]
+ [% DEFAULT permissions = c.user.permissions(problem) %]
[%- END %]
[% INCLUDE 'report/_main.html' %]