diff options
author | Matthew Somerville <matthew@mysociety.org> | 2013-01-18 13:20:34 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2013-01-18 13:20:34 +0000 |
commit | 137cdeb6bc888c462ef0cfa50105d1dd0479a7d4 (patch) | |
tree | 63c9abe40845d2e4b57b8ac97b0fd3f9658456d8 | |
parent | 8e453215c282004e2ee5d182260aaf14dd08f9c3 (diff) |
Add user addition form.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 36 | ||||
-rw-r--r-- | templates/web/default/admin/user-form.html | 18 | ||||
-rw-r--r-- | templates/web/default/admin/user_edit.html | 16 | ||||
-rw-r--r-- | templates/web/default/admin/users.html | 13 | ||||
-rw-r--r-- | templates/web/zurich/admin/reports.html | 5 |
5 files changed, 68 insertions, 20 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 7c985fdfc..08ac82298 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -730,11 +730,9 @@ sub users: Path('users') : Args(0) { my ( $self, $c ) = @_; if (my $search = $c->req->param('search')) { - $c->stash->{searched} = 1; + $c->stash->{searched} = $search; - my $search = $c->req->param('search'); my $isearch = '%' . $search . '%'; - my $search_n = 0; $search_n = int($search) if $search =~ /^\d+$/; @@ -765,6 +763,9 @@ sub users: Path('users') : Args(0) { } } + } else { + $c->forward('get_token'); + $c->forward('fetch_all_bodies'); } return 1; @@ -875,6 +876,35 @@ sub update_edit : Path('update_edit') : Args(1) { return 1; } +sub user_add : Path('user_edit') : Args(0) { + my ( $self, $c ) = @_; + + $c->stash->{template} = 'admin/user_edit.html'; + $c->forward('get_token'); + $c->forward('fetch_all_bodies'); + + return 1 unless $c->req->param('submit'); + + $c->forward('check_token'); + + my $user = $c->model('DB::User')->find_or_create( { + name => $c->req->param('name'), + email => $c->req->param('email'), + from_body => $c->req->param('body') || undef, + flagged => $c->req->param('flagged') || 0, + }, { + key => 'users_email_key' + } ); + $c->stash->{user} = $user; + + $c->forward( 'log_edit', [ $user->id, 'user', 'edit' ] ); + + $c->stash->{status_message} = + '<p><em>' . _('Updated!') . '</em></p>'; + + return 1; +} + sub user_edit : Path('user_edit') : Args(1) { my ( $self, $c, $id ) = @_; diff --git a/templates/web/default/admin/user-form.html b/templates/web/default/admin/user-form.html new file mode 100644 index 000000000..eec54d447 --- /dev/null +++ b/templates/web/default/admin/user-form.html @@ -0,0 +1,18 @@ +<form method="post" action="[% c.uri_for( 'user_edit', user.id ) %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8"> + <input type="hidden" name="token" value="[% token %]" > + <input type="hidden" name="submit" value="1" > + <ul> + <li>[% loc('Name:') %] <input type='text' name='name' id='name' value='[% user.name | html %]'></li> + <li>[% loc('Email:') %] <input type='text' id='email' name='email' value='[% user.email | html %]'></li> + <li>[% loc('Body:') %] <select id='body' name='body'> + <option value=''>[% loc('No body') %]</option> + [% FOR body IN bodies %] + <option value="[% body.id %]"[% ' selected' IF body.id == user.from_body.id %]>[% body.name %]</option> + [% END %] + </select> + [% IF c.cobrand.moniker != 'zurich' %] + <li>[% loc('Flagged:') %] <input type="checkbox" id="flagged" name="flagged"[% user.flagged ? ' checked' : '' %]></li> + [% END %] + </ul> + <input type="submit" name="Submit changes" value="[% loc('Submit changes') %]" > +</form> diff --git a/templates/web/default/admin/user_edit.html b/templates/web/default/admin/user_edit.html index df1cb221f..d69c873a3 100644 --- a/templates/web/default/admin/user_edit.html +++ b/templates/web/default/admin/user_edit.html @@ -3,20 +3,6 @@ [% status_message %] -<form method="post" action="[% c.uri_for( 'user_edit', user.id ) %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8"> - <input type="hidden" name="token" value="[% token %]" > - <input type="hidden" name="submit" value="1" > -<ul> -<li>[% loc('Name:') %] <input type='text' name='name' id='name' value='[% user.name | html %]'></li> -<li>[% loc('Email:') %] <input type='text' id='email' name='email' value='[% user.email | html %]'></li> -<li>[% loc('Body:') %] <select id='body' name='body'> - <option value=''>[% loc('No body') %]</option> -[% FOR body IN bodies %] - <option value="[% body.id %]"[% ' selected' IF body.id == user.from_body.id %]>[% body.name %]</option> -[% END %] -</select> -<li>[% loc('Flagged:') %] <input type="checkbox" id="flagged" name="flagged"[% user.flagged ? ' checked' : '' %]></li> -</ul> -<input type="submit" name="Submit changes" value="[% loc('Submit changes') %]" ></form> +[% INCLUDE 'admin/user-form.html' %] [% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/default/admin/users.html b/templates/web/default/admin/users.html index 7e652e559..de0b74746 100644 --- a/templates/web/default/admin/users.html +++ b/templates/web/default/admin/users.html @@ -2,17 +2,19 @@ [% PROCESS 'admin/report_blocks.html' %] <form method="get" action="[% c.uri_for('users') %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8"> - <p><label for="search">[% loc('Search:') %]</label> <input type="text" name="search" size="30" id="search"> + <p><label for="search">[% loc('Search:') %]</label> <input type="text" name="search" size="30" id="search" value="[% searched | html %]"> </form> - [% IF searched %] + <table cellspacing="0" cellpadding="2" border="1"> <tr> <th>[% loc('Name') %]</th> <th>[% loc('Email') %]</th> <th>[% loc('Body') %]</th> + [% IF c.cobrand.moniker != 'zurich' %] <th>[% loc('Flagged') %]</th> + [% END %] <th>*</th> </tr> [%- FOREACH user IN users %] @@ -20,12 +22,19 @@ <td>[% PROCESS value_or_nbsp value=user.name %]</td> <td><a href="[% c.uri_for( 'reports', search => user.email ) %]">[% PROCESS value_or_nbsp value=user.email %]</a></td> <td>[% PROCESS value_or_nbsp value=user.from_body.name %]</td> + [% IF c.cobrand.moniker != 'zurich' %] <td>[% user.flagged == 2 ? loc('(Email in abuse table)') : user.flagged ? loc('Yes') : ' ' %]</td> + [% END %] <td>[% IF user.id %]<a href="[% c.uri_for( 'user_edit', user.id ) %]">[% loc('Edit') %]</a>[% END %]</td> </tr> [%- END -%] </table> +[% ELSE %] + +<h2>[% loc('Add user') %]</h2> +[% INCLUDE 'admin/user-form.html' %] + [% END %] [% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/zurich/admin/reports.html b/templates/web/zurich/admin/reports.html index 0a3b5d568..207083926 100644 --- a/templates/web/zurich/admin/reports.html +++ b/templates/web/zurich/admin/reports.html @@ -1,6 +1,11 @@ [% PROCESS 'admin/header.html' title=loc('Search Reports') %] [% PROCESS 'admin/report_blocks.html' %] +<form method="get" action="[% c.uri_for('reports') %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8"> + <p><label for="search">[% loc('Search:') %]</label> <input type="text" name="search" size="30" id="search"> +</form> + + [% IF searched %] <table cellspacing="0" cellpadding="2" border="1"> <tr> |