Skip to content

Commit 94ed5fa

Browse files
committed
0.45:
- refined workaround against unquoted json feed for application and user json properties - apply this workaround only when running against a repository affected by the bug - minor CSS fix : historical margins for dashlet body no longer required. git-svn-id: https://share-extras.googlecode.com/svn/trunk/Audit Dashlet@1433 a3f5c567-fd0f-3a89-9b71-a290c5a5f590
1 parent be521e9 commit 94ed5fa

File tree

6 files changed

+74
-19
lines changed

6 files changed

+74
-19
lines changed

README.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ of the dashboard and drag the dashlet into one of the columns from the list of d
114114
Changelog
115115
---------
116116

117+
0.45:
118+
- refined workaround against unquoted json feed for application and user json properties
119+
- apply this workaround only when running against a repository affected by the bug
120+
- minor CSS fix : historical margins for dashlet body no longer required.
121+
117122
0.44:
118123
- expanded workaround against unquoted json feed for application and user json properties. addresses issue 71.
119124
- additional newline sanitizing of the server side json feed, in addition to the checks already present in the freemarker output. possibly addresses issue 82.

build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
build.version=0.44
1+
build.version=0.45
22
project.name=audit-dashlet
33
jar.name=${project.name}-${build.version}.jar
Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
function main()
22
{
3-
var application = args.application; // audit application name (as reported by /api/audit/control
3+
var application = args.application; // audit application name (as reported by /api/audit/control)
44
var valueFilter = args.valueFilter; // optional : "value" filter on the audit entries. match all
55
var limit = args.limit; // optional : max entry count retrieved by the repo query
66

7-
// optional : free field to add in other server-side filters (e.g fromTime... )
7+
// optional : free field to add in other server-side filters (e.g fromTime...)
88
var additionalQueryParams = args.additionalQueryParams;
99

1010
if (application != null)
1111
{
1212
var valueFilterQuery = valueFilter ? "&value=" + stringUtils.urlEncode(valueFilter) : "";
1313
if (logger.isLoggingEnabled())
14-
logger.log(" application:" +application+ " - " + "valueFilter:" +valueFilter);
14+
logger.log(" application:" +application+ " - " + "valueFilter:" +valueFilter);
1515

1616
var maxEntryCount = limit ? "&limit=" + stringUtils.urlEncode(limit) : "";
1717

1818
// decode the '&' param separators from the optional additional params passed in by the dashlet.
1919
var optionalAdditionalQueryParams = additionalQueryParams ? ("&" + additionalQueryParams.replace(/\uFFFF/g,'&')) : "";
2020

2121
if (logger.isLoggingEnabled())
22-
logger.log(" optionalAdditionalQueryParams: '" +optionalAdditionalQueryParams+ "'");
22+
logger.log(" optionalAdditionalQueryParams: '" +optionalAdditionalQueryParams+ "'");
2323

2424
var sortOrder = "&forward=" + false; // most recent first
2525

@@ -31,19 +31,29 @@ function main()
3131
if (logger.isLoggingEnabled())
3232
logger.log("called URI:'"+uri+"'");
3333

34+
3435
if (result.status == status.STATUS_OK)
3536
{
3637
var rawresponse = result.response+""; // cast rawresponse back into a js string
3738
//if (logger.isLoggingEnabled()) logger.log("rawresponse:\n"+rawresponse);
3839

39-
// the json outputted by the audit template does not quote user and application keys in the ouput
40-
// pending ALF-8307, working around it by adding the quotes with a regex replace
41-
var requoting_regex = /:([\w-@.]+)\,/g;
42-
var requoted_response = rawresponse.replace(requoting_regex, ":\"$1\",");
43-
//if (logger.isLoggingEnabled()) logger.log("requoted_response:\n"+requoted_response);
40+
var jsonQuoteFixRequired = isJsonQuoteFixRequired(connector);
41+
if (logger.isLoggingEnabled())
42+
logger.log("jsonQuoteFixRequired:'"+jsonQuoteFixRequired+"'");
43+
44+
var json_requoted_response = rawresponse;
45+
if(jsonQuoteFixRequired)
46+
{
47+
// the json outputted by the audit template does not quote user and application keys in the ouput.
48+
// Pending ALF-8307, working around it by adding the quotes with a regex replace.
49+
// Constrain the regex to only 'application' and 'user' entries, and expand the criteria to allow any character except quotes, in these field values.
50+
var json_requoting_regex = /"(application|user)":([^"]+)\,$/gm;
51+
json_requoted_response = rawresponse.replace(json_requoting_regex,"\"$1\":\"$2\",");
52+
//if (logger.isLoggingEnabled()) logger.log("json_requoted_response:\n"+json_requoted_response);
53+
}
4454

4555
// replace with a space spurious newlines that could have been stored in a json item, before the feed gets eval'd. see also ALF-11190.
46-
var escaped_response = requoted_response.replace(/(\n|\r\n|\r)/g, " ");
56+
var escaped_response = json_requoted_response.replace(/(\n|\r\n|\r)/g, " ");
4757
//if (logger.isLoggingEnabled()) logger.log("escaped_response:\n"+escaped_response);
4858

4959
var auditresponse = eval("(" + escaped_response + ")");
@@ -53,8 +63,7 @@ function main()
5363

5464
else
5565
{
56-
status.setCode(result.status, "Error during remote call. " +
57-
"Status: " + result.status + ", Response: " + result.response);
66+
status.setCode(result.status, "Error during remote call. Status: " + result.status + ", Response: " + result.response);
5867
status.redirect = true;
5968
}
6069
}
@@ -64,4 +73,38 @@ function main()
6473
status.redirect = true;
6574
}
6675
}
76+
77+
// ALF-8307 (missing quotes around audit application and user) is fixed in Enterprise 3.4.3 and Community 4.0.a, and above.
78+
// Determine is the fix is required, depending on the current version of the repository the web-tier is currently running against.
79+
function isJsonQuoteFixRequired(connector)
80+
{
81+
// get current server version to determine if a workaround for ALF-8307 is needed.
82+
var srvInfo = connector.get("/api/server");
83+
var srvInfoJson = eval('(' + srvInfo + ')');
84+
85+
var serverVersion, serverEdition, serverVersionNumbers;
86+
87+
// setup defaults
88+
serverVersion = srvInfoJson.data ? srvInfoJson.data.version : "1.0.0";
89+
serverEdition = srvInfoJson.data ? srvInfoJson.data.edition : "Enterprise";
90+
91+
// if Enterprise edition, extract x.y.z from the version number. if community, only extract x.y (exclude service packs).
92+
if (serverEdition == "Enterprise")
93+
{
94+
serverVersionNumbers = ((serverVersion.substr(0,5).replace(/\./g,""))*1); // extract x.y.z from the version number (i.e, include service pack).
95+
if (logger.isLoggingEnabled())
96+
logger.log("Enterprise serverVersionNumbers:'"+serverVersionNumbers+"'");
97+
return (serverVersionNumbers < 343);
98+
}
99+
else if (serverEdition == "Community")
100+
{
101+
serverVersionNumbers = ((serverVersion.substr(0,3).replace(/\./g,""))*1); // extract x.y from the version number (i.e, exclude service pack).
102+
if (logger.isLoggingEnabled())
103+
logger.log("Community serverVersionNumbers:'"+serverVersionNumbers+"'");
104+
return (serverVersionNumbers < 40);
105+
}
106+
else
107+
return true; // apply the fix if unhandled / different edition.
108+
}
109+
67110
main();

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
{
77
"id": ${e.id},
88
"application": "${e.application}",
9-
"user": "${e.user}",
9+
<#-- escape quotes that may exist in the persisted values for this entry -->
10+
"user": "${e.user?replace('"',"\\\\\\\"",'r')}",
1011
"time": "${e.time}",
1112
"values":
1213
{
1314
<#list e.values?keys as key>
14-
<#-- keep only the audit key for readability -->
15-
<#-- and remove spurious/invalid linebreaks (see ALF-11190) -->
16-
"${key?replace('.*/', '', 'r')}":"${e.values[key]?replace('(\n|\r\n|\r)',' ','r')}"
15+
<#-- keep only the audit key for readability, remove spurious/invalid linebreaks (see ALF-11190) -->
16+
<#-- and escape quotes that may exist in the persisted values for this entry. -->
17+
<#-- 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')}"
1719
<#if key_has_next>,</#if>
1820
</#list>
1921
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<div class="body" style="height: ${currentHeight}px;" id="${el}-body">
5757
<div class="message spaced-left" id="${el}-message"></div>
5858

59-
<div class="spaced-left" id="${el}-searchbox">
59+
<div class="spaced-left top-padded" id="${el}-searchbox">
6060
<#-- search box to filter audit values from YUI -->
6161
<label id="${el}-searchWithinResultsFilterLabel" for="${el}-searchWithinResultsFilter">${msg("audit.dashlet.searchWithinResults",0)} :</label>
6262
<input type="text" id="${el}-searchWithinResultsFilter">

source/web/extras/components/dashlets/audit-application.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111
height: 90%;
1212
}
1313

14-
.audit-application-dashlet .body
14+
/*.audit-application-dashlet .body
1515
{
1616
margin-top: 10px;
1717
margin-bottom: 10px;
18+
}*/
19+
20+
.audit-application-dashlet .top-padded
21+
{
22+
margin-top: 10px;
1823
}
1924

2025
.audit-application-dashlet .yui-dt table

0 commit comments

Comments
 (0)