aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
Diffstat (limited to 'perllib')
-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
3 files changed, 13 insertions, 4 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};