Skip to content

Commit 9f0add1

Browse files
committed
0.5:
- fixed config dialog URL to use /res, required in 4.2. addresses issue 129. - added the configurable server-side ability to query for entries containing a specific audit path. Note : querying for values when an audit path query is configured will restrict the search to entries with that value for that specific audit path. - made the repo version check configurable through the audit application data webscript config file - made the audit path trimming configurable through the config dialog - minor : added the year by default in the displayed timestamps. - fixed ID format for json entries, to make sure the ID representation does not have comma separators for high entry IDs. addresses issue 129, comment #6. - fixed an unreported issue where storing config values with double quotes in the text would prevent the config options to be loaded afterwards. git-svn-id: https://share-extras.googlecode.com/svn/trunk/Audit Dashlet@1438 a3f5c567-fd0f-3a89-9b71-a290c5a5f590
1 parent 94ed5fa commit 9f0add1

30 files changed

+264
-131
lines changed

README.txt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The dashlet has been developed to install on top of an existing Alfresco 3.4 ins
4040

4141
Once you have run this you will need to restart Tomcat so that the classpath resources in the JAR file are picked up.
4242

43-
As an alternative, you may also copy the exploded files in your classpath, but they must have the classpath tree
43+
As an alternative, you may also copy the exploded files in your classpath, but they must have the same classpath tree
4444
than the one in the jar. If using development/debug mode for the web framework, you will not need to restart tomcat,
4545
but you may have to clear your browser's cache.
4646

@@ -58,13 +58,15 @@ of the dashboard and drag the dashlet into one of the columns from the list of d
5858
For convenience, the list will pop out when opening the configure dialog with no applications currently configured.
5959
Could be useful if you don't know what application name to search for.
6060

61-
The number of data rows (audit events) displayed per page is configurable by the 'Entries per page' parameter.
61+
The number of data rows (audit events) displayed per page is configurable with the 'Entries per page' parameter.
6262

6363
Additional server side filters are configurable :
6464
UI Name Description Audit API corresponding parameter
6565
--------------------------------------------------------------------------------------------------------------------------------
66-
- value filter filter on the audit value (exact match, optional) 'value'
67-
- limit maximum number of audit entries retrieved (optional) 'limit' (default 100)
66+
- Value Filter filter on the audit value (exact match, optional) 'value'
67+
- Max Entry Count maximum number of audit entries retrieved (optional) 'limit' (default 100)
68+
- Audit Path Filter select only the audit entries with a matching audit path URL path after application (default none)
69+
key in their values map.
6870
- Additional Query params other possible query parameters (optional) from/to time, from/to id, user
6971

