diff options
author | Dave Arter <davea@mysociety.org> | 2016-08-02 17:32:50 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2016-08-17 15:35:42 +0100 |
commit | 4eb4658ad589d01d58b239993e201c47325a2eb4 (patch) | |
tree | b679f70a78d16ebf035cd395c914ea06865a6732 /perllib/FixMyStreet/App/Controller/Admin.pm | |
parent | 91c5520c7078f2caa3cbdbdcff4f86a29d9d7390 (diff) |
Restrict from_body editing to superusers
Superusers can set a user's from_body to any value, but a normal staff user
can only set another user's from_body to the same as their own or undefined.
This is presented in the UI as a 'staff' tickbox.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 91af480a8..ce2a653a2 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -1148,10 +1148,18 @@ sub user_edit : Path('user_edit') : Args(1) { $user->name( $c->get_param('name') ); $user->email( $c->get_param('email') ); $user->phone( $c->get_param('phone') ) if $c->get_param('phone'); - $user->from_body( $c->get_param('body') || undef ); $user->flagged( $c->get_param('flagged') || 0 ); # Only superusers can grant superuser status $user->is_superuser( ( $c->user->is_superuser && $c->get_param('is_superuser') ) || 0 ); + # Superusers can set from_body to any value, but other staff can only + # set from_body to the same value as their own from_body. + if ($c->user->is_superuser) { + $user->from_body( $c->get_param('body') || undef ); + } elsif ($c->get_param('body') eq $c->user->from_body->id) { + $user->from_body( $c->user->from_body ); + } else { + $user->from_body( undef ); + } unless ($user->email) { $c->stash->{field_errors}->{email} = _('Please enter a valid email'); |