diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-09-06 16:07:30 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-09-09 15:51:33 +0100 |
commit | 2835ee9d82d508e32720138702ca3879a41c19db (patch) | |
tree | ed7de10c4898a0e897ff58074b3b822d8ab87e2d /perllib/FixMyStreet/DB/Result/User.pm | |
parent | 2acf9eb59867c299da568bf77c9019fe6c3eb9ff (diff) |
Add manage screen for editing priority/category.
This is a cut-down version of the full inspect screen.
We truncate the co-ordinates just in case (they should be anyway but
e.g. the test report isn't).
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/User.pm')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 6444cfe6a..0ba7e252c 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -240,18 +240,34 @@ sub split_name { return { first => $first || '', last => $last || '' }; } +sub permissions { + my ($self, $c, $body_id) = @_; + + if ($self->is_superuser) { + my $perms = $c->cobrand->available_permissions; + return { map { %$_ } values %$perms }; + } + + return unless $self->belongs_to_body($body_id); + + my @permissions = $self->user_body_permissions->search({ + body_id => $self->from_body->id, + })->all; + return { map { $_->permission_type => 1 } @permissions }; +} + sub has_permission_to { my ($self, $permission_type, $body_id) = @_; return 1 if $self->is_superuser; - return unless $self->belongs_to_body($body_id); + return 0 unless $self->belongs_to_body($body_id); my $permission = $self->user_body_permissions->find({ permission_type => $permission_type, body_id => $self->from_body->id, }); - return $permission ? 1 : undef; + return $permission ? 1 : 0; } =head2 has_body_permission_to |