Skip to content

Commit

Permalink
Merge branch 'release/11.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
markdaugherty committed Dec 7, 2017
2 parents 5aa7431 + d268e39 commit f6ed43e
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 84 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<groupId>com.icfolson.aem.groovy.console</groupId>
<artifactId>aem-groovy-console</artifactId>
<packaging>jar</packaging>
<version>11.0.2</version>
<version>11.1.0</version>
<name>AEM Groovy Console</name>
<description>
The AEM Groovy Console provides an interface for running Groovy scripts in the AEM container. Scripts can be
Expand Down Expand Up @@ -397,7 +397,7 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.11</version>
<version>2.4.13</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h4 class="panel-title">
</div>
<div id="data" class="panel-collapse collapse">
<div class="panel-body">
<p>Editor contents will be added to the script bindings in a variable named <code>data</code>. JSON data will be converted to a map. If data is not valid JSON, the <code>data</code> variable will be a <code>String</code>.</p>
<p>Editor contents will be added to the script bindings in a variable named <code>data</code>. JSON data will be converted to a map. If data is not valid JSON, the <code>data</code> variable will be of type <code>String</code>.</p>

<div id="data-editor" class="ace_editor_wrapper"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="panel panel-default">
<div class="panel panel-default" data-sly-use.history="com.icfolson.aem.groovy.console.components.History">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#info" href="#history">History</a>
Expand Down Expand Up @@ -26,7 +26,7 @@ <h4 class="panel-title">
</div>
</div>

