[#4] Allow comment on device port in the log, for any user
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
2.029015
|
||||
|
||||
[NEW FEATURES]
|
||||
|
||||
* [#4] Allow comment on device port in the log, for any user
|
||||
|
||||
[ENHANCEMENTS]
|
||||
|
||||
* Request net-snmp-devel on Fedora/Red-Hat builds
|
||||
|
||||
@@ -160,6 +160,16 @@ __PACKAGE__->has_many( active_nodes_with_age => 'App::Netdisco::DB::Result::Virt
|
||||
cascade_copy => 0, cascade_update => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
=head2 logs
|
||||
|
||||
Returns the set of C<device_port_log> entries associated with this Port.
|
||||
|
||||
=cut
|
||||
|
||||
__PACKAGE__->has_many( logs => 'App::Netdisco::DB::Result::DevicePortLog',
|
||||
{ 'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port' },
|
||||
);
|
||||
|
||||
=head2 power
|
||||
|
||||
Returns a row from the C<device_port_power> table if one refers to this
|
||||
@@ -345,4 +355,16 @@ Returns the C<mac> column instantiated into a L<NetAddr::MAC> object.
|
||||
|
||||
sub net_mac { return NetAddr::MAC->new(mac => (shift)->mac) }
|
||||
|
||||
=head2 last_comment
|
||||
|
||||
Returns the most recent comment from the logs for this device port.
|
||||
|
||||
=cut
|
||||
|
||||
sub last_comment {
|
||||
my $row = (shift)->logs->search(undef,
|
||||
{ order_by => { -desc => 'creation' }, rows => 1 })->first;
|
||||
return ($row ? $row->log : '');
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
@@ -157,6 +157,7 @@ sub delete {
|
||||
DevicePortVlan
|
||||
DevicePortWireless
|
||||
DevicePortSsid
|
||||
DevicePortLog
|
||||
/) {
|
||||
$schema->resultset($set)->search(
|
||||
{ ip => { '-in' => $ports->as_query }},
|
||||
|
||||
@@ -14,6 +14,7 @@ hook 'before' => sub {
|
||||
|
||||
my @default_port_columns_right = (
|
||||
{ name => 'c_descr', label => 'Description', default => '' },
|
||||
{ name => 'c_comment', label => 'Last Comment', default => '' },
|
||||
{ name => 'c_type', label => 'Type', default => '' },
|
||||
{ name => 'c_duplex', label => 'Duplex', default => '' },
|
||||
{ name => 'c_lastchange', label => 'Last Change', default => '' },
|
||||
|
||||
@@ -14,6 +14,32 @@ register_report({
|
||||
hidden => true,
|
||||
});
|
||||
|
||||
sub _sanity_ok {
|
||||
return 0 unless
|
||||
param('ip') =~ m/^[[:print:]]+$/
|
||||
and param('port') =~ m/^[[:print:]]+$/
|
||||
and param('log') =~ m/^[[:print:]]+$/;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
ajax '/ajax/control/report/portlog/add' => require_login sub {
|
||||
send_error('Bad Request', 400) unless _sanity_ok();
|
||||
|
||||
schema('netdisco')->txn_do(sub {
|
||||
my $user = schema('netdisco')->resultset('DevicePortLog')
|
||||
->create({
|
||||
ip => param('ip'),
|
||||
port => param('port'),
|
||||
reason => 'other',
|
||||
log => param('log'),
|
||||
username => session('logged_in_user'),
|
||||
userip => request->remote_address,
|
||||
action => 'comment',
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
ajax '/ajax/content/report/portlog' => require_role port_control => sub {
|
||||
my $device = param('q');
|
||||
my $port = param('f');
|
||||
|
||||
@@ -82,6 +82,10 @@
|
||||
rel="tooltip" data-placement="top" data-offset="3"
|
||||
data-animation="" data-title="Enable Port"></i>
|
||||
</span>
|
||||
[% END %]
|
||||
[% ELSE %]
|
||||
<td nowrap class="nd_editable-cell"
|
||||
data-order="[% row.port | html_entity %]" data-filter="[% row.port | html_entity %]">
|
||||
[% END %]
|
||||
<a class="nd_log-icon"
|
||||
href="[% uri_for('/report/portlog') %]?q=[% device.ip | uri %]&f=[% row.port | uri %]">
|
||||
@@ -89,9 +93,6 @@
|
||||
rel="tooltip" data-placement="top" data-offset="3"
|
||||
data-animation="" data-title="View Port Log"></i>
|
||||
</a>
|
||||
[% ELSE %]
|
||||
<td nowrap data-order="[% row.port | html_entity %]" data-filter="[% row.port | html_entity %]">
|
||||
[% END %]
|
||||
<a class="nd_this-port-only nd_port-only-first" href="[% uri_for('/device',
|
||||
self_options) %]&q=[% params.q | uri %]&f=[% row.port | uri %]&prefer=port">
|
||||
[% IF row.is_master %]
|
||||
@@ -121,6 +122,10 @@
|
||||
<td nowrap>[% row.descr | html_entity %]</td>
|
||||
[% END %]
|
||||
|
||||
[% IF params.c_comment %]
|
||||
<td nowrap>[% row.last_comment | html_entity %]</td>
|
||||
[% END %]
|
||||
|
||||
[% IF params.c_type %]
|
||||
<td>[% row.type | html_entity %]</td>
|
||||
[% END %]
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
[% IF results.count == 0 %]
|
||||
<div class="span2 alert alert-info">This port's log is empty.</div>
|
||||
[% ELSE %]
|
||||
<table id="data-table" class="table table-bordered table-condensed table-striped" width="100%" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -10,9 +7,24 @@
|
||||
<th class="nd_center-cell">Action</th>
|
||||
<th class="nd_center-cell">Reason</th>
|
||||
<th class="nd_center-cell">Log</th>
|
||||
<th class="nd_center-cell">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</tbody>
|
||||
<tr>
|
||||
<td class="nd_center-cell">-</td>
|
||||
<td class="nd_center-cell">[% session.logged_in_user | html_entity %]</td>
|
||||
<td class="nd_center-cell">-</td>
|
||||
<td class="nd_center-cell">comment</td>
|
||||
<td class="nd_center-cell">Other</td>
|
||||
<td class="nd_center-cell"><input data-form="add" class="span4" name="log" type="text" placeholder="Add comment..."></td>
|
||||
<input data-form="add" name="ip" type="hidden" value="[% params.q | html_entity %]">
|
||||
<input data-form="add" name="port" type="hidden" value="[% params.f | html_entity %]">
|
||||
<td class="nd_center-cell">
|
||||
<button class="btn btn-small nd_adminbutton" name="add" type="submit"><i class="icon-plus-sign"></i> Add</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
[% WHILE (row = results.next) %]
|
||||
<tr>
|
||||
<td class="nd_center-cell">[% row.creation_stamp | html_entity %]</td>
|
||||
@@ -21,15 +33,16 @@
|
||||
<td class="nd_center-cell">[% row.action | html_entity %]</td>
|
||||
<td class="nd_center-cell">[% settings.port_control_reasons.item(row.reason) || row.reason | html_entity %]</td>
|
||||
<td class="nd_center-cell">[% row.log || '-' | html_entity %]</td>
|
||||
<td class="nd_center-cell"></td>
|
||||
</tr>
|
||||
[% END %]
|
||||
</tbody>
|
||||
</table>
|
||||
[% END %]
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#data-table').dataTable({
|
||||
sort: false,
|
||||
[% INCLUDE 'ajax/datatabledefaults.tt' -%]
|
||||
} );
|
||||
} );
|
||||
|
||||
@@ -52,4 +52,35 @@
|
||||
,delay: 150
|
||||
,minLength: 3
|
||||
});
|
||||
|
||||
// dynamically bind to all forms in the table
|
||||
$('.content').on('click', '.nd_adminbutton', function(event) {
|
||||
// stop form from submitting normally
|
||||
event.preventDefault();
|
||||
|
||||
// what purpose - add/update/del
|
||||
var mode = $(this).attr('name');
|
||||
|
||||
// submit the query and put results into the tab pane
|
||||
$.ajax({
|
||||
type: 'POST'
|
||||
,async: true
|
||||
,dataType: 'html'
|
||||
,url: uri_base + '/ajax/control/report/' + tab + '/' + mode
|
||||
,data: $(this).closest('tr').find('input[data-form="' + mode + '"]').serializeArray()
|
||||
,beforeSend: function() {
|
||||
$(target).html(
|
||||
'<div class="span2 alert">Request submitted...</div>'
|
||||
);
|
||||
}
|
||||
,success: function() {
|
||||
$('#' + tab + '_form').trigger('submit');
|
||||
}
|
||||
// skip any error reporting for now
|
||||
// TODO: fix sanity_ok in Netdisco Web
|
||||
,error: function() {
|
||||
$('#' + tab + '_form').trigger('submit');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user