Commit 8ab4519f authored by Leigh Stoller's avatar Leigh Stoller

Implement issue #284 (admin notes).

You can find and change the admin notes on the admin extension page,
since is the page where we show lots of admin only stuff. Might need
to rename this page at some point.
parent d7fc6298
......@@ -1773,6 +1773,14 @@ sub ExtendInternal($$$$$)
$instance->webURL() . "\n",
$TBOPS);
}
# Do not overwrite ...
if (!defined($instance->admin_notes()) ||
$instance->admin_notes() eq "") {
$instance->Update({"admin_notes" =>
"This instance is in user lockdown because ".
"of an admin granted extension longer then ".
"10 days."});
}
}
return 0;
......
......@@ -135,6 +135,7 @@ class Instance
function repourl() { return $this->field('repourl'); }
function reporef() { return $this->field('reporef'); }
function repohash() { return $this->field('repohash'); }
function admin_notes() { return $this->field('admin_notes'); }
function isopenstack() { return $this->field('isopenstack'); }
function openstack_utilization() {
return $this->field('openstack_utilization');
......@@ -436,6 +437,16 @@ class Instance
"where uuid='$uuid'");
}
function SetAdminNotes($notes)
{
$uuid = $this->uuid();
$safe_notes = mysql_escape_string($notes);
DBQueryWarn("update apt_instances set ".
" admin_notes='$safe_notes' ".
"where uuid='$uuid'");
}
function SetExtensionRequested($value)
{
$uuid = $this->uuid();
......
......@@ -189,6 +189,7 @@ $(function ()
}
// Update the Max Extension
DoMaxExtension();
SetupAdminNotes();
}
});
}
......@@ -349,7 +350,55 @@ $(function ()
var xmlthing = sup.CallServerMethod(null, "status", "OpenstackStats",
{"uuid" : window.UUID});
xmlthing.done(callback);
}
//
// Setup the admin notes panel for editing
//
function SetupAdminNotes()
{
var modified = 0;
// Panel starts out collapsed and read only. When it is expanded,
// change the button to edit.
$('#adminnotes-collapse').on('show.bs.collapse', function () {
$('#adminnotes-row .toggle').html('Hide');
});
$('#adminnotes-collapse').on('hide.bs.collapse', function () {
$('#adminnotes-row .toggle').html('View');
});
$("#adminnotes-collapse textarea")
.on("change input paste keyup", function() {
modified = 1;
$('#adminnotes-save-button').removeClass('hidden');
});
$('#adminnotes-save-button').click(function (event) {
event.preventDefault();
if (modified) {
SaveAdminNotes(function () {
modified = 0;
$('#adminnotes-save-button').addClass('hidden');
});
}
});
}
function SaveAdminNotes(done)
{
var notes = $("#adminnotes-collapse textarea").val();
var callback = function(json) {
if (json.code) {
sup.SpitOops("oops", "Failed to save admin notes: " +
json.value);
return;
}
done();
};
var xmlthing = sup.CallServerMethod(null, "status", "SaveAdminNotes",
{"uuid" : window.UUID,
"notes" : notes});
xmlthing.done(callback);
}
// Helper.
......@@ -358,5 +407,4 @@ $(function ()
}
initialize();
// $(document).ready(initialize);
});
......@@ -189,6 +189,8 @@ $routing = array("myprofiles" =>
"Do_Lockdown",
"Quarantine" =>
"Do_Quarantine",
"SaveAdminNotes" =>
"Do_SaveAdminNotes",
"LinktestControl" =>
"Do_Linktest",
"OpenstackStats" =>
......
......@@ -1476,6 +1476,36 @@ function Do_Lockdown()
SPITAJAX_RESPONSE("Success");
}
#
# Save new admin notes.
#
function Do_SaveAdminNotes()
{
global $this_user, $instance;
global $ajax_args;
if (StatusSetupAjax(0)) {
return;
}
if (!isset($this_user) || !ISADMIN()) {
SPITAJAX_ERROR(1, "Not enough permission.");
return;
}
if (!isset($ajax_args["notes"])) {
SPITAJAX_ERROR(1, "Missing notes");
return;
}
$notes = $ajax_args["notes"];
if ($notes != "") {
if (!TBvalid_fulltext($reason)) {
SPITAJAX_ERROR(1, "Illegal characters in nodes");
return;
}
}
$instance->SetAdminNotes($notes);
SPITAJAX_RESPONSE("Success");
}
#
# Handle Quarantine request/clear.
#
......@@ -1700,6 +1730,12 @@ function Do_ExpInfo()
$blob["admin_lockdown"] = $instance->admin_lockdown() ? true : false;
$blob["paniced"] = $instance->paniced() ? true : false;
$blob["lockout"] = $instance->extension_lockout() ? true : false;
if (ISADMIN() && $instance->admin_notes()) {
$blob["admin_notes"] = $instance->admin_notes();
}
else {
$blob["admin_notes"] = "";
}
SPITAJAX_RESPONSE($blob);
}
......
<div class="row">
<div class='col-sm-7 col-sm-offset-1'>
<div class='panel panel-default'>
<div class="panel-heading text-center">
......@@ -37,6 +38,7 @@
<td>Max Ext:</td>
<td id="max-extension">...</td>
<td></td>
</tr>
</tbody>
</table>
</div>
......@@ -119,3 +121,32 @@
</div>
</div>
</div>
</div>
<div class="row">
<div class="row" id="adminnotes-row">
<div class='col-sm-8 col-sm-offset-2' id="adminnotes-div">
<div class='panel panel-default'>
<div class="panel-heading clearfix">
<a class='btn btn-primary btn-xs pull-right toggle'
href="#adminnotes-collapse"
data-toggle="collapse"
type='button'>View</a>
<a class='btn btn-danger btn-xs pull-right hidden' hidden
style="margin-right: 10px;"
id="adminnotes-save-button"
type='button'>Save</a>
<span class="adminnotes-title">Admin Notes</span>
</div>
<div id="adminnotes-collapse"
class="panel-collapse collapse">
<div class='panel-body'>
<textarea style="width: 100%;" rows="3"
placeholder="Click Edit to add/change admin notes"
><%= expinfo.admin_notes %></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
......@@ -40,6 +40,11 @@ pre {
.panel-heading {
padding: 5px;
}
.adminnotes-title {
display:block;
width: 100px;
margin: 0 auto;
}
</style>
<div class="row" id="firstrow"></div>
<div class="row" id="secondrow"></div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment