aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/Result/User.pm
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 /perllib/FixMyStreet/DB/Result/User.pm
parent2d916ec746f5d7091bb98890bf035ab1c0f14443 (diff)
Move moderation check to own function, tidy up.
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/User.pm')
-rw-r--r--perllib/FixMyStreet/DB/Result/User.pm13
1 files changed, 11 insertions, 2 deletions
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};