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

@@ -36,12 +36,10 @@ __PACKAGE__->add_columns(
);
__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',
'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;

View File

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

View File

@@ -12,6 +12,7 @@ use Digest::MD5 ();
register_admin_task({
tag => 'users',
label => 'User Management',
provides_csv => 1,
});
sub _sanity_ok {
@@ -42,6 +43,7 @@ ajax '/ajax/control/admin/users/add' => require_role admin => sub {
ldap => (param('ldap') ? \'true' : \'false'),
port_control => (param('port_control') ? \'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'),
port_control => (param('port_control') ? \'true' : \'false'),
admin => (param('admin') ? \'true' : \'false'),
note => param('note'),
});
});
};
ajax '/ajax/content/admin/users' => require_role admin => sub {
my $set = schema('netdisco')->resultset('User')
->search(undef, { order_by => [qw/fullname username/]});
get '/ajax/content/admin/users' => require_role admin => sub {
my @results = schema('netdisco')->resultset('User')
->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');
template 'ajax/admintask/users.tt', {
results => $set,
}, { layout => undef };
return unless scalar @results;
if ( request->is_ajax ) {
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;