Expose the created, last login and note fields for User managment

This commit is contained in:
Oliver Gorwits
2015-08-26 11:01:12 +01:00
parent 2426931a3a
commit 463ae67ab4
6 changed files with 70 additions and 15 deletions

View File

@@ -1,3 +1,9 @@
2.033000 - 2015-08
[ENHANCEMENTS]
* Expose the created, last login and note fields for User managment
2.032007 - 2015-07-30 2.032007 - 2015-07-30
[ENHANCEMENTS] [ENHANCEMENTS]

View File

@@ -36,12 +36,10 @@ __PACKAGE__->add_columns(
); );
__PACKAGE__->set_primary_key("username"); __PACKAGE__->set_primary_key("username");
# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2awpSJkzXP7+8eyT4vGjfw
__PACKAGE__->has_many( roles => 'App::Netdisco::DB::Result::Virtual::UserRole', __PACKAGE__->has_many( roles => 'App::Netdisco::DB::Result::Virtual::UserRole',
'username', { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 } ); 'username', { cascade_copy => 0, cascade_update => 0, cascade_delete => 0 } );
# You can replace this text with custom code or comments, and it will be preserved on regeneration sub created { return (shift)->get_column('created') }
sub last_seen { return (shift)->get_column('last_seen') }
1; 1;

View File

@@ -50,6 +50,10 @@ post '/login' => sub {
details => param('return_url'), details => param('return_url'),
}); });
schema('netdisco')->resultset('User')
->find( session('logged_in_user') )
->update({ last_on => \'now()' });
return if request->is_ajax; return if request->is_ajax;
redirect param('return_url'); redirect param('return_url');
} }

View File

@@ -12,6 +12,7 @@ use Digest::MD5 ();
register_admin_task({ register_admin_task({
tag => 'users', tag => 'users',
label => 'User Management', label => 'User Management',
provides_csv => 1,
}); });
sub _sanity_ok { sub _sanity_ok {
@@ -42,6 +43,7 @@ ajax '/ajax/control/admin/users/add' => require_role admin => sub {
ldap => (param('ldap') ? \'true' : \'false'), ldap => (param('ldap') ? \'true' : \'false'),
port_control => (param('port_control') ? \'true' : \'false'), port_control => (param('port_control') ? \'true' : \'false'),
admin => (param('admin') ? \'true' : \'false'), admin => (param('admin') ? \'true' : \'false'),
note => param('note'),
}); });
}); });
}; };
@@ -71,18 +73,34 @@ ajax '/ajax/control/admin/users/update' => require_role admin => sub {
ldap => (param('ldap') ? \'true' : \'false'), ldap => (param('ldap') ? \'true' : \'false'),
port_control => (param('port_control') ? \'true' : \'false'), port_control => (param('port_control') ? \'true' : \'false'),
admin => (param('admin') ? \'true' : \'false'), admin => (param('admin') ? \'true' : \'false'),
note => param('note'),
}); });
}); });
}; };
ajax '/ajax/content/admin/users' => require_role admin => sub { get '/ajax/content/admin/users' => require_role admin => sub {
my $set = schema('netdisco')->resultset('User') my @results = schema('netdisco')->resultset('User')
->search(undef, { order_by => [qw/fullname username/]}); ->search(undef, {
'+columns' => {
created => \"to_char(creation, 'YYYY-MM-DD HH24:MI')",
last_seen => \"to_char(last_on, 'YYYY-MM-DD HH24:MI')",
},
order_by => [qw/fullname username/]
})->hri->all;
content_type('text/html'); return unless scalar @results;
template 'ajax/admintask/users.tt', {
results => $set, if ( request->is_ajax ) {
}, { layout => undef }; template 'ajax/admintask/users.tt',
{ results => \@results, },
{ layout => undef };
}
else {
header( 'Content-Type' => 'text/comma-separated-values' );
template 'ajax/admintask/users_csv.tt',
{ results => \@results, },
{ layout => undef };
}
}; };
true; true;

View File