<div class="pull-right delete-all">
<div class="pull-right delete-all ${history.hasAuditRecords ? '' : 'hidden'}">
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#delete-all-modal">
<span class="glyphicon glyphicon-trash" title="Delete All"></span> Delete All
</button>
Expand Down
36 changes: 25 additions & 11 deletions src/main/content/jcr_root/etc/clientlibs/groovyconsole/js/audit.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
GroovyConsole.Audit = function () {

var AUDIT_URL = '/bin/groovyconsole/audit.json';

var table;

return {
initialize: function () {
table = $('.audit').DataTable({
ajax: '/bin/groovyconsole/audit.json',
ajax: AUDIT_URL,
columns: [
{
className: 'open-record',
Expand Down Expand Up @@ -63,9 +65,9 @@ GroovyConsole.Audit = function () {

tableBody.on('click', 'td.open-record', function () {
var tr = $(this).closest('tr');
var script = table.row(tr).data().relativePath;
var data = table.row(tr).data();

$.getJSON('/bin/groovyconsole/audit.json?script=' + script, function (response) {
$.getJSON(AUDIT_URL, {'userId': data.userId, 'script': data.relativePath}, function (response) {
scriptEditor.getSession().setValue(response.script);

if (response.data.length) {
Expand All @@ -79,16 +81,20 @@ GroovyConsole.Audit = function () {
GroovyConsole.reset();
GroovyConsole.showResult(response);

$('html, body').animate({ scrollTop: 0 });
$('html, body').animate({scrollTop: 0});
});
});

tableBody.on('click', 'td.delete-record', function () {
var tr = $(this).closest('tr');
var script = table.row(tr).data().relativePath;
var data = table.row(tr).data();

$.ajax({
url: '/bin/groovyconsole/audit.json?script=' + script,
url: AUDIT_URL + '?' + $.param({
'userId': data.userId,
'script': data.relativePath
}),
traditional: true,
type: 'DELETE'
}).done(function () {
GroovyConsole.Audit.showAlert('.alert-success', 'Audit record deleted successfully.');
Expand All @@ -98,9 +104,9 @@ GroovyConsole.Audit = function () {
});
});

$('#delete-all-modal .btn-warning').click(function () {
$('#delete-all-modal').find('.btn-warning').click(function () {
$.ajax({
url: '/bin/groovyconsole/audit.json',
url: AUDIT_URL,
type: 'DELETE'
}).done(function () {
GroovyConsole.Audit.showAlert('.alert-success', 'Audit records deleted successfully.');
Expand All @@ -118,7 +124,7 @@ GroovyConsole.Audit = function () {

dateRange.daterangepicker({
maxDate: moment()
}).on('apply.daterangepicker', function(e, picker) {
}).on('apply.daterangepicker', function (e, picker) {
var startDate = picker.startDate.format('YYYY-MM-DD');
var endDate = picker.endDate.format('YYYY-MM-DD');

Expand All @@ -133,11 +139,19 @@ GroovyConsole.Audit = function () {
},

refreshAuditRecords: function () {
table.ajax.url('/bin/groovyconsole/audit.json').load();
table.ajax.url(AUDIT_URL).load(function (json) {
if (json.data.length) {
$('.delete-all').removeClass('hidden');
} else {
$('.delete-all').addClass('hidden');
}
});
},

loadAuditRecords: function (startDate, endDate) {
table.ajax.url('/bin/groovyconsole/audit.json?startDate=' + startDate + '&endDate=' + endDate).load();
var params = $.param({'startDate': startDate, 'endDate': endDate});

table.ajax.url(AUDIT_URL + '?' + params).load();
},

showAlert: function (selector, text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ var GroovyConsole = function () {

$('body').keydown(function (e) {
if (e.ctrlKey) {
if (e.keyCode == 13) {
if (e.keyCode === 13) {
$('#run-script').click();
} else if (e.keyCode == 78) {
} else if (e.keyCode === 78) {
$('#new-script').click();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
jcr:primaryType="rep:SystemUser"
jcr:uuid="3d75a089-8ec6-332f-aae4-5550f6ad06df"
rep:authorizableId="groovy-console-system-user"
rep:principalName="groovy-console-system-user"/>
rep:principalName="groovy-console-system-user"/>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class AuditRecord {

public static final String PROPERTY_RUNNING_TIME = "runningTime"

private static final Integer DEPTH_USER_ID = 5

private Node node

@Delegate
final RunScriptResponse response

Expand All @@ -31,11 +35,17 @@ class AuditRecord {
final Calendar date

AuditRecord(Node node) {
this.node = node

path = node.path
date = node.getProperty(JCR_CREATED).date
response = RunScriptResponse.fromAuditRecordNode(node)
}

String getUserId() {
node.getAncestor(DEPTH_USER_ID).name
}

String getRelativePath() {
(path - Text.getAbsoluteParent(path, 4)).substring(1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ interface AuditService {
*
* @param session request session for the user executing the script
* @param response response containing execution result or exception
* @throws RepositoryException if error occurs creating audit record
*/
AuditRecord createAuditRecord(Session session, RunScriptResponse response)
AuditRecord createAuditRecord(Session session, RunScriptResponse response) throws RepositoryException

/**
* Delete all audit records.
Expand All @@ -27,10 +28,11 @@ interface AuditService {
* Delete an audit record.
*
* @param session request session, only audit records for the current user will be deleted
* @param userId user that owns the audit record
* @param relativePath relative path to audit record from parent audit node
* @throws RepositoryException if an error occurs while deleting the audit record node
*/
void deleteAuditRecord(Session session, String relativePath) throws RepositoryException
void deleteAuditRecord(Session session, String userId, String relativePath) throws RepositoryException

/**
* Get all audit records.
Expand All @@ -45,10 +47,12 @@ interface AuditService {
* Get the audit record at the given relative path.
*
* @param session request session, only audit records for the current user will be retrieved
* @param userId user that owns the audit record
* @param relativePath relative path to audit record from parent audit node
* @return audit record or null if none exists
* @throws RepositoryException if error occurs getting audit record
*/
AuditRecord getAuditRecord(Session session, String relativePath)
AuditRecord getAuditRecord(Session session, String userId, String relativePath) throws RepositoryException

/**
* Get a list of audit records for the given date range.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.icfolson.aem.groovy.console.audit.impl

import com.icfolson.aem.groovy.console.audit.AuditRecord

import javax.jcr.Node
import javax.jcr.Property
import javax.jcr.RepositoryException
import javax.jcr.util.TraversingItemVisitor

import static com.icfolson.aem.groovy.console.constants.GroovyConsoleConstants.AUDIT_RECORD_NODE_PREFIX

class AuditRecordNodeVisitor extends TraversingItemVisitor {

final List<AuditRecord> auditRecords = []

AuditRecordNodeVisitor() {
super(true)
}

@Override
protected void entering(Property property, int level) throws RepositoryException {

}

@Override
protected void entering(Node node, int level) throws RepositoryException {
if (node.name.startsWith(AUDIT_RECORD_NODE_PREFIX)) {
auditRecords.add(new AuditRecord(node))
}
}

@Override
protected void leaving(Property property, int level) throws RepositoryException {

}

@Override
protected void leaving(Node node, int level) throws RepositoryException {

}
}
Loading

0 comments on commit f6ed43e

Please sign in to comment.