diff options
author | Matthew Somerville <matthew@mysociety.org> | 2019-06-12 17:46:08 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2019-07-10 09:43:47 +0100 |
commit | 541cac6d0341b720ef67ef90c0f7fd12666dc3a0 (patch) | |
tree | f59af03a3a2b3fd5d382250d68f629b040de3234 | |
parent | 9787e2ffe0edec7a477d4dfdd1ff04719d7b7a96 (diff) |
Allow password hash setting in user import.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Users.pm | 20 | ||||
-rw-r--r-- | templates/web/base/admin/users/import.html | 4 |
2 files changed, 12 insertions, 12 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Users.pm b/perllib/FixMyStreet/App/Controller/Admin/Users.pm index e55a3d111..d29d2b8b9 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Users.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Users.pm @@ -459,10 +459,9 @@ sub import :Local { my $csv = Text::CSV->new({ binary => 1}); my $fh = $c->req->upload('csvfile')->fh; - $csv->getline($fh); # discard the header - while (my $row = $csv->getline($fh)) { - my ($name, $email, $from_body, $permissions, $roles) = @$row; - $email = lc Utils::trim_text($email); + $csv->header($fh); + while (my $row = $csv->getline_hr($fh)) { + my $email = lc Utils::trim_text($row->{email}); my $user = FixMyStreet::DB->resultset("User")->find_or_new({ email => $email, email_verified => 1 }); if ($user->in_storage) { @@ -470,12 +469,13 @@ sub import :Local { next; } - $user->name($name); - $user->from_body($from_body || undef); - $user->update_or_insert; + $user->name($row->{name}); + $user->from_body($row->{from_body} || undef); + $user->password($row->{passwordhash}, 1) if $row->{passwordhash}; + $user->insert; - if ($roles) { - my @roles = split(/:/, $roles); + if ($row->{roles}) { + my @roles = split(/:/, $row->{roles}); foreach my $role (@roles) { $role = FixMyStreet::DB->resultset("Role")->find({ body_id => $user->from_body->id, @@ -484,7 +484,7 @@ sub import :Local { $user->add_to_roles($role); } } else { - my @permissions = split(/:/, $permissions); + my @permissions = split(/:/, $row->{permissions}); my @user_permissions = grep { $available_permissions{$_} } @permissions; foreach my $permission_type (@user_permissions) { $user->user_body_permissions->find_or_create({ diff --git a/templates/web/base/admin/users/import.html b/templates/web/base/admin/users/import.html index 4a93e0255..6e11c74a9 100644 --- a/templates/web/base/admin/users/import.html +++ b/templates/web/base/admin/users/import.html @@ -65,8 +65,8 @@ <p>[% loc('This page is a quick way to create many new staff users in one go.') %]</p> <p>[% loc("Existing users won't be modified.") %]</p> <p> - [% loc("The uploaded CSV file must contain a header row, and records must have the following fields (in this order):") %] - <pre>name,email,from_body,permissions,roles</pre> + [% loc("The uploaded CSV file must contain a header row, and records can have the following fields:") %] + <pre>name,email,from_body,permissions,roles,passwordhash</pre> <ul> <li><code>from_body</code>: [% loc("the database id of the body to associate that user with, e.g. <code>2217</code> for Buckinghamshire.") %]</li> <li><code>permissions</code>: [% loc("a colon-separated list of permissions to grant that user, e.g. <code>contribute_as_body:moderate:user_edit</code>.") %]</li> |