7072
(See http://wiki.alfresco.com/wiki/Auditing_(from_V3.4)#Advanced_Query). This filtering is done server-side.
@@ -74,6 +76,14 @@ of the dashboard and drag the dashlet into one of the columns from the list of d
7476
Note : the output in the "audited values" field will depend on the configuration of the current audit application.
7577
(ie what data extractors have been configured, if using the access auditor or not, etc...).
7678

79+
Note : querying for values when an audit path query is configured will restrict the search to entries with that value for that specific audit path.
80+
81+
The "Trim Audit Paths" checkbox can be used to show the full audit paths up to the audit key, or just the audit key, in the audit values.
82+
It can be useful to temporarily turn on in case one wants to use the audit path filter above, as it will show the full audit paths required for that filter.
83+
84+
Note : The data webscript does a version check to determine if a workaround for the unquoted json feed prior to 3.4.3 Enterprise / 4.0 Community (ALF-8307) is required.
85+
This can be overriden by copying the webscript config file (audit-application-data.get.config.xml) in the equivalent path in web-extension, if required.
86+
7787
* Search box
7888

7989
The dashlet search box allows more search capabilities than the server side filter, ie :
@@ -114,6 +124,16 @@ of the dashboard and drag the dashlet into one of the columns from the list of d
114124
Changelog
115125
---------
116126

127+
0.5:
128+
- fixed config dialog URL to use /res, required in 4.2. addresses issue 129.
129+
- added the configurable server-side ability to query for entries containing a specific audit path.
130+
Note : querying for values when an audit path query is configured will restrict the search to entries with that value for that specific audit path.
131+
- made the repo version check configurable through the audit application data webscript config file
132+
- made the audit path trimming configurable through the config dialog
133+
- minor : added the year by default in the displayed timestamps.
134+
- fixed ID format for json entries, to make sure the ID representation does not have comma separators for high entry IDs. addresses issue 129, comment #6.
135+
- fixed an unreported issue where storing config values with double quotes in the text would prevent the config options to be loaded afterwards.
136+
117137
0.45:
118138
- refined workaround against unquoted json feed for application and user json properties
119139
- apply this workaround only when running against a repository affected by the bug

build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
build.version=0.45
1+
build.version=0.5
22
project.name=audit-dashlet
33
jar.name=${project.name}-${build.version}.jar
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<config>
2+
<!-- if true, the script will check the current version of the repo to determine if the feed needs to be fixed for missing quotes before it gets parsed -->
3+
<enableVersionCheck>true</enableVersionCheck>
4+
</config>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<webscript>
22
<shortname>Audit Application Data Component</shortname>
33
<description>Audit Application Data Component</description>
4-
<url>/components/dashlets/audit-application/entries?application={application}&amp;valueFilter={valueFilter}&amp;limit={limit}&amp;additionalQueryParams={additionalQueryParams}</url>
4+
<url>/components/dashlets/audit-application/entries?application={application}&amp;valueFilter={valueFilter}&amp;limit={limit}&amp;pathFilter={pathFilter}&amp;trimAuditPaths={trimAuditPaths}&amp;additionalQueryParams={additionalQueryParams}</url>
55
<format default="json">extension</format>
66
</webscript>

config/alfresco/site-webscripts/org/sharextras/components/dashlets/audit-application-data.get.js

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,68 @@
11
function main()
22
{
3+
// read this webscript's config.
4+
var scriptConfig = new XML(config.script);
5+
var enableVersionCheck = (scriptConfig["enableVersionCheck"] == "true");
6+
7+
if (logger.isLoggingEnabled())
8+
logger.log("script config - enableVersionCheck : " +enableVersionCheck);
9+
310
var application = args.application; // audit application name (as reported by /api/audit/control)
411
var valueFilter = args.valueFilter; // optional : "value" filter on the audit entries. match all
512
var limit = args.limit; // optional : max entry count retrieved by the repo query
613

7-
// optional : free field to add in other server-side filters (e.g fromTime...)
8-
var additionalQueryParams = args.additionalQueryParams;
14+
var pathFilter = args.pathFilter; // optional : select only the audit entries which possess a matching audit path key in their values map.
15+
var additionalQueryParams = args.additionalQueryParams; // optional : free field to add in other server-side filters (e.g fromTime...)
16+
17+
// optional : keep only the audit key for better readability / shorter text.
18+
// Path trimming applies to the freemarker template, so push it into the model.
19+
model.trimAuditPaths = (args.trimAuditPaths ? (args.trimAuditPaths == "true") : false);
20+
if (logger.isLoggingEnabled())
21+
logger.log("trimAuditPaths:" +model.trimAuditPaths);
922

1023
if (application != null)
1124
{
1225
var valueFilterQuery = valueFilter ? "&value=" + stringUtils.urlEncode(valueFilter) : "";
13-
if (logger.isLoggingEnabled())
14-
logger.log(" application:" +application+ " - " + "valueFilter:" +valueFilter);
15-
1626
var maxEntryCount = limit ? "&limit=" + stringUtils.urlEncode(limit) : "";
1727

18-
// decode the '&' param separators from the optional additional params passed in by the dashlet.
19-
var optionalAdditionalQueryParams = additionalQueryParams ? ("&" + additionalQueryParams.replace(/\uFFFF/g,'&')) : "";
28+
// this pathFilter is not a URL argument, it will be appended to the application name.
29+
// Note : pending the ability to call the urlEncoder with reserveUriChars set to true, only the '/' are decoded back with a regex replace for use by the repo audit webscript.
30+
var pathFilterQuery = pathFilter ? (stringUtils.urlEncode(pathFilter)+"").replace(/\%2f/g,'/') : "";
2031

32+
if (logger.isLoggingEnabled())
33+
logger.log(" application:" +application+ " - " + " - pathFilterQuery: '" +pathFilterQuery+ "'" + "valueFilterQuery:" +valueFilterQuery);
34+
35+
// decode the '&' param separators from the optional additional params passed in by the dashlet, and encode the rest with the standard encoder (see note above).
36+
var optionalAdditionalQueryParams = additionalQueryParams ? ("&" + encodeURI(additionalQueryParams.replace(/\uFFFF/g,'&'))) : "";
2137
if (logger.isLoggingEnabled())
2238
logger.log(" optionalAdditionalQueryParams: '" +optionalAdditionalQueryParams+ "'");
2339

2440
var sortOrder = "&forward=" + false; // most recent first
2541

26-
var uri = "/api/audit/query/"+stringUtils.urlEncode(application)+"?verbose=true"
42+
// build the query URL using all the required parameters and perform the request.
43+
// Note optionalAdditionalQueryParams is unencoded, pending the ability to call the urlEncoder with reserveUriChars set to true.
44+
var uri = "/api/audit/query/"+stringUtils.urlEncode(application) + "/" + pathFilterQuery +"?verbose=true"
2745
+ optionalAdditionalQueryParams + valueFilterQuery + maxEntryCount + sortOrder;
2846

2947
var connector = remote.connect("alfresco");
3048
var result = connector.get(uri);
3149
if (logger.isLoggingEnabled())
32-
logger.log("called URI:'"+uri+"'");
50+
logger.log("called URI:'"+uri+"'");
3351

3452

3553
if (result.status == status.STATUS_OK)
3654
{
3755
var rawresponse = result.response+""; // cast rawresponse back into a js string
3856
//if (logger.isLoggingEnabled()) logger.log("rawresponse:\n"+rawresponse);
3957

40-
var jsonQuoteFixRequired = isJsonQuoteFixRequired(connector);
58+
var jsonQuoteFixRequired = false;
59+
if(enableVersionCheck)
60+
{
61+
if (logger.isLoggingEnabled())
62+
logger.log("versionCheck is enabled, will check repo version");
63+
jsonQuoteFixRequired = isJsonQuoteFixRequired(connector);
64+
}
65+
4166
if (logger.isLoggingEnabled())
4267
logger.log("jsonQuoteFixRequired:'"+jsonQuoteFixRequired+"'");
4368

config/alfresco/site-webscripts/org/sharextras/components/dashlets/audit-application-data.get.json.ftl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,26 @@
44
[
55
<#list auditresponse.entries as e>
66
{
7-
"id": ${e.id},
7+
<#-- output the ID in 'machine' representation, i.e. wihout any separators of any kind -->
8+
"id": ${e.id?c},
89
"application": "${e.application}",
910
<#-- escape quotes that may exist in the persisted values for this entry -->
10-
"user": "${e.user?replace('"',"\\\\\\\"",'r')}",
11+
"user": "${e.user!'null'?replace('"',"\\\\\\\"",'r')}",
1112
"time": "${e.time}",
1213
"values":
1314
{
1415
<#list e.values?keys as key>
15-
<#-- keep only the audit key for readability, remove spurious/invalid linebreaks (see ALF-11190) -->
16+
17+
<#assign displayed_key=key>
18+
<#if trimAuditPaths>
19+
<#-- keep only the audit key for better readability -->
20+
<#assign displayed_key=key?replace('.*/', '', 'r')>
21+
</#if>
22+
23+
<#-- Remove spurious/invalid linebreaks (see ALF-11190) -->
1624
<#-- and escape quotes that may exist in the persisted values for this entry. -->
1725
<#-- Note that the various backslashes are required to pass through the evaluation chain. -->
18-
"${key?replace('.*/', '', 'r')}":"${e.values[key]?replace('(\n|\r\n|\r)',' ','r')?replace('"',"\\\\\\\"",'r')}"
26+
"${displayed_key}":"${e.values[key]?replace('(\n|\r\n|\r)',' ','r')?replace('"',"\\\\\\\"",'r')}"
1927
<#if key_has_next>,</#if>
2028
</#list>
2129
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<#include "/org/alfresco/components/component.head.inc">
22
<!-- Audit Application dashlet -->
3-
<@script type="text/javascript" src="${page.url.context}/modules/simple-dialog.js"></@script>
3+
<@script type="text/javascript" src="${page.url.context}/res/modules/simple-dialog.js"></@script>
44
<@link rel="stylesheet" type="text/css" href="${page.url.context}/res/extras/components/dashlets/audit-application.css" />
55
<@script type="text/javascript" src="${page.url.context}/res/extras/components/dashlets/audit-application.js"></@script>

config/alfresco/site-webscripts/org/sharextras/components/dashlets/audit-application.get.html.ftl

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@
44
new Extras.dashlet.AuditApplication("${el}").setOptions(
55
{
66
componentId: "${instance.object.id}",
7-
application: "${args.application!''}",
8-
valueFilter: "${args.valueFilter!''}",
9-
limit: "${args.limit!''}",
10-
rowsPerPage: "${args.rowsPerPage!'10'}",
11-
additionalQueryParams: "${args.additionalQueryParams!''}",
12-
show_id_column: "${args.show_id_column!'show'}",
13-
show_user_column: "${args.show_user_column!'show'}",
14-
show_time_column: "${args.show_time_column!'show'}",
15-
show_values_column: "${args.show_values_column!'show'}"
7+
8+
<#-- escape quotes in user-entered parameters, just in case -->
9+
application: "${escape_quotes(args.application!'')}",
10+
valueFilter: "${escape_quotes(args.valueFilter!'')}",
11+
limit: "${escape_quotes(args.limit!'')}",
12+
rowsPerPage: "${escape_quotes(args.rowsPerPage!'10')}",
13+
pathFilter: "${escape_quotes(args.pathFilter!'')}",
14+
additionalQueryParams: "${escape_quotes(args.additionalQueryParams!'')}",
15+
16+
<#-- these values are managed by the dashlet, but escape them anyways, just in case... -->
17+
show_id_column: "${escape_quotes(args.show_id_column!'show')}",
18+
show_user_column: "${escape_quotes(args.show_user_column!'show')}",
19+
show_time_column: "${escape_quotes(args.show_time_colum!'show')}",
20+
show_values_column: "${escape_quotes(args.show_values_column!'show')}",
21+
trim_audit_paths: "${escape_quotes(args.trim_audit_paths!'true')}"
22+
1623
}).setMessages(${messages});
1724
18-
<#-- dashlet resizer does not dynamically adjust the number of rows displayed on the page re: pagination -->
19-
<#-- the number of rows can be configured in the dialog though, sufficient for now -->
25+
<#-- dashlet resizer does not dynamically adjust the number of rows displayed on the page re: pagination. -->
26+
<#-- The number of rows can be configured in the dialog though, sufficient for now. -->
2027
<#-- future research : subscribe to rowsPerPageChange, "" etc... -->
2128
new Alfresco.widget.DashletResizer("${el}", "${instance.object.id}").setOptions(
2229
{
@@ -49,7 +56,7 @@
4956
</div>
5057
</div>
5158

52-
<#-- audit only allows admin to query audit entries. therefore the dashlet is only usable by admin users. -->
59+
<#-- audit only allows admin to query audit entries. Therefore the dashlet is only usable by admin users. -->
5360
<#if userIsAdmin>
5461
<#assign currentHeight=default_height>
5562
<#if args.height??><#assign currentHeight=args.height></#if>
@@ -70,3 +77,14 @@
7077
</div>
7178
</#if>
7279
</div>
80+
81+
<#-- for safety, escape double quotes in the arguments that will be passed to the instanciated dashlet component options, otherwise the json feed will be invalid. -->
82+
<#-- Takes a string as parameter (cannot be null), and returns the string with double quotes escaped. If the parameter is the empty string, it will be returned as is. -->
83+
<#function escape_quotes string>
84+
<#if string?has_content>
85+
<#-- note that the various backslashes are required to pass through the evaluation chain -->
86+
<#return string?replace('"',"\\\\\\\"",'r')>
87+
<#else>
88+
<#return string>
89+
</#if>
90+
</#function>

config/alfresco/site-webscripts/org/sharextras/components/dashlets/audit-application.get.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ audit.dashlet.header.default=Audit Dashlet
22

33
audit.dashlet.link.configure=Configure
44
audit.dashlet.link.help=Help
5-
audit.dashlet.link.help.url=http://code.google.com/p/share-extras/wiki/SampleAuditDashlet
5+
audit.dashlet.link.help.url=http://code.google.com/p/share-extras/wiki/AuditDashlet
66

77
audit.dashlet.notConfigured=No application is configured.
88
audit.dashlet.loading=Loading...

config/alfresco/site-webscripts/org/sharextras/components/dashlets/audit-application.get_en.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ audit.dashlet.header.default=Audit Dashlet
22

33
audit.dashlet.link.configure=Configure
44
audit.dashlet.link.help=Help
5-
audit.dashlet.link.help.url=http://code.google.com/p/share-extras/wiki/SampleAuditDashlet
5+
audit.dashlet.link.help.url=http://code.google.com/p/share-extras/wiki/AuditDashlet
66

77
audit.dashlet.notConfigured=No application is configured.
88
audit.dashlet.loading=Loading...

0 commit comments

Comments
 (0)