@@ -7,6 +7,9 @@
<th class="nd_center-cell">LDAP Auth</th> <th class="nd_center-cell">LDAP Auth</th>
<th class="nd_center-cell">Port Control</th> <th class="nd_center-cell">Port Control</th>
<th class="nd_center-cell">Administrator</th> <th class="nd_center-cell">Administrator</th>
<th class="nd_center-cell">Created</th>
<th class="nd_center-cell">Last Login</th>
<th class="nd_center-cell">Note</th>
<th class="nd_center-cell">Action</th> <th class="nd_center-cell">Action</th>
</tr> </tr>
</thead> </thead>
@@ -18,13 +21,16 @@
<td class="nd_center-cell"><input data-form="add" type="checkbox" name="ldap"></td> <td class="nd_center-cell"><input data-form="add" type="checkbox" name="ldap"></td>
<td class="nd_center-cell"><input data-form="add" type="checkbox" name="port_control"></td> <td class="nd_center-cell"><input data-form="add" type="checkbox" name="port_control"></td>
<td class="nd_center-cell"><input data-form="add" type="checkbox" name="admin"></td> <td class="nd_center-cell"><input data-form="add" type="checkbox" name="admin"></td>
<td class="nd_center-cell"></td>
<td class="nd_center-cell"></td>
<td class="nd_center-cell"><input data-form="add" name="note" type="text"></td>
<td class="nd_center-cell"> <td class="nd_center-cell">
<button class="btn btn-small nd_adminbutton" name="add" type="submit"><i class="icon-plus-sign"></i> Add</button> <button class="btn btn-small nd_adminbutton" name="add" type="submit"><i class="icon-plus-sign"></i> Add</button>
</td> </td>
</tr> </tr>
[% SET count = 0 %] [% SET count = 0 %]
[% WHILE (row = results.next) %] [% FOREACH row IN results %]
[% SET count = count + 1 %] [% SET count = count + 1 %]
<tr> <tr>
<td class="nd_center-cell"> <td class="nd_center-cell">
@@ -45,6 +51,11 @@
<td class="nd_center-cell"> <td class="nd_center-cell">
<input data-form="update" name="admin" type="checkbox" [% 'checked="checked"' IF row.admin %]> <input data-form="update" name="admin" type="checkbox" [% 'checked="checked"' IF row.admin %]>
</td> </td>
<td class="nd_center-cell">[% row.created | html_entity %]</td>
<td class="nd_center-cell">[% row.last_seen | html_entity %]</td>
<td class="nd_center-cell">
<input data-form="update" name="note" type="text" value="[% row.note | html_entity %]">
</td>
<td class="nd_center-cell"> <td class="nd_center-cell">
<button class="btn nd_adminbutton" name="update" type="submit"><i class="icon-save text-warning"></i></button> <button class="btn nd_adminbutton" name="update" type="submit"><i class="icon-save text-warning"></i></button>
@@ -80,11 +91,11 @@ $(document).ready(function() {
$('#data-table').dataTable({ $('#data-table').dataTable({
"columnDefs": [ "columnDefs": [
{ {
"targets": [ 2, 3, 4, 5, 6 ], "targets": [ 2, 3, 4, 5, 6, 7, 8, 9 ],
"searchable": false "searchable": false
}, },
{ {
"targets": [ 0, 1, 2, 3, 4, 5, 6 ], "targets": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ],
"orderable": false "orderable": false
} }
], ],

View File

@@ -0,0 +1,18 @@
[% USE CSV -%]
[% CSV.dump([ 'Full Name' 'Username'
'LDAP Auth' 'Port Control' 'Administrator' 'Created'
'Last Login' 'Note']) %]
[% FOREACH row IN results %]
[% mylist = [] %]
[% mylist.push(row.fullname) %]
[% mylist.push(row.username) %]
[% mylist.push(row.ldap) %]
[% mylist.push(row.port_control) %]
[% mylist.push(row.admin) %]
[% mylist.push(row.created) %]
[% mylist.push(row.last_seen) %]
[% mylist.push(row.note) %]
[% CSV.dump(mylist) %]
[% END %]