Skip to content
Permalink
Browse files

[JENKINS-22834] Allow delete an approved classpath.

  • Loading branch information
ikedam committed Aug 2, 2014
1 parent 662cab3 commit f66bf2061857365fc559c1af609304a1678b3f3e
@@ -161,6 +161,10 @@ protected boolean addApprovedClasspath(ApprovedClasspath acp) {
return true;
}

protected boolean removeApprovedClasspath(String hash) {
return getApprovedClasspathMap().remove(hash) != null;
}

protected void removeAllApprovedClasspath() {
getApprovedClasspathMap().clear();
}
@@ -801,7 +805,16 @@ public Object denyClasspath(String hash, String classpath) throws IOException {
return getClasspathRenderInfo();
}

// TODO nicer would be to allow the user to actually edit the list directly (with syntax checks)
@Restricted(NoExternalUse.class) // for use from AJAX
@JavaScriptMethod
public Object denyApprovedClasspath(String hash) throws IOException {
Jenkins.getInstance().checkPermission(Jenkins.RUN_SCRIPTS);
if (removeApprovedClasspath(hash)) {
save();
}
return getClasspathRenderInfo();
}

@Restricted(NoExternalUse.class) // for use from AJAX
@JavaScriptMethod
public synchronized Object clearApprovedClasspaths() throws IOException {
@@ -70,9 +70,7 @@ THE SOFTWARE.
});
}

function renderClasspaths(r) {
var pendingClasspaths = r.responseObject()[0];
var approvedClasspaths = r.responseObject()[1];
function renderPendingClasspaths(pendingClasspaths) {
if (pendingClasspaths.length == 0) {
$('pendingClasspaths-none').show();
$('pendingClasspaths').childElements().each(function(e){e.remove()});
@@ -108,8 +106,48 @@ THE SOFTWARE.
});
$('pendingClasspaths').show();
}
$('approvedClasspaths').value = approvedClasspaths.map(function(e){return e.hash + "(" + e.path + ")";}).join('\n');
}

function renderApprovedClasspaths(approvedClasspaths) {
if (approvedClasspaths.length == 0) {
$('approvedClasspaths-none').show();
$('approvedClasspaths').childElements().each(function(e){e.remove()});
$('approvedClasspaths').hide();
$('approvedClasspaths-clear').hide();
} else {
$('approvedClasspaths-none').hide();
$('approvedClasspaths').childElements().each(function(e){e.remove()});
/*
Create a list like:
<p id="acp-${acp.hash}">
<button onclick="denyApprovedClasspath('${pcp.hash}')">Delete</button>
${acp.hash} (${acp.path})
</p>
*/
approvedClasspaths.each(function(e) {
var block = new Element('p', { 'id': 'acp-' + e.hash });
var deleteButton = new Element('button', { 'hash': e.hash, 'path': e.path });
deleteButton.insert('Delete');
deleteButton.observe('click', function() {
if (confirm('Really delete this approved classpath? Any existing scripts using this classpath will need to be rerun and classpath reapproved.')) {
denyApprovedClasspath(this.readAttribute('hash'));
}
});
block.insert(deleteButton);
block.insert(e.hash + "(" + e.path + ")");

$('approvedClasspaths').insert(block);
});
$('approvedClasspaths').show();
$('approvedClasspaths-clear').show();
}
}

function renderClasspaths(r) {
renderPendingClasspaths(r.responseObject()[0]);
renderApprovedClasspaths(r.responseObject()[1]);
}

function approveClasspath(hash, path) {
mgr.approveClasspath(hash, path, function(r) {
renderClasspaths(r);
@@ -120,6 +158,11 @@ THE SOFTWARE.
renderClasspaths(r);
});
}
function denyApprovedClasspath(hash) {
mgr.denyApprovedClasspath(hash, function(r) {
renderClasspaths(r);
});
}
function clearApprovedClasspaths() {
mgr.clearApprovedClasspaths(function(r) {
renderClasspaths(r);
@@ -196,11 +239,14 @@ THE SOFTWARE.
<div id="pendingClasspaths">
</div>
<p>Classpaths already approved:</p>
<textarea readonly="readonly" id="approvedClasspaths" rows="10" cols="80">
</textarea>
<p>
<p id="approvedClasspaths-none">
No approved classpath.
</p>
<div id="approvedClasspaths">
</div>
<p id="approvedClasspaths-clear">
You can also remove all previous classpaths approvals:
<button onclick="if (confirm('Really delete all approvals? Any existing scripts will need to be rerun and classpaths reapproved.')) {clearApprovedClasspaths()}">Clear Classpaths</button>
<button onclick="if (confirm('Really delete all approvals? Any existing scripts using classpaths will need to be rerun and classpaths reapproved.')) {clearApprovedClasspaths()}">Clear Classpaths</button>
</p>
</l:main-panel>
</l:layout>

0 comments on commit f66bf20

Please sign in to comment.
You can’t perform that action at this time.